if (this.parameters.isDataDigested()) {
Attribute attr = new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(data)));
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(attr);
signerInfoGeneratorBuilder.setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(v)));
}
SignerInfoGenerator signerInfoGenerator = signerInfoGeneratorBuilder.build(contentSigner, (X509Certificate) certificate);
signedDataGenerator.addSignerInfoGenerator(signerInfoGenerator);
signedDataGenerator.addCertificates(this.getCertificateStore(chain));
}
CMSTypedData content = null;
boolean encapsulate = true;
if (this.parameters.isDataDigested()) {
content = new CMSAbsentContent();
encapsulate = false;
} else {
if ((this.parameters.isMergeSignatures()) && (this.isSigned(data))) {
CMSSignedData signedData = new CMSSignedData(data);
signedDataGenerator.addSigners(signedData.getSignerInfos());
content = (CMSTypedData) signedData.getSignedContent();
} else {
content = new CMSProcessableByteArray(data);
}
if (PKCS7SignatureMode.DETACHED.equals(mode)) {
encapsulate = false;
}
}
CMSSignedData signedData = null;
if (this.parameters.isDataDigested()) {
signedData = signedDataGenerator.generate(CMSSignedGenerator.DATA, null, false, Security.getProvider(BouncyCastleProviderHelper.PROVIDER_NAME), true);
} else {
signedData = signedDataGenerator.generate(content, encapsulate);
}
if (timeStampClient != null) {
SignerInformationStore signerInformationStore = signedData.getSignerInfos();
List list = new ArrayList();
for (Object o : signerInformationStore.getSigners()) {
SignerInformation signerInformation = (SignerInformation) o;
TimeStamp timeStamp = timeStampClient.getTimeStamp(signerInformation.getSignature());
ASN1Primitive asn1Primitive = BouncyCastleProviderHelper.toASN1Primitive(timeStamp.getEncoded());
DERSet derSet = new DERSet(asn1Primitive);
Hashtable hashtable = new Hashtable();
Attribute attribute = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, derSet);
hashtable.put(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, attribute);
AttributeTable unsignedAtts = new AttributeTable(hashtable);
list.add(SignerInformation.replaceUnsignedAttributes(signerInformation, unsignedAtts));
}
SignerInformationStore tmpSignerInformationStore = new SignerInformationStore(list);