Search in sources :

Example 1 with ASN1Set

use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.

the class Filter method encode.

/**
 * Encodes this search filter to an ASN.1 element suitable for inclusion in an
 * LDAP search request protocol op.
 *
 * @return  An ASN.1 element containing the encoded search filter.
 */
@NotNull()
public ASN1Element encode() {
    switch(filterType) {
        case FILTER_TYPE_AND:
        case FILTER_TYPE_OR:
            final ASN1Element[] filterElements = new ASN1Element[filterComps.length];
            for (int i = 0; i < filterComps.length; i++) {
                filterElements[i] = filterComps[i].encode();
            }
            return new ASN1Set(filterType, filterElements);
        case FILTER_TYPE_NOT:
            return new ASN1Element(filterType, notComp.encode().encode());
        case FILTER_TYPE_EQUALITY:
        case FILTER_TYPE_GREATER_OR_EQUAL:
        case FILTER_TYPE_LESS_OR_EQUAL:
        case FILTER_TYPE_APPROXIMATE_MATCH:
            final ASN1OctetString[] attrValueAssertionElements = { new ASN1OctetString(attrName), assertionValue };
            return new ASN1Sequence(filterType, attrValueAssertionElements);
        case FILTER_TYPE_SUBSTRING:
            final ArrayList<ASN1OctetString> subList = new ArrayList<>(2 + subAny.length);
            if (subInitial != null) {
                subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBINITIAL, subInitial.getValue()));
            }
            for (final ASN1Element subAnyElement : subAny) {
                subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBANY, subAnyElement.getValue()));
            }
            if (subFinal != null) {
                subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBFINAL, subFinal.getValue()));
            }
            final ASN1Element[] subFilterElements = { new ASN1OctetString(attrName), new ASN1Sequence(subList) };
            return new ASN1Sequence(filterType, subFilterElements);
        case FILTER_TYPE_PRESENCE:
            return new ASN1OctetString(filterType, attrName);
        case FILTER_TYPE_EXTENSIBLE_MATCH:
            final ArrayList<ASN1Element> emElementList = new ArrayList<>(4);
            if (matchingRuleID != null) {
                emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCHING_RULE_ID, matchingRuleID));
            }
            if (attrName != null) {
                emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_ATTRIBUTE_NAME, attrName));
            }
            emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCH_VALUE, assertionValue.getValue()));
            if (dnAttributes) {
                emElementList.add(new ASN1Boolean(EXTENSIBLE_TYPE_DN_ATTRIBUTES, true));
            }
            return new ASN1Sequence(filterType, emElementList);
        default:
            throw new AssertionError(ERR_FILTER_INVALID_TYPE.get(StaticUtils.toHex(filterType)));
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 2 with ASN1Set

use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.

the class ListNotificationSubscriptionsExtendedRequest method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value of this extended request.
 *
 * @param  managerID          The notification manager ID.  It must not be
 *                            {@code null}.
 * @param  destinationIDs     The set of notification destination IDs for
 *                            which to retrieve the subscription information.
 *                            It may be {@code null} or empty if subscription
 *                            information for all destinations should be
 *                            returned.
 *
 * @return  The ASN.1 octet string containing the encoded value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String managerID, @Nullable final Collection<String> destinationIDs) {
    Validator.ensureNotNull(managerID);
    final ArrayList<ASN1Element> elements = new ArrayList<>(2);
    elements.add(new ASN1OctetString(managerID));
    if ((destinationIDs != null) && (!destinationIDs.isEmpty())) {
        final LinkedHashSet<ASN1Element> destIDElements = new LinkedHashSet<>(StaticUtils.computeMapCapacity(destinationIDs.size()));
        for (final String destinationID : destinationIDs) {
            destIDElements.add(new ASN1OctetString(destinationID));
        }
        elements.add(new ASN1Set(destIDElements));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LinkedHashSet(java.util.LinkedHashSet) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Example 3 with ASN1Set

use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.

the class GetChangelogBatchExtendedRequestTestCase method testDecodeValueSequenceInvalidChangeType.

/**
 * Provides test coverage for an attempt to decode an extended request with a
 * value sequence with an invalid change type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidChangeType() throws Exception {
    final ASN1Set changeTypeSet = new ASN1Set((byte) 0xA4, new ASN1Enumerated(0), new ASN1Enumerated(5));
    final ASN1Sequence valueSequence = new ASN1Sequence(new EndOfChangelogStartingPoint().encode(), new ASN1Integer(0), changeTypeSet);
    new GetChangelogBatchExtendedRequest(new ExtendedRequest(GetChangelogBatchExtendedRequest.GET_CHANGELOG_BATCH_REQUEST_OID, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Example 4 with ASN1Set

use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.

the class UniquenessRequestControlTestCase method testDecodeControlValueSequenceInvalidPostCommitValidationLevel.

/**
 * Tests the behavior when trying to decode a control whose value sequence has
 * an invalid multiple post-commit validation level value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceInvalidPostCommitValidationLevel() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "uniqueness-id"), new ASN1Set((byte) 0xA1, new ASN1OctetString("uid")), new ASN1Enumerated((byte) 0x87, 12345));
    new UniquenessRequestControl(new Control("1.3.6.1.4.1.30221.2.5.52", true, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) Test(org.testng.annotations.Test)

Example 5 with ASN1Set

use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.

the class UniquenessRequestControlTestCase method testDecodeControlValueSequenceUnrecognizedElementType.

/**
 * Tests the behavior when trying to decode a control whose value sequence has
 * an element with an unrecognized BER type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceUnrecognizedElementType() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "uniqueness-id"), new ASN1Set((byte) 0xA1, new ASN1OctetString("uid")), new ASN1Enumerated((byte) 0x8F, 12345));
    new UniquenessRequestControl(new Control("1.3.6.1.4.1.30221.2.5.52", true, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) Test(org.testng.annotations.Test)

Aggregations

ASN1Set (org.bouncycastle.asn1.ASN1Set)67 ArrayList (java.util.ArrayList)51 ASN1Set (com.unboundid.asn1.ASN1Set)33 IOException (java.io.IOException)32 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)30 ASN1Set (com.github.zhenwei.core.asn1.ASN1Set)26 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)22 ASN1Element (com.unboundid.asn1.ASN1Element)21 NotNull (com.unboundid.util.NotNull)21 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)19 List (java.util.List)17 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)17 DEROctetString (org.bouncycastle.asn1.DEROctetString)16 Enumeration (java.util.Enumeration)14 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)14 OutputStream (java.io.OutputStream)12 Test (org.testng.annotations.Test)12 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)11 X509Certificate (java.security.cert.X509Certificate)11