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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations