in jvm/src/main/kotlin/com/jetbrains/signatureverifier/bouncycastle/cms/CMSSignedData.kt [455:501]
fun replaceSigners(
signedData: CMSSignedData,
signerInformationStore: SignerInformationStore
): CMSSignedData {
//
// copy
//
val cms = CMSSignedData(signedData)
//
// replace the store
//
cms.signerInfoStore = signerInformationStore
//
// replace the signers in the SignedData object
//
val digestAlgs: MutableSet<AlgorithmIdentifier> = HashSet()
var vec = ASN1EncodableVector()
val it: Iterator<*> = signerInformationStore.signers.iterator()
while (it.hasNext()) {
val signer = it.next() as SignerInformation
CMSUtils.addDigestAlgs(digestAlgs, signer, dgstAlgFinder)
vec.add(signer.toASN1Structure())
}
val digests = CMSUtils.convertToBERSet(digestAlgs)
val signers: ASN1Set = DLSet(vec)
val sD = signedData.signedData.toASN1Primitive() as ASN1Sequence
vec = ASN1EncodableVector()
//
// signers are the last item in the sequence.
//
vec.add(sD.getObjectAt(0)) // version
vec.add(digests)
for (i in 2 until sD.size() - 1) {
vec.add(sD.getObjectAt(i))
}
vec.add(signers)
cms.signedData = SignedData.getInstance(BERSequence(vec))
//
// replace the contentInfo with the new one
//
cms.contentInfo = ContentInfo(cms.contentInfo.contentType, cms.signedData)
return cms
}