Search in sources :

Example 16 with ASN1Integer

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

the class RSAPrivateKeyTestCase method testDecodeKeyInvalidVersion.

/**
 * Tests the behavior when trying to decode a private key with an invalid
 * version.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testDecodeKeyInvalidVersion() throws Exception {
    final ASN1Sequence pkSequence = new ASN1Sequence(new ASN1Integer(123), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE));
    new RSAPrivateKey(new ASN1OctetString(pkSequence.encode()));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Example 17 with ASN1Integer

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

the class PersistentSearchRequestControl method encodeValue.

/**
 * Encodes the provided information into an octet string that can be used as
 * the value for this control.
 *
 * @param  changeTypes  The set of change types for which to register.  It
 *                      must not be {@code null} or empty.
 * @param  changesOnly  Indicates whether the search should only return search
 *                      result entries for changes made to entries matching
 *                      the search criteria, or if existing matching entries
 *                      in the server should be returned as well.
 * @param  returnECs    Indicates whether the search result entries returned
 *                      as part of this persistent search should include the
 *                      entry change notification control.
 *
 * @return  An ASN.1 octet string that can be used as the value for this
 *          control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final Set<PersistentSearchChangeType> changeTypes, final boolean changesOnly, final boolean returnECs) {
    Validator.ensureNotNull(changeTypes);
    Validator.ensureFalse(changeTypes.isEmpty(), "PersistentSearchRequestControl.changeTypes must not be empty.");
    final ASN1Element[] elements = { new ASN1Integer(PersistentSearchChangeType.encodeChangeTypes(changeTypes)), new ASN1Boolean(changesOnly), new ASN1Boolean(returnECs) };
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Integer(com.unboundid.asn1.ASN1Integer) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 18 with ASN1Integer

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

the class ActiveDirectoryDirSyncControl method encodeValue.

/**
 * Encodes the provided information into a format appropriate for use as the
 * value of a DirSync control.
 *
 * @param  flags              The value of the flags that should be used for
 *                            DirSync operation.  This should be zero if no
 *                            special flags or needed, or a bitwise OR of the
 *                            values of the individual flags that are desired.
 * @param  maxAttributeCount  The maximum number of attributes to return.
 * @param  cookie             A cookie that may be used to resume a previous
 *                            DirSync search.  This may be {@code null} if
 *                            no previous cookie is available.
 *
 * @return  An ASN.1 octet string containing the encoded control value.
 */
@NotNull()
private static ASN1OctetString encodeValue(final int flags, final int maxAttributeCount, @Nullable final ASN1OctetString cookie) {
    final ASN1Element[] valueElements = new ASN1Element[3];
    valueElements[0] = new ASN1Integer(flags);
    valueElements[1] = new ASN1Integer(maxAttributeCount);
    if (cookie == null) {
        valueElements[2] = new ASN1OctetString();
    } else {
        valueElements[2] = cookie;
    }
    return new ASN1OctetString(new ASN1Sequence(valueElements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Integer(com.unboundid.asn1.ASN1Integer) NotNull(com.unboundid.util.NotNull)

Example 19 with ASN1Integer

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

the class MatchingEntryCountRequestControlTestCase method testDecodeValueSequenceNegativeMaxCandidatesToExamine.

/**
 * Tests the behavior when trying to decode a control whose value sequence
 * includes a max candidates to examine element with a negative value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceNegativeMaxCandidatesToExamine() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Integer((byte) 0x80, -1));
    new MatchingEntryCountRequestControl(new Control("1.3.6.1.4.1.30221.2.5.36", true, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Example 20 with ASN1Integer

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

the class MatchingEntryCountResponseControlTestCase method testDecodeNegativeZeroUpperBound.

/**
 * Tests the behavior when trying to decode a control whose value sequence
 * contains an upper bound value of zero.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeNegativeZeroUpperBound() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Integer((byte) 0x82, -1));
    new MatchingEntryCountResponseControl("1.3.6.1.4.1.30221.2.5.37", false, new ASN1OctetString(valueSequence.encode()));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Aggregations

ASN1Integer (org.bouncycastle.asn1.ASN1Integer)213 ASN1Integer (com.unboundid.asn1.ASN1Integer)96 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)94 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)91 IOException (java.io.IOException)90 DERSequence (org.bouncycastle.asn1.DERSequence)89 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)86 BigInteger (java.math.BigInteger)86 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)80 ASN1Element (com.unboundid.asn1.ASN1Element)69 Test (org.testng.annotations.Test)63 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)52 DERSequence (com.github.zhenwei.core.asn1.DERSequence)50 ArrayList (java.util.ArrayList)50 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)47 DEROctetString (org.bouncycastle.asn1.DEROctetString)38 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)35 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)28 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)27 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)27