Search in sources :

Example 11 with BERSequence

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

the class CMSSignedData method addDigestAlgorithm.

/**
 * Return a new CMSSignedData which guarantees to have the passed in digestAlgorithm in it.
 *
 * @param signedData      the signed data object to be used as a base.
 * @param digestAlgorithm the digest algorithm to be added to the signed data.
 * @return a new signed data object.
 */
public static CMSSignedData addDigestAlgorithm(CMSSignedData signedData, AlgorithmIdentifier digestAlgorithm) {
    Set<AlgorithmIdentifier> digestAlgorithms = signedData.getDigestAlgorithmIDs();
    AlgorithmIdentifier digestAlg = CMSSignedHelper.INSTANCE.fixDigestAlgID(digestAlgorithm, dgstAlgFinder);
    // 
    if (digestAlgorithms.contains(digestAlg)) {
        return signedData;
    }
    // 
    // copy
    // 
    CMSSignedData cms = new CMSSignedData(signedData);
    // 
    // build up the new set
    // 
    Set<AlgorithmIdentifier> digestAlgs = new HashSet<AlgorithmIdentifier>();
    Iterator it = digestAlgorithms.iterator();
    while (it.hasNext()) {
        digestAlgs.add(CMSSignedHelper.INSTANCE.fixDigestAlgID((AlgorithmIdentifier) it.next(), dgstAlgFinder));
    }
    digestAlgs.add(digestAlg);
    ASN1Set digests = CMSUtils.convertToBERSet(digestAlgs);
    ASN1Sequence sD = (ASN1Sequence) signedData.signedData.toASN1Primitive();
    ASN1EncodableVector vec = new ASN1EncodableVector();
    // 
    // signers are the last item in the sequence.
    // 
    // version
    vec.add(sD.getObjectAt(0));
    vec.add(digests);
    for (int i = 2; i != sD.size(); i++) {
        vec.add(sD.getObjectAt(i));
    }
    cms.signedData = SignedData.getInstance(new BERSequence(vec));
    // 
    // replace the contentInfo with the new one
    // 
    cms.contentInfo = new ContentInfo(cms.contentInfo.getContentType(), cms.signedData);
    return cms;
}
Also used : ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) ContentInfo(com.github.zhenwei.pkix.util.asn1.cms.ContentInfo) BERSequence(com.github.zhenwei.core.asn1.BERSequence) Iterator(java.util.Iterator) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) HashSet(java.util.HashSet)

Example 12 with BERSequence

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

the class AuthenticatedData method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(9);
    v.add(version);
    if (originatorInfo != null) {
        v.add(new DERTaggedObject(false, 0, originatorInfo));
    }
    v.add(recipientInfos);
    v.add(macAlgorithm);
    if (digestAlgorithm != null) {
        v.add(new DERTaggedObject(false, 1, digestAlgorithm));
    }
    v.add(encapsulatedContentInfo);
    if (authAttrs != null) {
        v.add(new DERTaggedObject(false, 2, authAttrs));
    }
    v.add(mac);
    if (unauthAttrs != null) {
        v.add(new DERTaggedObject(false, 3, unauthAttrs));
    }
    return new BERSequence(v);
}
Also used : DERTaggedObject(com.github.zhenwei.core.asn1.DERTaggedObject) BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 13 with BERSequence

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

the class CompressedData method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(3);
    v.add(version);
    v.add(compressionAlgorithm);
    v.add(encapContentInfo);
    return new BERSequence(v);
}
Also used : BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 14 with BERSequence

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

the class DigestedData method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(4);
    v.add(version);
    v.add(digestAlgorithm);
    v.add(encapContentInfo);
    v.add(digest);
    return new BERSequence(v);
}
Also used : BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 15 with BERSequence

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

the class EncryptedContentInfo method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(3);
    v.add(contentType);
    v.add(contentEncryptionAlgorithm);
    if (encryptedContent != null) {
        v.add(new BERTaggedObject(false, 0, encryptedContent));
    }
    return new BERSequence(v);
}
Also used : BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) BERTaggedObject(com.github.zhenwei.core.asn1.BERTaggedObject)

Aggregations

BERSequence (org.bouncycastle.asn1.BERSequence)21 BERSequence (com.github.zhenwei.core.asn1.BERSequence)18 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)18 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)17 BERTaggedObject (org.bouncycastle.asn1.BERTaggedObject)11 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)7 BERTaggedObject (com.github.zhenwei.core.asn1.BERTaggedObject)6 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)6 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)6 ASN1Set (org.bouncycastle.asn1.ASN1Set)6 HashSet (java.util.HashSet)5 Iterator (java.util.Iterator)5 ASN1Set (com.github.zhenwei.core.asn1.ASN1Set)4 Enumeration (java.util.Enumeration)4 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)3 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)3 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 BERApplicationSpecific (org.bouncycastle.asn1.BERApplicationSpecific)3 BERConstructedOctetString (org.bouncycastle.asn1.BERConstructedOctetString)3