Search in sources :

Example 1 with ASN1Sequence

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)));
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) TimeStampToken(org.bouncycastle.tsp.TimeStampToken)

Example 2 with ASN1Sequence

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;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) TimeStampToken(org.bouncycastle.tsp.TimeStampToken)

Example 3 with ASN1Sequence

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());
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) DSAParameters(org.bouncycastle.crypto.params.DSAParameters)

Example 4 with ASN1Sequence

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)));
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 5 with ASN1Sequence

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());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) Nullable(com.unboundid.util.Nullable)

Aggregations

ASN1Sequence (com.unboundid.asn1.ASN1Sequence)455 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)397 Test (org.testng.annotations.Test)311 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)297 ASN1Element (com.unboundid.asn1.ASN1Element)231 ArrayList (java.util.ArrayList)184 IOException (java.io.IOException)136 NotNull (com.unboundid.util.NotNull)116 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)95 ASN1Integer (com.unboundid.asn1.ASN1Integer)94 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)76 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)73 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)69 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)64 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)57 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)53 X509Certificate (java.security.cert.X509Certificate)53 Enumeration (java.util.Enumeration)52 BigInteger (java.math.BigInteger)50