Search in sources :

Example 1 with ASN1ParsingException

use of com.github.zhenwei.core.asn1.ASN1ParsingException in project jmulticard by ctt-gob-es.

the class ExtensionsGenerator method addExtension.

/**
 * Add an extension with the given oid and the passed in byte array to be wrapped in the
 * OCTET STRING associated with the extension.
 *
 * @param oid      OID for the extension.
 * @param critical true if critical, false otherwise.
 * @param value    the byte array to be wrapped.
 */
public void addExtension(ASN1ObjectIdentifier oid, boolean critical, byte[] value) {
    if (extensions.containsKey(oid)) {
        if (dupsAllowed.contains(oid)) {
            Extension existingExtension = (Extension) extensions.get(oid);
            ASN1Sequence seq1 = ASN1Sequence.getInstance(DEROctetString.getInstance(existingExtension.getExtnValue()).getOctets());
            ASN1Sequence seq2 = ASN1Sequence.getInstance(value);
            ASN1EncodableVector items = new ASN1EncodableVector(seq1.size() + seq2.size());
            for (Enumeration en = seq1.getObjects(); en.hasMoreElements(); ) {
                items.add((ASN1Encodable) en.nextElement());
            }
            for (Enumeration en = seq2.getObjects(); en.hasMoreElements(); ) {
                items.add((ASN1Encodable) en.nextElement());
            }
            try {
                extensions.put(oid, new Extension(oid, critical, new DERSequence(items).getEncoded()));
            } catch (IOException e) {
                throw new ASN1ParsingException(e.getMessage(), e);
            }
        } else {
            throw new IllegalArgumentException("extension " + oid + " already added");
        }
    } else {
        extOrdering.addElement(oid);
        extensions.put(oid, new Extension(oid, critical, new DEROctetString(Arrays.clone(value))));
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Enumeration(java.util.Enumeration) DERSequence(org.bouncycastle.asn1.DERSequence) ASN1ParsingException(org.bouncycastle.asn1.ASN1ParsingException) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) IOException(java.io.IOException) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 2 with ASN1ParsingException

use of com.github.zhenwei.core.asn1.ASN1ParsingException in project LinLong-Java by zhenwei1108.

the class AuthEnvelopedDataParser method getAuthAttrs.

public ASN1SetParser getAuthAttrs() throws IOException {
    if (nextObject == null) {
        nextObject = seq.readObject();
    }
    if (nextObject instanceof ASN1TaggedObjectParser) {
        ASN1TaggedObjectParser o = (ASN1TaggedObjectParser) nextObject;
        nextObject = null;
        return (ASN1SetParser) ASN1Util.parseContextBaseUniversal(o, 1, false, BERTags.SET_OF);
    }
    // EncryptedContentInfo is not id-data."
    if (!isData) {
        throw new ASN1ParsingException("authAttrs must be present with non-data content");
    }
    return null;
}
Also used : ASN1TaggedObjectParser(com.github.zhenwei.core.asn1.ASN1TaggedObjectParser) ASN1ParsingException(com.github.zhenwei.core.asn1.ASN1ParsingException) ASN1SetParser(com.github.zhenwei.core.asn1.ASN1SetParser)

Example 3 with ASN1ParsingException

use of com.github.zhenwei.core.asn1.ASN1ParsingException in project LinLong-Java by zhenwei1108.

the class ExtensionsGenerator method addExtension.

/**
 * Add an extension with the given oid and the passed in byte array to be wrapped in the OCTET
 * STRING associated with the extension.
 *
 * @param oid      OID for the extension.
 * @param critical true if critical, false otherwise.
 * @param value    the byte array to be wrapped.
 */
public void addExtension(ASN1ObjectIdentifier oid, boolean critical, byte[] value) {
    if (extensions.containsKey(oid)) {
        if (dupsAllowed.contains(oid)) {
            Extension existingExtension = (Extension) extensions.get(oid);
            ASN1Sequence seq1 = ASN1Sequence.getInstance(DEROctetString.getInstance(existingExtension.getExtnValue()).getOctets());
            ASN1Sequence seq2 = ASN1Sequence.getInstance(value);
            ASN1EncodableVector items = new ASN1EncodableVector(seq1.size() + seq2.size());
            for (Enumeration en = seq1.getObjects(); en.hasMoreElements(); ) {
                items.add((ASN1Encodable) en.nextElement());
            }
            for (Enumeration en = seq2.getObjects(); en.hasMoreElements(); ) {
                items.add((ASN1Encodable) en.nextElement());
            }
            try {
                extensions.put(oid, new Extension(oid, critical, new DERSequence(items).getEncoded()));
            } catch (IOException e) {
                throw new ASN1ParsingException(e.getMessage(), e);
            }
        } else {
            throw new IllegalArgumentException("extension " + oid + " already added");
        }
    } else {
        extOrdering.addElement(oid);
        extensions.put(oid, new Extension(oid, critical, new DEROctetString(value)));
    }
}
Also used : ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) Enumeration(java.util.Enumeration) DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1ParsingException(com.github.zhenwei.core.asn1.ASN1ParsingException) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) IOException(java.io.IOException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString)

Aggregations

ASN1ParsingException (com.github.zhenwei.core.asn1.ASN1ParsingException)2 IOException (java.io.IOException)2 Enumeration (java.util.Enumeration)2 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)1 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)1 ASN1SetParser (com.github.zhenwei.core.asn1.ASN1SetParser)1 ASN1TaggedObjectParser (com.github.zhenwei.core.asn1.ASN1TaggedObjectParser)1 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)1 DERSequence (com.github.zhenwei.core.asn1.DERSequence)1 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)1 ASN1ParsingException (org.bouncycastle.asn1.ASN1ParsingException)1 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1 DERSequence (org.bouncycastle.asn1.DERSequence)1