Search in sources :

Example 11 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence 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 12 with ASN1Sequence

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

the class ReplaceCertificateExtendedResult method encodeValue.

/**
 * Encodes a value for this extended result, if appropriate.
 *
 * @param  oid         The OID to use for the extended result.  It may be
 *                     {@code null} if no OID should be used.
 * @param  toolOutput  The output obtained from running the
 *                     {@code replace-certificate} tool.  It may be
 *                     {@code null} if request processing failed before
 *                     running the tool.
 *
 * @return  The encoded value for this extended result, or {@code null} if
 *          no value should be included.
 */
@Nullable()
public static ASN1OctetString encodeValue(@Nullable final String oid, @Nullable final String toolOutput) {
    if ((oid == null) && (toolOutput == null)) {
        return null;
    }
    final List<ASN1Element> valueElements = new ArrayList<>(1);
    if (toolOutput != null) {
        valueElements.add(new ASN1OctetString(TYPE_TOOL_OUTPUT, toolOutput));
    }
    final ASN1Sequence valueSequence = new ASN1Sequence(valueElements);
    return new ASN1OctetString(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) Nullable(com.unboundid.util.Nullable)

Example 13 with ASN1Sequence

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

the class ReplaceInterServerCertificateExtendedRequest method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the encoded value for a replace inter-server certificate extended
 * request.
 *
 * @param  keyStoreContent
 *              An object with information about how the server should obtain
 *              the new inter-server certificate data.  It must not be
 *              {@code null}.
 * @param  skipCertificateValidation
 *              Indicates whether to skip validation for the new certificate
 *              chain.
 *
 * @return  An ASN.1 octet string containing the encoded request value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ReplaceCertificateKeyStoreContent keyStoreContent, final boolean skipCertificateValidation) {
    Validator.ensureNotNullWithMessage(keyStoreContent, "ReplaceInterServerCertificateExtendedRequest.keyStoreContent must " + "not be null.");
    final List<ASN1Element> elements = new ArrayList<>();
    elements.add(keyStoreContent.encode());
    if (skipCertificateValidation) {
        elements.add(new ASN1Boolean(TYPE_SKIP_CERT_VALIDATION, true));
    }
    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 14 with ASN1Sequence

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

the class SetNotificationDestinationExtendedRequest 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  destinationID       The notification destination ID.  It must not
 *                             be {@code null}.
 * @param  destinationDetails  The implementation-specific details for the
 *                             notification destination.  At least one detail
 *                             value must be provided.
 * @param  changeType          The change type for the destination details.
 *
 * @return  The ASN.1 octet string containing the encoded value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String managerID, @NotNull final String destinationID, @NotNull final Collection<ASN1OctetString> destinationDetails, @Nullable final SetNotificationDestinationChangeType changeType) {
    Validator.ensureNotNull(managerID);
    Validator.ensureNotNull(destinationID);
    Validator.ensureNotNull(destinationDetails);
    Validator.ensureFalse(destinationDetails.isEmpty());
    final ArrayList<ASN1Element> elements = new ArrayList<>(4);
    elements.add(new ASN1OctetString(managerID));
    elements.add(new ASN1OctetString(destinationID));
    elements.add(new ASN1Sequence(new ArrayList<ASN1Element>(destinationDetails)));
    if ((changeType != null) && (changeType != SetNotificationDestinationChangeType.REPLACE)) {
        elements.add(new ASN1Enumerated(BER_TYPE_CHANGE_TYPE, changeType.intValue()));
    }
    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 15 with ASN1Sequence

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

the class SetSubtreeAccessibilityExtendedRequest method encodeValue.

/**
 * Encodes the provided information for use as the extended request value.
 *
 * @param  subtreeBaseDNs      The set of base DNs for the target subtrees.
 *                             It must not be {@code null} or empty.
 * @param  accessibilityState  The accessibility state to use for the target
 *                             subtrees.
 * @param  bypassUserDN        The DN of a user that will be allowed to bypass
 *                             restrictions on the target subtrees.
 *
 * @return  An ASN.1 octet string containing the encoded value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final Collection<String> subtreeBaseDNs, @NotNull final SubtreeAccessibilityState accessibilityState, @Nullable final String bypassUserDN) {
    final Iterator<String> dnIterator = subtreeBaseDNs.iterator();
    final String subtreeBaseDN = dnIterator.next();
    Validator.ensureNotNull(subtreeBaseDN);
    final ArrayList<ASN1Element> elements = new ArrayList<>(4);
    elements.add(new ASN1OctetString(subtreeBaseDN));
    elements.add(new ASN1Enumerated(accessibilityState.intValue()));
    if (bypassUserDN != null) {
        elements.add(new ASN1OctetString(TYPE_BYPASS_USER_DN, bypassUserDN));
    }
    if (dnIterator.hasNext()) {
        final ArrayList<ASN1Element> additionalDNElements = new ArrayList<>(subtreeBaseDNs.size() - 1);
        while (dnIterator.hasNext()) {
            final String additionalDN = dnIterator.next();
            Validator.ensureNotNull(additionalDN);
            additionalDNElements.add(new ASN1OctetString(additionalDN));
        }
        elements.add(new ASN1Sequence(TYPE_ADDITIONAL_SUBTREE_BASE_DNS, additionalDNElements));
    }
    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) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

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