use of org.webpki.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 org.webpki.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 org.webpki.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 org.webpki.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 org.webpki.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class GetSupportedOTPDeliveryMechanismsExtendedResult method encodeValue.
/**
* Encodes the provided information into an appropriate format for the value
* of this extended operation.
*
* @param resultCode The result code from the response. It must
* not be {@code null}.
* @param deliveryMechanismInfo The set of supported delivery mechanism info
* for the result, if appropriate. It should
* be {@code null} or empty for non-success
* results.
*
* @return The ASN.1 octet string containing the encoded value.
*/
@Nullable()
private static ASN1OctetString encodeValue(@NotNull final ResultCode resultCode, @Nullable final Collection<SupportedOTPDeliveryMechanismInfo> deliveryMechanismInfo) {
if (resultCode != ResultCode.SUCCESS) {
return null;
}
if ((deliveryMechanismInfo == null) || deliveryMechanismInfo.isEmpty()) {
return new ASN1OctetString(new ASN1Sequence().encode());
}
final ArrayList<ASN1Element> elements = new ArrayList<>(deliveryMechanismInfo.size());
for (final SupportedOTPDeliveryMechanismInfo i : deliveryMechanismInfo) {
final ArrayList<ASN1Element> infoElements = new ArrayList<>(3);
infoElements.add(new ASN1OctetString(TYPE_DELIVERY_MECHANISM, i.getDeliveryMechanism()));
if (i.isSupported() != null) {
infoElements.add(new ASN1Boolean(TYPE_IS_SUPPORTED, i.isSupported()));
}
if (i.getRecipientID() != null) {
infoElements.add(new ASN1OctetString(TYPE_RECIPIENT_ID, i.getRecipientID()));
}
elements.add(new ASN1Sequence(infoElements));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Aggregations