Search in sources :

Example 1 with ASN1Enumerated

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

the class GetConfigurationExtendedResult method encodeValue.

/**
 * Creates an ASN.1 octet string containing an encoded representation of the
 * value for a get configuration extended result with the provided
 * information.
 *
 * @param  configurationType  The type of configuration that has been
 *                            returned.
 * @param  fileName           The name of the configuration file that has been
 *                            returned.
 * @param  fileData           The raw data for the configuration file that has
 *                            been returned.
 *
 * @return  An ASN.1 octet string containing an encoded representation of the
 *          value for a get configuration extended result, or {@code null} if
 *          a result with the provided information should not have a value.
 */
@Nullable()
public static ASN1OctetString encodeValue(@Nullable final GetConfigurationType configurationType, @Nullable final String fileName, @Nullable final byte[] fileData) {
    if (configurationType == null) {
        Validator.ensureTrue((fileName == null), "The configuration file name must be null if the configuration " + "type is null.");
        Validator.ensureTrue((fileData == null), "The configuration file data must be null if the configuration " + "type is null.");
        return null;
    }
    Validator.ensureTrue((fileName != null), "The configuration file name must not be null if the configuration " + "type is not null.");
    Validator.ensureTrue((fileData != null), "The configuration file data must not be null if the configuration " + "type is not null.");
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated(TYPE_CONFIG_TYPE, configurationType.getIntValue()), new ASN1OctetString(TYPE_FILE_NAME, fileName), new ASN1OctetString(TYPE_FILE_DATA, fileData));
    return new ASN1OctetString(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) Nullable(com.unboundid.util.Nullable)

Example 2 with ASN1Enumerated

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

the class GetSubtreeAccessibilityExtendedResult method encodeValue.

/**
 * Encodes the value for this extended result using the provided information.
 *
 * @param  restrictions  The set of subtree accessibility restrictions to
 *                       include in the response.  It may be {@code null} if
 *                       this represents an error response, or it may be empty
 *                       if there are no subtree accessibility restrictions
 *                       defined in the server.
 *
 * @return  An ASN.1 octet string containing the properly-encoded value, or
 *          {@code null} if there should be no value.
 */
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final Collection<SubtreeAccessibilityRestriction> restrictions) {
    if (restrictions == null) {
        return null;
    }
    final ArrayList<ASN1Element> elements = new ArrayList<>(restrictions.size());
    for (final SubtreeAccessibilityRestriction r : restrictions) {
        final ArrayList<ASN1Element> restrictionElements = new ArrayList<>(4);
        restrictionElements.add(new ASN1OctetString(TYPE_BASE_DN, r.getSubtreeBaseDN()));
        restrictionElements.add(new ASN1Enumerated(TYPE_STATE, r.getAccessibilityState().intValue()));
        if (r.getBypassUserDN() != null) {
            restrictionElements.add(new ASN1OctetString(TYPE_BYPASS_USER, r.getBypassUserDN()));
        }
        restrictionElements.add(new ASN1OctetString(TYPE_EFFECTIVE_TIME, StaticUtils.encodeGeneralizedTime(r.getEffectiveTime())));
        elements.add(new ASN1Sequence(restrictionElements));
    }
    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) Nullable(com.unboundid.util.Nullable)

Example 3 with ASN1Enumerated

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

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

Example 5 with ASN1Enumerated

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

the class MultiUpdateExtendedRequest method encodeValue.

/**
 * Generates an ASN.1 octet string suitable for use as the value of a
 * multi-update extended request.
 *
 * @param  errorBehavior  The behavior to exhibit if errors are encountered.
 *                        It must not be {@code null}.
 * @param  requests       The  set of requests to be processed.  It must not
 *                        be {@code null} or empty.  Only add, delete, modify,
 *                        modify DN, and certain extended requests (as
 *                        determined by the server) should be included.  Each
 *                        request may include zero or more controls that
 *                        should apply only to that request.
 *
 * @return  An ASN.1 octet string suitable for use as the value of a
 *          multi-update extended request.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final MultiUpdateErrorBehavior errorBehavior, @NotNull final List<LDAPRequest> requests) {
    final ArrayList<ASN1Element> requestElements = new ArrayList<>(requests.size());
    for (final LDAPRequest r : requests) {
        final ArrayList<ASN1Element> rsElements = new ArrayList<>(2);
        switch(r.getOperationType()) {
            case ADD:
                rsElements.add(((AddRequest) r).encodeProtocolOp());
                break;
            case DELETE:
                rsElements.add(((DeleteRequest) r).encodeProtocolOp());
                break;
            case MODIFY:
                rsElements.add(((ModifyRequest) r).encodeProtocolOp());
                break;
            case MODIFY_DN:
                rsElements.add(((ModifyDNRequest) r).encodeProtocolOp());
                break;
            case EXTENDED:
                rsElements.add(((ExtendedRequest) r).encodeProtocolOp());
                break;
        }
        if (r.hasControl()) {
            rsElements.add(Control.encodeControls(r.getControls()));
        }
        requestElements.add(new ASN1Sequence(rsElements));
    }
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated(errorBehavior.intValue()), new ASN1Sequence(requestElements));
    return new ASN1OctetString(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) LDAPRequest(com.unboundid.ldap.sdk.LDAPRequest) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) NotNull(com.unboundid.util.NotNull)

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