Search in sources :

Example 11 with ASN1Enumerated

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

the class JoinResultControl method encodeValue.

/**
 * Encodes the provided information as appropriate for use as the value of
 * this control.
 *
 * @param  resultCode         The result code for the join processing.  It
 *                            must not be {@code null}.
 * @param  diagnosticMessage  A message with additional information about the
 *                            result of the join processing.  It may be
 *                            {@code null} if no message is needed.
 * @param  matchedDN          The matched DN for the join processing.  It may
 *                            be {@code null} if no matched DN is needed.
 * @param  referralURLs       The set of referral URLs for any referrals
 *                            encountered while processing the join.  It may
 *                            be {@code null} or empty if no referral URLs
 *                            are needed.
 * @param  joinResults        The set of entries that have been joined with
 *                            associated search result entry.    It may be
 *                            {@code null} or empty if no entries were joined
 *                            with the search result entry.
 *
 * @return  An ASN.1 element containing an encoded representation of the
 *          value for this control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ResultCode resultCode, @Nullable final String diagnosticMessage, @Nullable final String matchedDN, @Nullable final List<String> referralURLs, @Nullable final List<JoinedEntry> joinResults) {
    Validator.ensureNotNull(resultCode);
    final ArrayList<ASN1Element> elements = new ArrayList<>(5);
    elements.add(new ASN1Enumerated(resultCode.intValue()));
    if (matchedDN == null) {
        elements.add(new ASN1OctetString());
    } else {
        elements.add(new ASN1OctetString(matchedDN));
    }
    if (diagnosticMessage == null) {
        elements.add(new ASN1OctetString());
    } else {
        elements.add(new ASN1OctetString(diagnosticMessage));
    }
    if ((referralURLs != null) && (!referralURLs.isEmpty())) {
        final ArrayList<ASN1Element> refElements = new ArrayList<>(referralURLs.size());
        for (final String s : referralURLs) {
            refElements.add(new ASN1OctetString(s));
        }
        elements.add(new ASN1Sequence(TYPE_REFERRAL_URLS, refElements));
    }
    if ((joinResults == null) || joinResults.isEmpty()) {
        elements.add(new ASN1Sequence(TYPE_JOIN_RESULTS));
    } else {
        final ArrayList<ASN1Element> entryElements = new ArrayList<>(joinResults.size());
        for (final JoinedEntry e : joinResults) {
            entryElements.add(e.encode());
        }
        elements.add(new ASN1Sequence(TYPE_JOIN_RESULTS, entryElements));
    }
    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 12 with ASN1Enumerated

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

the class AssuredReplicationResponseControl method encodeValue.

/**
 * Encodes the provided information to an ASN.1 octet string suitable for
 * use as an assured replication response control value.
 *
 * @param  localLevel                The local assurance level selected by the
 *                                   server for the associated operation.  It
 *                                   may be {@code null} if this is not
 *                                   available.
 * @param  localAssuranceSatisfied   Indicates whether the desired local level
 *                                   of assurance is known to have been
 *                                   satisfied.
 * @param  localAssuranceMessage     An optional message providing additional
 *                                   information about local assurance
 *                                   processing.  This may be {@code null} if
 *                                   no additional message is needed.
 * @param  remoteLevel               The remote assurance level selected by
 *                                   the server for the associated operation.
 *                                   It may be {@code null} if this is not
 *                                   available.
 * @param  remoteAssuranceSatisfied  Indicates whether the desired remote
 *                                   level of assurance is known to have been
 *                                   satisfied.
 * @param  remoteAssuranceMessage    An optional message providing additional
 *                                   information about remote assurance
 *                                   processing.  This may be {@code null} if
 *                                   no additional message is needed.
 * @param  csn                       The change sequence number (CSN) that has
 *                                   been assigned to the associated
 *                                   operation.  It may be {@code null} if no
 *                                   CSN is available.
 * @param  serverResults             The set of individual results from the
 *                                   local and/or remote replication servers
 *                                   and/or directory servers used in
 *                                   assurance processing.  This may be
 *                                   {@code null} or empty if no server
 *                                   results are available.
 *
 * @return  The ASN.1 octet string containing the encoded value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@Nullable final AssuredReplicationLocalLevel localLevel, final boolean localAssuranceSatisfied, @Nullable final String localAssuranceMessage, @Nullable final AssuredReplicationRemoteLevel remoteLevel, final boolean remoteAssuranceSatisfied, @Nullable final String remoteAssuranceMessage, @Nullable final String csn, @Nullable final Collection<AssuredReplicationServerResult> serverResults) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(8);
    if (localLevel != null) {
        elements.add(new ASN1Enumerated(TYPE_LOCAL_LEVEL, localLevel.intValue()));
    }
    elements.add(new ASN1Boolean(TYPE_LOCAL_SATISFIED, localAssuranceSatisfied));
    if (localAssuranceMessage != null) {
        elements.add(new ASN1OctetString(TYPE_LOCAL_MESSAGE, localAssuranceMessage));
    }
    if (remoteLevel != null) {
        elements.add(new ASN1Enumerated(TYPE_REMOTE_LEVEL, remoteLevel.intValue()));
    }
    elements.add(new ASN1Boolean(TYPE_REMOTE_SATISFIED, remoteAssuranceSatisfied));
    if (remoteAssuranceMessage != null) {
        elements.add(new ASN1OctetString(TYPE_REMOTE_MESSAGE, remoteAssuranceMessage));
    }
    if (csn != null) {
        elements.add(new ASN1OctetString(TYPE_CSN, csn));
    }
    if ((serverResults != null) && (!serverResults.isEmpty())) {
        final ArrayList<ASN1Element> srElements = new ArrayList<>(serverResults.size());
        for (final AssuredReplicationServerResult r : serverResults) {
            srElements.add(r.encode());
        }
        elements.add(new ASN1Sequence(TYPE_SERVER_RESULTS, srElements));
    }
    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) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 13 with ASN1Enumerated

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

the class AssuredReplicationServerResult method encode.

/**
 * Encodes this assured replication server result to an ASN.1 element suitable
 * for use in a {@link AssuredReplicationResponseControl}.
 *
 * @return  The encoded representation of this assured replication server
 *          result.
 */
@NotNull()
ASN1Element encode() {
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(new ASN1Enumerated(TYPE_RESULT_CODE, resultCode.intValue()));
    if (replicationServerID != null) {
        elements.add(new ASN1Integer(TYPE_SERVER_ID, replicationServerID));
    }
    if (replicaID != null) {
        elements.add(new ASN1Integer(TYPE_REPLICA_ID, replicaID));
    }
    return new ASN1Sequence(elements);
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Integer(com.unboundid.asn1.ASN1Integer) NotNull(com.unboundid.util.NotNull)

Example 14 with ASN1Enumerated

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

the class CollectSupportDataExtendedRequestTestCase method testDecodeUndefinedSecurityLevel.

/**
 * Tests the behavior when trying to decode an extended request that has an
 * undefined security level.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeUndefinedSecurityLevel() throws Exception {
    final TestCollectSupportDataIntermediateResponseListener listener = new TestCollectSupportDataIntermediateResponseListener();
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated((byte) 0x86, 1234));
    new CollectSupportDataExtendedRequest(new ExtendedRequest("1.3.6.1.4.1.30221.2.6.64", new ASN1OctetString(valueSequence.encode())), listener);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) Test(org.testng.annotations.Test)

Example 15 with ASN1Enumerated

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

the class UniquenessRequestControlTestCase method testDecodeControlValueSequenceInvalidPostCommitValidationLevel.

/**
 * Tests the behavior when trying to decode a control whose value sequence has
 * an invalid multiple post-commit validation level value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceInvalidPostCommitValidationLevel() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "uniqueness-id"), new ASN1Set((byte) 0xA1, new ASN1OctetString("uid")), new ASN1Enumerated((byte) 0x87, 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)

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