diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-10-11 17:41:20 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-10-11 17:41:20 +0700 |
commit | 02d07a1f8bd57f4141ef1a1dc006e5f72c1116c5 (patch) | |
tree | fb5b664fda22c03a399d5185d0fe48336961fea7 /crypto/src/cms | |
parent | More PORTABLE fixes (diff) | |
download | BouncyCastle.NET-ed25519-02d07a1f8bd57f4141ef1a1dc006e5f72c1116c5.tar.xz |
Refactoring to support custom ISignatureFactory
- see https://github.com/bcgit/bc-csharp/issues/153
Diffstat (limited to 'crypto/src/cms')
-rw-r--r-- | crypto/src/cms/CMSAuthenticatedDataGenerator.cs | 2 | ||||
-rw-r--r-- | crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs | 2 | ||||
-rw-r--r-- | crypto/src/cms/CMSEnvelopedHelper.cs | 2 | ||||
-rw-r--r-- | crypto/src/cms/CMSSignedDataGenerator.cs | 3 | ||||
-rw-r--r-- | crypto/src/cms/CMSSignedDataStreamGenerator.cs | 2 | ||||
-rw-r--r-- | crypto/src/cms/DigOutputStream.cs | 28 | ||||
-rw-r--r-- | crypto/src/cms/MacOutputStream.cs | 28 | ||||
-rw-r--r-- | crypto/src/cms/SigOutputStream.cs | 43 | ||||
-rw-r--r-- | crypto/src/cms/SignerInformation.cs | 14 |
9 files changed, 17 insertions, 107 deletions
diff --git a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs index 131a4753f..addd14c7d 100644 --- a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs +++ b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs @@ -80,7 +80,7 @@ namespace Org.BouncyCastle.Cms mac.Init(encKey); MemoryStream bOut = new MemoryStream(); - Stream mOut = new TeeOutputStream(bOut, new MacOutputStream(mac)); + Stream mOut = new TeeOutputStream(bOut, new MacSink(mac)); content.Write(mOut); diff --git a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs index 4d18d10d4..9d9e2450c 100644 --- a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs @@ -168,7 +168,7 @@ namespace Org.BouncyCastle.Cms IMac mac = MacUtilities.GetMac(macAlgId.Algorithm); // TODO Confirm no ParametersWithRandom needed mac.Init(cipherParameters); - Stream mOut = new TeeOutputStream(octetOutputStream, new MacOutputStream(mac)); + Stream mOut = new TeeOutputStream(octetOutputStream, new MacSink(mac)); return new CmsAuthenticatedDataOutputStream(mOut, mac, cGen, authGen, eiGen); } diff --git a/crypto/src/cms/CMSEnvelopedHelper.cs b/crypto/src/cms/CMSEnvelopedHelper.cs index 77d2da47a..930ffcbf1 100644 --- a/crypto/src/cms/CMSEnvelopedHelper.cs +++ b/crypto/src/cms/CMSEnvelopedHelper.cs @@ -223,7 +223,7 @@ namespace Org.BouncyCastle.Cms return new CmsProcessableInputStream( new TeeInputStream( readable.GetInputStream(), - new MacOutputStream(this.mac))); + new MacSink(this.mac))); } catch (IOException e) { diff --git a/crypto/src/cms/CMSSignedDataGenerator.cs b/crypto/src/cms/CMSSignedDataGenerator.cs index 5aa5f92ab..f2676a440 100644 --- a/crypto/src/cms/CMSSignedDataGenerator.cs +++ b/crypto/src/cms/CMSSignedDataGenerator.cs @@ -6,6 +6,7 @@ using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Cms; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Crypto.IO; using Org.BouncyCastle.Security; using Org.BouncyCastle.Security.Certificates; using Org.BouncyCastle.Utilities; @@ -128,7 +129,7 @@ namespace Org.BouncyCastle.Cms IDigest dig = Helper.GetDigestInstance(digestName); if (content != null) { - content.Write(new DigOutputStream(dig)); + content.Write(new DigestSink(dig)); } hash = DigestUtilities.DoFinal(dig); outer._digests.Add(digestOID, hash.Clone()); diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs index 1cea087f3..0a3e0c87e 100644 --- a/crypto/src/cms/CMSSignedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSSignedDataStreamGenerator.cs @@ -746,7 +746,7 @@ namespace Org.BouncyCastle.Cms Stream result = s; foreach (IDigest digest in digests) { - result = GetSafeTeeOutputStream(result, new DigOutputStream(digest)); + result = GetSafeTeeOutputStream(result, new DigestSink(digest)); } return result; } diff --git a/crypto/src/cms/DigOutputStream.cs b/crypto/src/cms/DigOutputStream.cs deleted file mode 100644 index 103b45cac..000000000 --- a/crypto/src/cms/DigOutputStream.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Utilities.IO; - -namespace Org.BouncyCastle.Cms -{ - internal class DigOutputStream - : BaseOutputStream - { - private readonly IDigest dig; - - internal DigOutputStream(IDigest dig) - { - this.dig = dig; - } - - public override void WriteByte(byte b) - { - dig.Update(b); - } - - public override void Write(byte[] b, int off, int len) - { - dig.BlockUpdate(b, off, len); - } - } -} diff --git a/crypto/src/cms/MacOutputStream.cs b/crypto/src/cms/MacOutputStream.cs deleted file mode 100644 index 8891dbc2c..000000000 --- a/crypto/src/cms/MacOutputStream.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Utilities.IO; - -namespace Org.BouncyCastle.Cms -{ - internal class MacOutputStream - : BaseOutputStream - { - private readonly IMac mac; - - internal MacOutputStream(IMac mac) - { - this.mac = mac; - } - - public override void Write(byte[] b, int off, int len) - { - mac.BlockUpdate(b, off, len); - } - - public override void WriteByte(byte b) - { - mac.Update(b); - } - } -} diff --git a/crypto/src/cms/SigOutputStream.cs b/crypto/src/cms/SigOutputStream.cs deleted file mode 100644 index a807fa7fc..000000000 --- a/crypto/src/cms/SigOutputStream.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; - -using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Utilities.IO; -using Org.BouncyCastle.Security; - -namespace Org.BouncyCastle.Cms -{ - internal class SigOutputStream - : BaseOutputStream - { - private readonly ISigner sig; - - internal SigOutputStream(ISigner sig) - { - this.sig = sig; - } - - public override void WriteByte(byte b) - { - try - { - sig.Update(b); - } - catch (SignatureException e) - { - throw new CmsStreamException("signature problem: " + e); - } - } - - public override void Write(byte[] b, int off, int len) - { - try - { - sig.BlockUpdate(b, off, len); - } - catch (SignatureException e) - { - throw new CmsStreamException("signature problem: " + e); - } - } - } -} \ No newline at end of file diff --git a/crypto/src/cms/SignerInformation.cs b/crypto/src/cms/SignerInformation.cs index 39ecfa6d3..c262806a8 100644 --- a/crypto/src/cms/SignerInformation.cs +++ b/crypto/src/cms/SignerInformation.cs @@ -8,6 +8,7 @@ using Org.BouncyCastle.Asn1.Cms; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Engines; +using Org.BouncyCastle.Crypto.IO; using Org.BouncyCastle.Crypto.Signers; using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; @@ -387,7 +388,7 @@ namespace Org.BouncyCastle.Cms { if (content != null) { - content.Write(new DigOutputStream(digest)); + content.Write(new DigestSink(digest)); } else if (signedAttributeSet == null) { @@ -485,8 +486,15 @@ namespace Org.BouncyCastle.Cms } else if (content != null) { - // TODO Use raw signature of the hash value instead - content.Write(new SigOutputStream(sig)); + try + { + // TODO Use raw signature of the hash value instead + content.Write(new SignerSink(sig)); + } + catch (SignatureException e) + { + throw new CmsStreamException("signature problem: " + e); + } } } else |