use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class DraftBeheraLDAPPasswordPolicy10ResponseControlTestCase method testDecodeControlAllTypes.
/**
* Tests the {@code decodeControl} method with a valid set of information
* with all element types.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDecodeControlAllTypes() throws Exception {
ASN1Element[] valueElements = { new ASN1Element((byte) 0xA0, new ASN1Integer((byte) 0x80, 12345).encode()), new ASN1Enumerated((byte) 0x81, 0) };
ASN1OctetString value = new ASN1OctetString(new ASN1Sequence(valueElements).encode());
DraftBeheraLDAPPasswordPolicy10ResponseControl c = new DraftBeheraLDAPPasswordPolicy10ResponseControl().decodeControl("1.3.6.1.4.1.42.2.27.8.5.1", false, value);
assertNotNull(c.getWarningType());
assertEquals(c.getWarningType(), DraftBeheraLDAPPasswordPolicy10WarningType.TIME_BEFORE_EXPIRATION);
assertEquals(c.getWarningValue(), 12345);
assertNotNull(c.getErrorType());
assertEquals(c.getErrorType(), DraftBeheraLDAPPasswordPolicy10ErrorType.PASSWORD_EXPIRED);
assertNotNull(c.getControlName());
assertNotNull(c.toString());
}
use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class DraftBeheraLDAPPasswordPolicy10ResponseControlTestCase method testDecodeControlValueSequenceTooManyElements.
/**
* Tests the {@code decodeControl} method with a value sequence with too many
* elements.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceTooManyElements() throws Exception {
ASN1Element[] valueElements = { new ASN1Element((byte) 0xA0, new ASN1Integer((byte) 0x80, 12345).encode()), new ASN1Enumerated((byte) 0x81, 0), new ASN1Integer(0) };
ASN1OctetString value = new ASN1OctetString(new ASN1Sequence(valueElements).encode());
new DraftBeheraLDAPPasswordPolicy10ResponseControl().decodeControl("1.3.6.1.4.1.42.2.27.8.5.1", false, value);
}
use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class CryptoHelperTestCase method testInferKeyStoreTypeSequenceFirstElementIntegerUnexpectedValue.
/**
* Tests the behavior for the {@code inferKeyStoreType} method with a file
* that contains an empty ASN.1 sequence in which the first element is an
* integer with a value that is not 3 (the expected value for a PKCS #12 key
* store).
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testInferKeyStoreTypeSequenceFirstElementIntegerUnexpectedValue() throws Exception {
final File f = createTempFile();
assertTrue(f.delete());
try (FileOutputStream fos = new FileOutputStream(f)) {
new ASN1Sequence(new ASN1Integer(0)).writeTo(fos);
}
try {
CryptoHelper.inferKeyStoreType(f);
fail("Expected an exception from inferKeyStoreType with a file " + "containing an ASN.1 sequence in which the first element is an " + "integer with a value that is not 3");
} catch (final KeyStoreException e) {
// This was expected.
}
}
use of org.webpki.asn1.ASN1Integer in project OpenUnison by TremoloSecurity.
the class X509ExtensionParsingUtil method getInt.
/**
* Extracts an {@code int} from an {@link ASN1Encodable}.
* @throws CertificateParsingException
*/
public static int getInt(ASN1Encodable asn1Encodable) throws CertificateParsingException {
if (asn1Encodable == null || !(asn1Encodable instanceof ASN1Integer)) {
throw new CertificateParsingException("Expected INTEGER type.");
}
ASN1Integer asn1Integer = (ASN1Integer) asn1Encodable;
BigInteger bigInt = asn1Integer.getPositiveValue();
if (bigInt.bitLength() > MAX_INT_BITS) {
throw new CertificateParsingException("INTEGER too big");
}
return bigInt.intValue();
}
use of org.webpki.asn1.ASN1Integer in project OpenUnison by TremoloSecurity.
the class X509ExtensionParsingUtil method getLong.
/**
* Extracts an {@code long} from an {@link ASN1Encodable}.
* @throws CertificateParsingException
*/
public static long getLong(ASN1Encodable asn1Encodable) throws CertificateParsingException {
if (asn1Encodable == null || !(asn1Encodable instanceof ASN1Integer)) {
throw new CertificateParsingException("Expected INTEGER type.");
}
ASN1Integer asn1Integer = (ASN1Integer) asn1Encodable;
BigInteger bigInt = asn1Integer.getPositiveValue();
if (bigInt.bitLength() > MAX_LONG_BITS) {
throw new CertificateParsingException("INTEGER too big");
}
return bigInt.longValue();
}
Aggregations