diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 20:55:57 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 20:55:57 +0700 |
commit | e049cab36e9e68adff298acc24acdaa2551f72ef (patch) | |
tree | e772d623791461cba50b1eba3bbd4f833f893ae9 /crypto/src/cms | |
parent | Add Objects class (diff) | |
download | BouncyCastle.NET-ed25519-e049cab36e9e68adff298acc24acdaa2551f72ef.tar.xz |
Refactoring around Stream signers
Diffstat (limited to 'crypto/src/cms')
-rw-r--r-- | crypto/src/cms/CMSSignedDataGenerator.cs | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/crypto/src/cms/CMSSignedDataGenerator.cs b/crypto/src/cms/CMSSignedDataGenerator.cs index 596c6a130..3a612a635 100644 --- a/crypto/src/cms/CMSSignedDataGenerator.cs +++ b/crypto/src/cms/CMSSignedDataGenerator.cs @@ -131,39 +131,40 @@ namespace Org.BouncyCastle.Cms outer.m_digests.Add(digestOID, (byte[])hash.Clone()); } - IStreamCalculator calculator = sigCalc.CreateCalculator(); - Stream sigStr = new BufferedStream(calculator.Stream); - Asn1Set signedAttr = null; - if (sAttr != null) - { - var parameters = outer.GetBaseParameters(contentType, digAlgId, hash); - -// Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(Collections.unmodifiableMap(parameters)); - Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(parameters); - - if (contentType == null) //counter signature - { - if (signed != null && signed[CmsAttributes.ContentType] != null) - { - signed = signed.Remove(CmsAttributes.ContentType); - } - } - // TODO Validate proposed signed attributes - - signedAttr = outer.GetAttributeSet(signed); - - // sig must be composed from the DER encoding. - signedAttr.EncodeTo(sigStr, Asn1Encodable.Der); - } - else if (content != null) + IStreamCalculator calculator = sigCalc.CreateCalculator(); + using (Stream sigStr = calculator.Stream) { - // TODO Use raw signature of the hash value instead - content.Write(sigStr); - } + if (sAttr != null) + { + var parameters = outer.GetBaseParameters(contentType, digAlgId, hash); + + //Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(Collections.unmodifiableMap(parameters)); + Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(parameters); + + if (contentType == null) //counter signature + { + if (signed != null && signed[CmsAttributes.ContentType] != null) + { + signed = signed.Remove(CmsAttributes.ContentType); + } + } + + // TODO Validate proposed signed attributes + + signedAttr = outer.GetAttributeSet(signed); + + // sig must be composed from the DER encoding. + signedAttr.EncodeTo(sigStr, Asn1Encodable.Der); + } + else if (content != null) + { + // TODO Use raw signature of the hash value instead + content.Write(sigStr); + } + } - Platform.Dispose(sigStr); byte[] sigBytes = ((IBlockResult)calculator.GetResult()).Collect(); Asn1Set unsignedAttr = null; |