use of com.unboundid.asn1.ASN1Sequence in project X-Road by nordic-institute.
the class AsicContainerVerifier method getTimeStampToken.
private TimeStampToken getTimeStampToken() throws Exception {
String timestampDerBase64 = asic.getEntryAsString(ENTRY_TIMESTAMP);
byte[] tsDerDecoded = decodeBase64(timestampDerBase64);
return new TimeStampToken(new ContentInfo((ASN1Sequence) ASN1Sequence.fromByteArray(tsDerDecoded)));
}
use of com.unboundid.asn1.ASN1Sequence in project X-Road by nordic-institute.
the class TimestampVerifierTest method getTimestampFromFile.
private static TimeStampToken getTimestampFromFile(String fileName) throws Exception {
byte[] data = getBytesFromFile(fileName);
TimeStampToken token = new TimeStampToken(new ContentInfo((ASN1Sequence) ASN1Sequence.fromByteArray(data)));
assertNotNull(token);
return token;
}
use of com.unboundid.asn1.ASN1Sequence in project sshj by hierynomus.
the class DSAPrivateKeyInfoKeyPairConverter method getDsaParameters.
private DSAParameters getDsaParameters(final AlgorithmIdentifier algorithmIdentifier) {
final ASN1Sequence sequence = ASN1Sequence.getInstance(algorithmIdentifier.getParameters());
final ASN1Integer p = ASN1Integer.getInstance(sequence.getObjectAt(P_INDEX));
final ASN1Integer q = ASN1Integer.getInstance(sequence.getObjectAt(Q_INDEX));
final ASN1Integer g = ASN1Integer.getInstance(sequence.getObjectAt(G_INDEX));
return new DSAParameters(p.getValue(), q.getValue(), g.getValue());
}
use of com.unboundid.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class Filter method encode.
/**
* Encodes this search filter to an ASN.1 element suitable for inclusion in an
* LDAP search request protocol op.
*
* @return An ASN.1 element containing the encoded search filter.
*/
@NotNull()
public ASN1Element encode() {
switch(filterType) {
case FILTER_TYPE_AND:
case FILTER_TYPE_OR:
final ASN1Element[] filterElements = new ASN1Element[filterComps.length];
for (int i = 0; i < filterComps.length; i++) {
filterElements[i] = filterComps[i].encode();
}
return new ASN1Set(filterType, filterElements);
case FILTER_TYPE_NOT:
return new ASN1Element(filterType, notComp.encode().encode());
case FILTER_TYPE_EQUALITY:
case FILTER_TYPE_GREATER_OR_EQUAL:
case FILTER_TYPE_LESS_OR_EQUAL:
case FILTER_TYPE_APPROXIMATE_MATCH:
final ASN1OctetString[] attrValueAssertionElements = { new ASN1OctetString(attrName), assertionValue };
return new ASN1Sequence(filterType, attrValueAssertionElements);
case FILTER_TYPE_SUBSTRING:
final ArrayList<ASN1OctetString> subList = new ArrayList<>(2 + subAny.length);
if (subInitial != null) {
subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBINITIAL, subInitial.getValue()));
}
for (final ASN1Element subAnyElement : subAny) {
subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBANY, subAnyElement.getValue()));
}
if (subFinal != null) {
subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBFINAL, subFinal.getValue()));
}
final ASN1Element[] subFilterElements = { new ASN1OctetString(attrName), new ASN1Sequence(subList) };
return new ASN1Sequence(filterType, subFilterElements);
case FILTER_TYPE_PRESENCE:
return new ASN1OctetString(filterType, attrName);
case FILTER_TYPE_EXTENSIBLE_MATCH:
final ArrayList<ASN1Element> emElementList = new ArrayList<>(4);
if (matchingRuleID != null) {
emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCHING_RULE_ID, matchingRuleID));
}
if (attrName != null) {
emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_ATTRIBUTE_NAME, attrName));
}
emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCH_VALUE, assertionValue.getValue()));
if (dnAttributes) {
emElementList.add(new ASN1Boolean(EXTENSIBLE_TYPE_DN_ATTRIBUTES, true));
}
return new ASN1Sequence(filterType, emElementList);
default:
throw new AssertionError(ERR_FILTER_INVALID_TYPE.get(StaticUtils.toHex(filterType)));
}
}
use of com.unboundid.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class Control method decode.
/**
* Decodes the provided ASN.1 sequence as an LDAP control.
*
* @param controlSequence The ASN.1 sequence to be decoded.
*
* @return The decoded control.
*
* @throws LDAPException If a problem occurs while attempting to decode the
* provided ASN.1 sequence as an LDAP control.
*/
@NotNull()
public static Control decode(@NotNull final ASN1Sequence controlSequence) throws LDAPException {
final ASN1Element[] elements = controlSequence.elements();
if ((elements.length < 1) || (elements.length > 3)) {
throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_DECODE_INVALID_ELEMENT_COUNT.get(elements.length));
}
final String oid = ASN1OctetString.decodeAsOctetString(elements[0]).stringValue();
boolean isCritical = false;
ASN1OctetString value = null;
if (elements.length == 2) {
switch(elements[1].getType()) {
case ASN1Constants.UNIVERSAL_BOOLEAN_TYPE:
try {
isCritical = ASN1Boolean.decodeAsBoolean(elements[1]).booleanValue();
} catch (final ASN1Exception ae) {
Debug.debugException(ae);
throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_DECODE_CRITICALITY.get(StaticUtils.getExceptionMessage(ae)), ae);
}
break;
case ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE:
value = ASN1OctetString.decodeAsOctetString(elements[1]);
break;
default:
throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_INVALID_TYPE.get(StaticUtils.toHex(elements[1].getType())));
}
} else if (elements.length == 3) {
try {
isCritical = ASN1Boolean.decodeAsBoolean(elements[1]).booleanValue();
} catch (final ASN1Exception ae) {
Debug.debugException(ae);
throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_DECODE_CRITICALITY.get(StaticUtils.getExceptionMessage(ae)), ae);
}
value = ASN1OctetString.decodeAsOctetString(elements[2]);
}
return decode(oid, isCritical, value);
}
Aggregations