Search in sources :

Example 36 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class RouteToServerRequestControlTestCase method testDecodeValueSequenceUnexpectedElementType.

/**
 * Tests the ability to decode a control with a value sequence containing an
 * unexpected element type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceUnexpectedElementType() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "foo"), new ASN1Boolean((byte) 0x82, true), new ASN1Boolean((byte) 0x00, true));
    new RouteToServerRequestControl(new Control(RouteToServerRequestControl.ROUTE_TO_SERVER_REQUEST_OID, true, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) Test(org.testng.annotations.Test)

Example 37 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class SoftDeletedEntryAccessRequestControlTestCase method testDecodeValueSequenceBadElement.

/**
 * Tests the behavior when attempting to decode a control whose value has an
 * invalid sequence element.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceBadElement() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Boolean((byte) 0x80, false), new ASN1OctetString((byte) 0x83, "unexpected type"));
    new SoftDeletedEntryAccessRequestControl(new Control(SoftDeletedEntryAccessRequestControl.SOFT_DELETED_ENTRY_ACCESS_REQUEST_OID, false, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) Test(org.testng.annotations.Test)

Example 38 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class Control method encode.

/**
 * Encodes this control to an ASN.1 sequence suitable for use in an LDAP
 * message.
 *
 * @return  The encoded representation of this control.
 */
@NotNull()
public final ASN1Sequence encode() {
    final ArrayList<ASN1Element> elementList = new ArrayList<>(3);
    elementList.add(new ASN1OctetString(oid));
    if (isCritical) {
        elementList.add(new ASN1Boolean(isCritical));
    }
    if (value != null) {
        elementList.add(new ASN1OctetString(value.getValue()));
    }
    return new ASN1Sequence(elementList);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 39 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class SearchRequest method encodeProtocolOp.

/**
 * Encodes the search request protocol op to an ASN.1 element.
 *
 * @return  The ASN.1 element with the encoded search request protocol op.
 */
@Override()
@NotNull()
public ASN1Element encodeProtocolOp() {
    // Create the search request protocol op.
    final ASN1Element[] attrElements = new ASN1Element[attributes.length];
    for (int i = 0; i < attrElements.length; i++) {
        attrElements[i] = new ASN1OctetString(attributes[i]);
    }
    final ASN1Element[] protocolOpElements = { new ASN1OctetString(baseDN), new ASN1Enumerated(scope.intValue()), new ASN1Enumerated(derefPolicy.intValue()), new ASN1Integer(sizeLimit), new ASN1Integer(timeLimit), new ASN1Boolean(typesOnly), filter.encode(), new ASN1Sequence(attrElements) };
    return new ASN1Sequence(LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST, protocolOpElements);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Integer(com.unboundid.asn1.ASN1Integer) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 40 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class ContentSyncInfoIntermediateResponse method encodeValue.

/**
 * Encodes the provided information into a form suitable for use as the value
 * of this intermediate response.
 *
 * @param  type            The type for this sync info message.
 * @param  cookie          The updated sync state cookie.
 * @param  refreshDone     Indicates whether the refresh phase of the
 *                         synchronization operation is complete.
 * @param  entryUUIDs      The set of entryUUIDs for the entries referenced
 *                         in this message.
 * @param  refreshDeletes  Indicates whether the associated entryUUIDs are for
 *                         entries that have been removed.
 *
 * @return  The encoded value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ContentSyncInfoType type, @Nullable final ASN1OctetString cookie, final boolean refreshDone, @Nullable final List<UUID> entryUUIDs, final boolean refreshDeletes) {
    final ASN1Element e;
    switch(type) {
        case NEW_COOKIE:
            e = new ASN1OctetString(type.getType(), cookie.getValue());
            break;
        case REFRESH_DELETE:
        case REFRESH_PRESENT:
            ArrayList<ASN1Element> l = new ArrayList<>(2);
            if (cookie != null) {
                l.add(cookie);
            }
            if (!refreshDone) {
                l.add(new ASN1Boolean(refreshDone));
            }
            e = new ASN1Sequence(type.getType(), l);
            break;
        case SYNC_ID_SET:
            l = new ArrayList<>(3);
            if (cookie != null) {
                l.add(cookie);
            }
            if (refreshDeletes) {
                l.add(new ASN1Boolean(refreshDeletes));
            }
            final ArrayList<ASN1Element> uuidElements = new ArrayList<>(entryUUIDs.size());
            for (final UUID uuid : entryUUIDs) {
                uuidElements.add(new ASN1OctetString(StaticUtils.encodeUUID(uuid)));
            }
            l.add(new ASN1Set(uuidElements));
            e = new ASN1Sequence(type.getType(), l);
            break;
        default:
            // This should never happen.
            throw new AssertionError("Unexpected sync info type:  " + type.name());
    }
    return new ASN1OctetString(e.encode());
}
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) UUID(java.util.UUID) NotNull(com.unboundid.util.NotNull)

Aggregations

ASN1Boolean (com.unboundid.asn1.ASN1Boolean)51 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)51 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)51 ASN1Element (com.unboundid.asn1.ASN1Element)38 NotNull (com.unboundid.util.NotNull)32 ArrayList (java.util.ArrayList)32 ASN1Integer (com.unboundid.asn1.ASN1Integer)15 Test (org.testng.annotations.Test)14 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)12 ASN1Boolean (com.github.zhenwei.core.asn1.ASN1Boolean)5 Nullable (com.unboundid.util.Nullable)5 IOException (java.io.IOException)5 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)4 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)4 ASN1TaggedObject (com.github.zhenwei.core.asn1.ASN1TaggedObject)4 ASN1Set (com.unboundid.asn1.ASN1Set)4 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)3 ASN1Long (com.unboundid.asn1.ASN1Long)3 Control (com.unboundid.ldap.sdk.Control)3 ASN1Boolean (org.bouncycastle.asn1.ASN1Boolean)3