Skip to content

Commit 02d07a1

Browse files
committed
Refactoring to support custom ISignatureFactory
- see #153
1 parent 5ba9e20 commit 02d07a1

29 files changed

+406
-337
lines changed

crypto/BouncyCastle.Android.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,13 @@
602602
<Compile Include="src\cms\CounterSignatureDigestCalculator.cs" />
603603
<Compile Include="src\cms\DefaultAuthenticatedAttributeTableGenerator.cs" />
604604
<Compile Include="src\cms\DefaultSignedAttributeTableGenerator.cs" />
605-
<Compile Include="src\cms\DigOutputStream.cs" />
606605
<Compile Include="src\cms\IDigestCalculator.cs" />
607606
<Compile Include="src\cms\KEKRecipientInfoGenerator.cs" />
608607
<Compile Include="src\cms\KEKRecipientInformation.cs" />
609608
<Compile Include="src\cms\KeyAgreeRecipientInfoGenerator.cs" />
610609
<Compile Include="src\cms\KeyAgreeRecipientInformation.cs" />
611610
<Compile Include="src\cms\KeyTransRecipientInfoGenerator.cs" />
612611
<Compile Include="src\cms\KeyTransRecipientInformation.cs" />
613-
<Compile Include="src\cms\MacOutputStream.cs" />
614612
<Compile Include="src\cms\OriginatorId.cs" />
615613
<Compile Include="src\cms\OriginatorInfoGenerator.cs" />
616614
<Compile Include="src\cms\OriginatorInformation.cs" />
@@ -622,7 +620,6 @@
622620
<Compile Include="src\cms\RecipientInfoGenerator.cs" />
623621
<Compile Include="src\cms\RecipientInformation.cs" />
624622
<Compile Include="src\cms\RecipientInformationStore.cs" />
625-
<Compile Include="src\cms\SigOutputStream.cs" />
626623
<Compile Include="src\cms\SignerId.cs" />
627624
<Compile Include="src\cms\SignerInfoGenerator.cs" />
628625
<Compile Include="src\cms\SignerInformation.cs" />
@@ -841,8 +838,11 @@
841838
<Compile Include="src\crypto\generators\X25519KeyPairGenerator.cs" />
842839
<Compile Include="src\crypto\generators\X448KeyPairGenerator.cs" />
843840
<Compile Include="src\crypto\io\CipherStream.cs" />
841+
<Compile Include="src\crypto\io\DigestSink.cs" />
844842
<Compile Include="src\crypto\io\DigestStream.cs" />
843+
<Compile Include="src\crypto\io\MacSink.cs" />
845844
<Compile Include="src\crypto\io\MacStream.cs" />
845+
<Compile Include="src\crypto\io\SignerSink.cs" />
846846
<Compile Include="src\crypto\io\SignerStream.cs" />
847847
<Compile Include="src\crypto\macs\CMac.cs" />
848848
<Compile Include="src\crypto\macs\CbcBlockCipherMac.cs" />
@@ -880,6 +880,10 @@
880880
<Compile Include="src\crypto\modes\gcm\Tables64kGcmMultiplier.cs" />
881881
<Compile Include="src\crypto\modes\gcm\Tables8kGcmMultiplier.cs" />
882882
<Compile Include="src\crypto\operators\Asn1Signature.cs" />
883+
<Compile Include="src\crypto\operators\DefaultSignatureCalculator.cs" />
884+
<Compile Include="src\crypto\operators\DefaultSignatureResult.cs" />
885+
<Compile Include="src\crypto\operators\DefaultVerifierCalculator.cs" />
886+
<Compile Include="src\crypto\operators\DefaultVerifierResult.cs" />
883887
<Compile Include="src\crypto\paddings\BlockCipherPadding.cs" />
884888
<Compile Include="src\crypto\paddings\ISO10126d2Padding.cs" />
885889
<Compile Include="src\crypto\paddings\ISO7816d4Padding.cs" />

crypto/BouncyCastle.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,13 @@
596596
<Compile Include="src\cms\CounterSignatureDigestCalculator.cs" />
597597
<Compile Include="src\cms\DefaultAuthenticatedAttributeTableGenerator.cs" />
598598
<Compile Include="src\cms\DefaultSignedAttributeTableGenerator.cs" />
599-
<Compile Include="src\cms\DigOutputStream.cs" />
600599
<Compile Include="src\cms\IDigestCalculator.cs" />
601600
<Compile Include="src\cms\KEKRecipientInfoGenerator.cs" />
602601
<Compile Include="src\cms\KEKRecipientInformation.cs" />
603602
<Compile Include="src\cms\KeyAgreeRecipientInfoGenerator.cs" />
604603
<Compile Include="src\cms\KeyAgreeRecipientInformation.cs" />
605604
<Compile Include="src\cms\KeyTransRecipientInfoGenerator.cs" />
606605
<Compile Include="src\cms\KeyTransRecipientInformation.cs" />
607-
<Compile Include="src\cms\MacOutputStream.cs" />
608606
<Compile Include="src\cms\OriginatorId.cs" />
609607
<Compile Include="src\cms\OriginatorInfoGenerator.cs" />
610608
<Compile Include="src\cms\OriginatorInformation.cs" />
@@ -616,7 +614,6 @@
616614
<Compile Include="src\cms\RecipientInfoGenerator.cs" />
617615
<Compile Include="src\cms\RecipientInformation.cs" />
618616
<Compile Include="src\cms\RecipientInformationStore.cs" />
619-
<Compile Include="src\cms\SigOutputStream.cs" />
620617
<Compile Include="src\cms\SignerId.cs" />
621618
<Compile Include="src\cms\SignerInfoGenerator.cs" />
622619
<Compile Include="src\cms\SignerInformation.cs" />
@@ -835,8 +832,11 @@
835832
<Compile Include="src\crypto\generators\X25519KeyPairGenerator.cs" />
836833
<Compile Include="src\crypto\generators\X448KeyPairGenerator.cs" />
837834
<Compile Include="src\crypto\io\CipherStream.cs" />
835+
<Compile Include="src\crypto\io\DigestSink.cs" />
838836
<Compile Include="src\crypto\io\DigestStream.cs" />
837+
<Compile Include="src\crypto\io\MacSink.cs" />
839838
<Compile Include="src\crypto\io\MacStream.cs" />
839+
<Compile Include="src\crypto\io\SignerSink.cs" />
840840
<Compile Include="src\crypto\io\SignerStream.cs" />
841841
<Compile Include="src\crypto\macs\CMac.cs" />
842842
<Compile Include="src\crypto\macs\CbcBlockCipherMac.cs" />
@@ -874,6 +874,10 @@
874874
<Compile Include="src\crypto\modes\gcm\Tables64kGcmMultiplier.cs" />
875875
<Compile Include="src\crypto\modes\gcm\Tables8kGcmMultiplier.cs" />
876876
<Compile Include="src\crypto\operators\Asn1Signature.cs" />
877+
<Compile Include="src\crypto\operators\DefaultSignatureCalculator.cs" />
878+
<Compile Include="src\crypto\operators\DefaultSignatureResult.cs" />
879+
<Compile Include="src\crypto\operators\DefaultVerifierCalculator.cs" />
880+
<Compile Include="src\crypto\operators\DefaultVerifierResult.cs" />
877881
<Compile Include="src\crypto\paddings\BlockCipherPadding.cs" />
878882
<Compile Include="src\crypto\paddings\ISO10126d2Padding.cs" />
879883
<Compile Include="src\crypto\paddings\ISO7816d4Padding.cs" />

crypto/BouncyCastle.iOS.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,13 @@
597597
<Compile Include="src\cms\CounterSignatureDigestCalculator.cs" />
598598
<Compile Include="src\cms\DefaultAuthenticatedAttributeTableGenerator.cs" />
599599
<Compile Include="src\cms\DefaultSignedAttributeTableGenerator.cs" />
600-
<Compile Include="src\cms\DigOutputStream.cs" />
601600
<Compile Include="src\cms\IDigestCalculator.cs" />
602601
<Compile Include="src\cms\KEKRecipientInfoGenerator.cs" />
603602
<Compile Include="src\cms\KEKRecipientInformation.cs" />
604603
<Compile Include="src\cms\KeyAgreeRecipientInfoGenerator.cs" />
605604
<Compile Include="src\cms\KeyAgreeRecipientInformation.cs" />
606605
<Compile Include="src\cms\KeyTransRecipientInfoGenerator.cs" />
607606
<Compile Include="src\cms\KeyTransRecipientInformation.cs" />
608-
<Compile Include="src\cms\MacOutputStream.cs" />
609607
<Compile Include="src\cms\OriginatorId.cs" />
610608
<Compile Include="src\cms\OriginatorInfoGenerator.cs" />
611609
<Compile Include="src\cms\OriginatorInformation.cs" />
@@ -617,7 +615,6 @@
617615
<Compile Include="src\cms\RecipientInfoGenerator.cs" />
618616
<Compile Include="src\cms\RecipientInformation.cs" />
619617
<Compile Include="src\cms\RecipientInformationStore.cs" />
620-
<Compile Include="src\cms\SigOutputStream.cs" />
621618
<Compile Include="src\cms\SignerId.cs" />
622619
<Compile Include="src\cms\SignerInfoGenerator.cs" />
623620
<Compile Include="src\cms\SignerInformation.cs" />
@@ -836,8 +833,11 @@
836833
<Compile Include="src\crypto\generators\X25519KeyPairGenerator.cs" />
837834
<Compile Include="src\crypto\generators\X448KeyPairGenerator.cs" />
838835
<Compile Include="src\crypto\io\CipherStream.cs" />
836+
<Compile Include="src\crypto\io\DigestSink.cs" />
839837
<Compile Include="src\crypto\io\DigestStream.cs" />
838+
<Compile Include="src\crypto\io\MacSink.cs" />
840839
<Compile Include="src\crypto\io\MacStream.cs" />
840+
<Compile Include="src\crypto\io\SignerSink.cs" />
841841
<Compile Include="src\crypto\io\SignerStream.cs" />
842842
<Compile Include="src\crypto\macs\CMac.cs" />
843843
<Compile Include="src\crypto\macs\CbcBlockCipherMac.cs" />
@@ -875,6 +875,10 @@
875875
<Compile Include="src\crypto\modes\gcm\Tables64kGcmMultiplier.cs" />
876876
<Compile Include="src\crypto\modes\gcm\Tables8kGcmMultiplier.cs" />
877877
<Compile Include="src\crypto\operators\Asn1Signature.cs" />
878+
<Compile Include="src\crypto\operators\DefaultSignatureCalculator.cs" />
879+
<Compile Include="src\crypto\operators\DefaultSignatureResult.cs" />
880+
<Compile Include="src\crypto\operators\DefaultVerifierCalculator.cs" />
881+
<Compile Include="src\crypto\operators\DefaultVerifierResult.cs" />
878882
<Compile Include="src\crypto\paddings\BlockCipherPadding.cs" />
879883
<Compile Include="src\crypto\paddings\ISO10126d2Padding.cs" />
880884
<Compile Include="src\crypto\paddings\ISO7816d4Padding.cs" />

crypto/crypto.csproj

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,11 +2868,6 @@
28682868
SubType = "Code"
28692869
BuildAction = "Compile"
28702870
/>
2871-
<File
2872-
RelPath = "src\cms\DigOutputStream.cs"
2873-
SubType = "Code"
2874-
BuildAction = "Compile"
2875-
/>
28762871
<File
28772872
RelPath = "src\cms\IDigestCalculator.cs"
28782873
SubType = "Code"
@@ -2908,11 +2903,6 @@
29082903
SubType = "Code"
29092904
BuildAction = "Compile"
29102905
/>
2911-
<File
2912-
RelPath = "src\cms\MacOutputStream.cs"
2913-
SubType = "Code"
2914-
BuildAction = "Compile"
2915-
/>
29162906
<File
29172907
RelPath = "src\cms\OriginatorId.cs"
29182908
SubType = "Code"
@@ -2988,11 +2978,6 @@
29882978
SubType = "Code"
29892979
BuildAction = "Compile"
29902980
/>
2991-
<File
2992-
RelPath = "src\cms\SigOutputStream.cs"
2993-
SubType = "Code"
2994-
BuildAction = "Compile"
2995-
/>
29962981
<File
29972982
RelPath = "src\cms\SimpleAttributeTableGenerator.cs"
29982983
SubType = "Code"
@@ -3988,16 +3973,31 @@
39883973
SubType = "Code"
39893974
BuildAction = "Compile"
39903975
/>
3976+
<File
3977+
RelPath = "src\crypto\io\DigestSink.cs"
3978+
SubType = "Code"
3979+
BuildAction = "Compile"
3980+
/>
39913981
<File
39923982
RelPath = "src\crypto\io\DigestStream.cs"
39933983
SubType = "Code"
39943984
BuildAction = "Compile"
39953985
/>
3986+
<File
3987+
RelPath = "src\crypto\io\MacSink.cs"
3988+
SubType = "Code"
3989+
BuildAction = "Compile"
3990+
/>
39963991
<File
39973992
RelPath = "src\crypto\io\MacStream.cs"
39983993
SubType = "Code"
39993994
BuildAction = "Compile"
40003995
/>
3996+
<File
3997+
RelPath = "src\crypto\io\SignerSink.cs"
3998+
SubType = "Code"
3999+
BuildAction = "Compile"
4000+
/>
40014001
<File
40024002
RelPath = "src\crypto\io\SignerStream.cs"
40034003
SubType = "Code"
@@ -4183,6 +4183,26 @@
41834183
SubType = "Code"
41844184
BuildAction = "Compile"
41854185
/>
4186+
<File
4187+
RelPath = "src\crypto\operators\DefaultSignatureCalculator.cs"
4188+
SubType = "Code"
4189+
BuildAction = "Compile"
4190+
/>
4191+
<File
4192+
RelPath = "src\crypto\operators\DefaultSignatureResult.cs"
4193+
SubType = "Code"
4194+
BuildAction = "Compile"
4195+
/>
4196+
<File
4197+
RelPath = "src\crypto\operators\DefaultVerifierCalculator.cs"
4198+
SubType = "Code"
4199+
BuildAction = "Compile"
4200+
/>
4201+
<File
4202+
RelPath = "src\crypto\operators\DefaultVerifierResult.cs"
4203+
SubType = "Code"
4204+
BuildAction = "Compile"
4205+
/>
41864206
<File
41874207
RelPath = "src\crypto\paddings\BlockCipherPadding.cs"
41884208
SubType = "Code"

crypto/src/cms/CMSAuthenticatedDataGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private CmsAuthenticatedData Generate(
8080
mac.Init(encKey);
8181

8282
MemoryStream bOut = new MemoryStream();
83-
Stream mOut = new TeeOutputStream(bOut, new MacOutputStream(mac));
83+
Stream mOut = new TeeOutputStream(bOut, new MacSink(mac));
8484

8585
content.Write(mOut);
8686

crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected Stream Open(
168168
IMac mac = MacUtilities.GetMac(macAlgId.Algorithm);
169169
// TODO Confirm no ParametersWithRandom needed
170170
mac.Init(cipherParameters);
171-
Stream mOut = new TeeOutputStream(octetOutputStream, new MacOutputStream(mac));
171+
Stream mOut = new TeeOutputStream(octetOutputStream, new MacSink(mac));
172172

173173
return new CmsAuthenticatedDataOutputStream(mOut, mac, cGen, authGen, eiGen);
174174
}

crypto/src/cms/CMSEnvelopedHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public CmsReadable GetReadable(KeyParameter sKey)
223223
return new CmsProcessableInputStream(
224224
new TeeInputStream(
225225
readable.GetInputStream(),
226-
new MacOutputStream(this.mac)));
226+
new MacSink(this.mac)));
227227
}
228228
catch (IOException e)
229229
{

crypto/src/cms/CMSSignedDataGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Org.BouncyCastle.Asn1.Cms;
77
using Org.BouncyCastle.Asn1.X509;
88
using Org.BouncyCastle.Crypto;
9+
using Org.BouncyCastle.Crypto.IO;
910
using Org.BouncyCastle.Security;
1011
using Org.BouncyCastle.Security.Certificates;
1112
using Org.BouncyCastle.Utilities;
@@ -128,7 +129,7 @@ internal SignerInfo ToSignerInfo(
128129
IDigest dig = Helper.GetDigestInstance(digestName);
129130
if (content != null)
130131
{
131-
content.Write(new DigOutputStream(dig));
132+
content.Write(new DigestSink(dig));
132133
}
133134
hash = DigestUtilities.DoFinal(dig);
134135
outer._digests.Add(digestOID, hash.Clone());

crypto/src/cms/CMSSignedDataStreamGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ private static Stream AttachDigestsToOutputStream(ICollection digests, Stream s)
746746
Stream result = s;
747747
foreach (IDigest digest in digests)
748748
{
749-
result = GetSafeTeeOutputStream(result, new DigOutputStream(digest));
749+
result = GetSafeTeeOutputStream(result, new DigestSink(digest));
750750
}
751751
return result;
752752
}

crypto/src/cms/DigOutputStream.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)