Search in sources :

Example 16 with ASN1Enumerated

use of com.github.zhenwei.core.asn1.ASN1Enumerated 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)

Example 17 with ASN1Enumerated

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

the class ContentSyncStateControl method encodeValue.

/**
 * Encodes the provided information into a form suitable for use as the value
 * of this control.
 *
 * @param  state      The sync state for the associated entry or reference.
 *                    It must not be {@code null}.
 * @param  entryUUID  The entryUUID for the associated entry or reference.  It
 *                    must not be {@code null}.
 * @param  cookie     A cookie with an updated synchronization state.  It may
 *                    be {@code null} if no updated state is available.
 *
 * @return  An ASN.1 octet string containing the encoded control value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ContentSyncState state, @NotNull final UUID entryUUID, @Nullable final ASN1OctetString cookie) {
    Validator.ensureNotNull(state, entryUUID);
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(new ASN1Enumerated(state.intValue()));
    elements.add(new ASN1OctetString(StaticUtils.encodeUUID(entryUUID)));
    if (cookie != null) {
        elements.add(cookie);
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) NotNull(com.unboundid.util.NotNull)

Example 18 with ASN1Enumerated

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

the class PasswordPolicyResponseControlTestCase method testDecodeControlOnlyError.

/**
 * Tests the {@code decodeControl} method with a valid set of information
 * with only an error element.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDecodeControlOnlyError() throws Exception {
    ASN1Element[] valueElements = { new ASN1Enumerated((byte) 0x81, 1) };
    ASN1OctetString value = new ASN1OctetString(new ASN1Sequence(valueElements).encode());
    PasswordPolicyResponseControl c = new PasswordPolicyResponseControl().decodeControl("1.3.6.1.4.1.42.2.27.8.5.1", false, value);
    assertNull(c.getWarningType());
    assertEquals(c.getWarningValue(), -1);
    assertNotNull(c.getErrorType());
    assertEquals(c.getErrorType(), PasswordPolicyErrorType.ACCOUNT_LOCKED);
    assertNotNull(c.getControlName());
    assertNotNull(c.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) Test(org.testng.annotations.Test)

Example 19 with ASN1Enumerated

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

the class PasswordPolicyResponseControlTestCase method testDecodeControlValueSequenceMultipleValueElements.

/**
 * Tests the {@code decodeControl} method with a value sequence multiple value
 * elements.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceMultipleValueElements() throws Exception {
    ASN1Element[] valueElements = { new ASN1Enumerated((byte) 0x81, 0), new ASN1Enumerated((byte) 0x81, 1) };
    ASN1OctetString value = new ASN1OctetString(new ASN1Sequence(valueElements).encode());
    new PasswordPolicyResponseControl().decodeControl("1.3.6.1.4.1.42.2.27.8.5.1", false, value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) Test(org.testng.annotations.Test)

Example 20 with ASN1Enumerated

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

the class PasswordPolicyResponseControlTestCase method testDecodeControlValueSequenceInvalidErrorType.

/**
 * Tests the {@code decodeControl} method with a value sequence with an
 * invalid error type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceInvalidErrorType() throws Exception {
    ASN1Element[] valueElements = { new ASN1Enumerated((byte) 0x81, 999) };
    ASN1OctetString value = new ASN1OctetString(new ASN1Sequence(valueElements).encode());
    new PasswordPolicyResponseControl().decodeControl("1.3.6.1.4.1.42.2.27.8.5.1", false, value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) Test(org.testng.annotations.Test)

Aggregations

ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)95 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)95 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)92 Test (org.testng.annotations.Test)62 ASN1Element (com.unboundid.asn1.ASN1Element)59 ArrayList (java.util.ArrayList)32 NotNull (com.unboundid.util.NotNull)30 ASN1Integer (com.unboundid.asn1.ASN1Integer)21 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)15 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)12 IOException (java.io.IOException)12 ASN1Set (com.unboundid.asn1.ASN1Set)11 Control (com.unboundid.ldap.sdk.Control)9 ASN1Enumerated (org.bouncycastle.asn1.ASN1Enumerated)9 ASN1Enumerated (com.github.zhenwei.core.asn1.ASN1Enumerated)6 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)6 DEROctetString (org.bouncycastle.asn1.DEROctetString)6 DERSequence (org.bouncycastle.asn1.DERSequence)6 IntermediateResponse (com.unboundid.ldap.sdk.IntermediateResponse)5 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)5