Search in sources :

Example 56 with ASN1Sequence

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

the class OverrideSearchLimitsRequestControl method encodeValue.

/**
 * Encodes the provided set of properties into an ASN.1 element suitable for
 * use as the value of this control.
 *
 * @param  properties  The map of properties to set in this control.  It must
 *                     not be {@code null} or empty, and none of the keys or
 *                     values inside it may be {@code null} or empty.
 *
 * @return  The ASN.1 octet string containing the encoded value.
 */
@NotNull()
static ASN1OctetString encodeValue(@NotNull final Map<String, String> properties) {
    Validator.ensureTrue(((properties != null) && (!properties.isEmpty())), "OverrideSearchLimitsRequestControl.<init>properties must not be " + "null or empty");
    final ArrayList<ASN1Element> propertyElements = new ArrayList<>(properties.size());
    for (final Map.Entry<String, String> e : properties.entrySet()) {
        final String propertyName = e.getKey();
        final String propertyValue = e.getValue();
        Validator.ensureTrue(((propertyName != null) && (!propertyName.isEmpty())), "OverrideSearchLimitsRequestControl.<init>properties keys must " + "not be null or empty");
        Validator.ensureTrue(((propertyValue != null) && (!propertyValue.isEmpty())), "OverrideSearchLimitsRequestControl.<init>properties values must " + "not be null or empty");
        propertyElements.add(new ASN1Sequence(new ASN1OctetString(propertyName), new ASN1OctetString(propertyValue)));
    }
    return new ASN1OctetString(new ASN1Sequence(propertyElements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NotNull(com.unboundid.util.NotNull)

Example 57 with ASN1Sequence

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

the class InteractiveTransactionSpecificationRequestControl method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value of this control.
 *
 * @param  transactionID   The transaction ID for the associated transaction,
 *                         as obtained from the start interactive transaction
 *                         extended operation.  It must not be {@code null}.
 * @param  abortOnFailure  Indicates whether the transaction should be aborted
 *                         if the associated operation does not complete
 *                         successfully.
 * @param  writeLock       Indicates whether the server should attempt to
 *                         obtain a write lock on the target entry.  This
 *                         should only be {@code false} if the associated
 *                         operation is a search or compare and it is known
 *                         that the target entry will not be updated later in
 *                         the transaction.
 *
 * @return  The ASN.1 octet string containing the encoded value for this
 *          control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString transactionID, final boolean abortOnFailure, final boolean writeLock) {
    Validator.ensureNotNull(transactionID);
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(new ASN1OctetString(TYPE_TXN_ID, transactionID.getValue()));
    if (abortOnFailure) {
        elements.add(new ASN1Boolean(TYPE_ABORT_ON_FAILURE, abortOnFailure));
    }
    if (!writeLock) {
        elements.add(new ASN1Boolean(TYPE_WRITE_LOCK, writeLock));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
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 58 with ASN1Sequence

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

the class GeneratePasswordResponseControl method encodeValue.

/**
 * Encodes the provided information appropriately for use as the value of this
 * control.
 *
 * @param  generatedPassword        The password generated by the server.  It
 *                                 must not be {@code null}.
 * @param  mustChangePassword      Indicates whether the user will be required
 *                                 to choose a new password the first time
 *                                 they authenticate.
 * @param  secondsUntilExpiration  The number of seconds until the new
 *                                 password will expire.  It may be
 *                                 {@code null} if the new password will not
 *                                 expire.
 *
 * @return  The ASN.1 octet string suitable for use as the control value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString generatedPassword, final boolean mustChangePassword, @Nullable final Long secondsUntilExpiration) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(generatedPassword);
    elements.add(mustChangePassword ? ASN1Boolean.UNIVERSAL_BOOLEAN_TRUE_ELEMENT : ASN1Boolean.UNIVERSAL_BOOLEAN_FALSE_ELEMENT);
    if (secondsUntilExpiration != null) {
        elements.add(new ASN1Long(TYPE_SECONDS_UNTIL_EXPIRATION, secondsUntilExpiration));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Long(com.unboundid.asn1.ASN1Long) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) NotNull(com.unboundid.util.NotNull)

Example 59 with ASN1Sequence

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

the class ChangelogEntryIntermediateResponseTestCase method testDecodeValueSequenceWithMalformedElements.

/**
 * Tests the behavior when attempting to decode an intermediate response
 * with a value sequence with a value sequence containing malformed elements.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceWithMalformedElements() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString("foo"), new ASN1OctetString("foo"), new ASN1OctetString("foo"), new ASN1OctetString("foo"));
    new ChangelogEntryIntermediateResponse(new IntermediateResponse(ChangelogEntryIntermediateResponse.CHANGELOG_ENTRY_INTERMEDIATE_RESPONSE_OID, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) Test(org.testng.annotations.Test)

Example 60 with ASN1Sequence

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

the class ChangelogEntryIntermediateResponseTestCase method testDecodeValueSequenceInvalidElementCount.

/**
 * Tests the behavior when attempting to decode an intermediate response
 * with a value sequence with an unexpected number of elements.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidElementCount() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString("foo"));
    new ChangelogEntryIntermediateResponse(new IntermediateResponse(ChangelogEntryIntermediateResponse.CHANGELOG_ENTRY_INTERMEDIATE_RESPONSE_OID, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) Test(org.testng.annotations.Test)

Aggregations

ASN1Sequence (com.unboundid.asn1.ASN1Sequence)455 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)397 Test (org.testng.annotations.Test)311 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)297 ASN1Element (com.unboundid.asn1.ASN1Element)231 ArrayList (java.util.ArrayList)184 IOException (java.io.IOException)141 NotNull (com.unboundid.util.NotNull)116 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)95 ASN1Integer (com.unboundid.asn1.ASN1Integer)94 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)76 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)73 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)69 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)64 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)57 Enumeration (java.util.Enumeration)54 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)53 X509Certificate (java.security.cert.X509Certificate)53 BigInteger (java.math.BigInteger)50