Search in sources :

Example 46 with ASN1Set

use of org.openecard.bouncycastle.asn1.ASN1Set in project jruby-openssl by jruby.

the class Signed method certificatesFromASN1Set.

private static Collection<X509AuxCertificate> certificatesFromASN1Set(ASN1Encodable content) throws PKCS7Exception {
    Collection<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>();
    if (content instanceof ASN1Sequence) {
        try {
            for (Enumeration<?> enm = ((ASN1Sequence) content).getObjects(); enm.hasMoreElements(); ) {
                ASN1Encodable current = (ASN1Encodable) enm.nextElement();
                result.add(certificateFromASN1(current));
            }
        } catch (IllegalArgumentException iae) {
            result.add(certificateFromASN1(content));
        }
    } else if (content instanceof ASN1Set) {
        // EXPLICIT Set shouldn't apper here but keep this for backward compatibility.
        for (Enumeration<?> enm = ((ASN1Set) content).getObjects(); enm.hasMoreElements(); ) {
            ASN1Encodable current = (ASN1Encodable) enm.nextElement();
            result.add(certificateFromASN1(current));
        }
    } else {
        throw new PKCS7Exception(PKCS7.F_B64_READ_PKCS7, PKCS7.R_CERTIFICATE_VERIFY_ERROR, "unknown certificates format");
    }
    return result;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Enumeration(java.util.Enumeration) ASN1Set(org.bouncycastle.asn1.ASN1Set) ArrayList(java.util.ArrayList) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) X509AuxCertificate(org.jruby.ext.openssl.x509store.X509AuxCertificate)

Example 47 with ASN1Set

use of org.openecard.bouncycastle.asn1.ASN1Set in project jruby-openssl by jruby.

the class Envelope method fromASN1.

/**
 * EnvelopedData ::= SEQUENCE {
 *   version Version,
 *   recipientInfos RecipientInfos,
 *   encryptedContentInfo EncryptedContentInfo }
 *
 * Version ::= INTEGER
 *
 * RecipientInfos ::= SET OF RecipientInfo
 */
public static Envelope fromASN1(ASN1Encodable content) {
    ASN1Sequence sequence = (ASN1Sequence) content;
    ASN1Integer version = (ASN1Integer) sequence.getObjectAt(0);
    ASN1Set recipients = (ASN1Set) sequence.getObjectAt(1);
    ASN1Encodable encContent = sequence.getObjectAt(2);
    Envelope envelope = new Envelope();
    envelope.setVersion(version.getValue().intValue());
    envelope.setRecipientInfo(recipientInfosFromASN1Set(recipients));
    envelope.setEncData(EncContent.fromASN1(encContent));
    return envelope;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Set(org.bouncycastle.asn1.ASN1Set) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Aggregations

ASN1Set (org.bouncycastle.asn1.ASN1Set)41 IOException (java.io.IOException)18 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)14 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)13 ArrayList (java.util.ArrayList)11 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)11 DEROctetString (org.bouncycastle.asn1.DEROctetString)9 Enumeration (java.util.Enumeration)8 List (java.util.List)8 CertificateException (java.security.cert.CertificateException)7 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)7 KeyPair (java.security.KeyPair)6 X509Certificate (java.security.cert.X509Certificate)6 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5 ASN1Encodable (com.android.org.bouncycastle.asn1.ASN1Encodable)5 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1Set (com.android.org.bouncycastle.asn1.ASN1Set)5