use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.
the class CMSSignedData method replaceSigners.
/**
* Replace the SignerInformation store associated with this CMSSignedData object with the new one
* passed in. You would probably only want to do this if you wanted to change the unsigned
* attributes associated with a signer, or perhaps delete one.
*
* @param signedData the signed data object to be used as a base.
* @param signerInformationStore the new signer information store to use.
* @return a new signed data object.
*/
public static CMSSignedData replaceSigners(CMSSignedData signedData, SignerInformationStore signerInformationStore) {
//
// copy
//
CMSSignedData cms = new CMSSignedData(signedData);
//
// replace the store
//
cms.signerInfoStore = signerInformationStore;
//
// replace the signers in the SignedData object
//
Set<AlgorithmIdentifier> digestAlgs = new HashSet<AlgorithmIdentifier>();
ASN1EncodableVector vec = new ASN1EncodableVector();
Iterator it = signerInformationStore.getSigners().iterator();
while (it.hasNext()) {
SignerInformation signer = (SignerInformation) it.next();
CMSUtils.addDigestAlgs(digestAlgs, signer, dgstAlgFinder);
vec.add(signer.toASN1Structure());
}
ASN1Set digests = CMSUtils.convertToBERSet(digestAlgs);
ASN1Set signers = new DLSet(vec);
ASN1Sequence sD = (ASN1Sequence) signedData.signedData.toASN1Primitive();
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() - 1; i++) {
vec.add(sD.getObjectAt(i));
}
vec.add(signers);
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 AuthEnvelopedData method toASN1Primitive.
/**
* Produce an object suitable for an ASN1OutputStream.
*/
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(7);
v.add(version);
if (originatorInfo != null) {
v.add(new DERTaggedObject(false, 0, originatorInfo));
}
v.add(recipientInfos);
v.add(authEncryptedContentInfo);
// "authAttrs optionally contains the authenticated attributes."
if (authAttrs != null) {
// "AuthAttributes MUST be DER encoded, even if the rest of the
// AuthEnvelopedData structure is BER encoded."
v.add(new DERTaggedObject(false, 1, authAttrs));
}
v.add(mac);
// "unauthAttrs optionally contains the unauthenticated attributes."
if (unauthAttrs != null) {
v.add(new DERTaggedObject(false, 2, unauthAttrs));
}
return new BERSequence(v);
}
use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.
the class ContentInfo method toASN1Primitive.
/**
* Produce an object suitable for an ASN1OutputStream.
*/
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(2);
v.add(contentType);
if (content != null) {
v.add(new BERTaggedObject(0, content));
}
return new BERSequence(v);
}
use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.
the class EncryptedData method toASN1Primitive.
/**
* @return a basic ASN.1 object representation.
*/
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(3);
v.add(version);
v.add(encryptedContentInfo);
if (unprotectedAttrs != null) {
v.add(new BERTaggedObject(false, 1, unprotectedAttrs));
}
return new BERSequence(v);
}
use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.
the class EnvelopedData method toASN1Primitive.
/**
* Produce an object suitable for an ASN1OutputStream.
*/
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(5);
v.add(version);
if (originatorInfo != null) {
v.add(new DERTaggedObject(false, 0, originatorInfo));
}
v.add(recipientInfos);
v.add(encryptedContentInfo);
if (unprotectedAttrs != null) {
v.add(new DERTaggedObject(false, 1, unprotectedAttrs));
}
return new BERSequence(v);
}
Aggregations