From a71fda092163f5111197798e5f6dc6d39518add8 Mon Sep 17 00:00:00 2001 From: mw Date: Mon, 31 Aug 2020 10:30:31 +1000 Subject: renamed DigestFactory to Asn1DigestFactory --- crypto/src/crypto/operators/Asn1DigestFactory.cs | 67 ++++++++++++++++++++ crypto/src/crypto/operators/DigestFactory.cs | 79 ------------------------ crypto/src/tsp/TimeStampToken.cs | 1 - crypto/src/tsp/TimeStampTokenGenerator.cs | 9 +-- 4 files changed, 68 insertions(+), 88 deletions(-) create mode 100644 crypto/src/crypto/operators/Asn1DigestFactory.cs delete mode 100644 crypto/src/crypto/operators/DigestFactory.cs (limited to 'crypto/src') diff --git a/crypto/src/crypto/operators/Asn1DigestFactory.cs b/crypto/src/crypto/operators/Asn1DigestFactory.cs new file mode 100644 index 000000000..2455db3a0 --- /dev/null +++ b/crypto/src/crypto/operators/Asn1DigestFactory.cs @@ -0,0 +1,67 @@ +using Org.BouncyCastle.Asn1; +using Org.BouncyCastle.Asn1.X509; +using Org.BouncyCastle.Crypto.IO; +using Org.BouncyCastle.Security; +using System; +using System.IO; + + +namespace Org.BouncyCastle.Crypto.Operators +{ + public class Asn1DigestFactory : IDigestFactory + { + + public static Asn1DigestFactory Get(DerObjectIdentifier oid) + { + return new Asn1DigestFactory(DigestUtilities.GetDigest(oid), oid); + } + + public static Asn1DigestFactory Get(String mechanism) + { + DerObjectIdentifier oid = DigestUtilities.GetObjectIdentifier(mechanism); + return new Asn1DigestFactory(DigestUtilities.GetDigest(oid), oid); + } + + + private IDigest digest; + private DerObjectIdentifier oid; + + public Asn1DigestFactory(IDigest digest, DerObjectIdentifier oid) + { + this.digest = digest; + this.oid = oid; + } + + public object AlgorithmDetails => new AlgorithmIdentifier(oid); + + public int DigestLength => digest.GetDigestSize(); + + public IStreamCalculator CreateCalculator() => new DfDigestStream(digest); + + } + + + internal class DfDigestStream : IStreamCalculator + { + + private DigestSink stream; + + public DfDigestStream(IDigest digest) + { + stream = new DigestSink(digest); + } + + public Stream Stream => stream; + + public object GetResult() + { + byte[] result = new byte[stream.Digest.GetDigestSize()]; + stream.Digest.DoFinal(result, 0); + return new SimpleBlockResult(result); + } + + } + + + +} diff --git a/crypto/src/crypto/operators/DigestFactory.cs b/crypto/src/crypto/operators/DigestFactory.cs deleted file mode 100644 index 7624fdf43..000000000 --- a/crypto/src/crypto/operators/DigestFactory.cs +++ /dev/null @@ -1,79 +0,0 @@ -using Org.BouncyCastle.Asn1; -using Org.BouncyCastle.Asn1.Nist; -using Org.BouncyCastle.Asn1.Oiw; -using Org.BouncyCastle.Asn1.Pkcs; -using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Crypto.Digests; -using Org.BouncyCastle.Crypto.IO; -using Org.BouncyCastle.Crypto.Paddings; -using Org.BouncyCastle.Crypto.Tests; -using Org.BouncyCastle.Security; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Text; - -namespace Org.BouncyCastle.Crypto.Operators -{ - - - - public class DigestFactory : IDigestFactory - { - - public static DigestFactory Get(DerObjectIdentifier oid) - { - return new DigestFactory(DigestUtilities.GetDigest(oid), oid); - } - - public static DigestFactory Get(String mechanism) - { - DerObjectIdentifier oid = DigestUtilities.GetObjectIdentifier(mechanism); - return new DigestFactory(DigestUtilities.GetDigest(oid), oid); - } - - - private IDigest digest; - private DerObjectIdentifier oid; - - public DigestFactory(IDigest digest, DerObjectIdentifier oid) - { - this.digest = digest; - this.oid = oid; - } - - public object AlgorithmDetails => new AlgorithmIdentifier(oid); - - public int DigestLength => digest.GetDigestSize(); - - public IStreamCalculator CreateCalculator() => new DfDigestStream(digest); - - } - - - internal class DfDigestStream : IStreamCalculator - { - - private DigestSink stream; - - public DfDigestStream(IDigest digest) - { - stream = new DigestSink(digest); - } - - public Stream Stream => stream; - - public object GetResult() - { - byte[] result = new byte[stream.Digest.GetDigestSize()]; - stream.Digest.DoFinal(result, 0); - return new SimpleBlockResult(result); - } - - } - - - -} diff --git a/crypto/src/tsp/TimeStampToken.cs b/crypto/src/tsp/TimeStampToken.cs index 32f2523ce..0615cbd76 100644 --- a/crypto/src/tsp/TimeStampToken.cs +++ b/crypto/src/tsp/TimeStampToken.cs @@ -10,7 +10,6 @@ using Org.BouncyCastle.Asn1.Pkcs; using Org.BouncyCastle.Asn1.Tsp; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Cms; -using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Security; using Org.BouncyCastle.Security.Certificates; using Org.BouncyCastle.Utilities; diff --git a/crypto/src/tsp/TimeStampTokenGenerator.cs b/crypto/src/tsp/TimeStampTokenGenerator.cs index 3441a18a2..76228761a 100644 --- a/crypto/src/tsp/TimeStampTokenGenerator.cs +++ b/crypto/src/tsp/TimeStampTokenGenerator.cs @@ -1,23 +1,16 @@ using System; using System.Collections; using System.IO; -using System.Runtime.InteropServices.ComTypes; using Org.BouncyCastle.Asn1; -using Org.BouncyCastle.Asn1.Cms; using Org.BouncyCastle.Asn1.Ess; -using Org.BouncyCastle.Asn1.Nist; using Org.BouncyCastle.Asn1.Oiw; using Org.BouncyCastle.Asn1.Pkcs; using Org.BouncyCastle.Asn1.Tsp; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Cms; using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Crypto.IO; using Org.BouncyCastle.Crypto.Operators; -using Org.BouncyCastle.Crypto.Paddings; using Org.BouncyCastle.Math; -using Org.BouncyCastle.Security; -using Org.BouncyCastle.Security.Certificates; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.X509; using Org.BouncyCastle.X509.Store; @@ -129,7 +122,7 @@ namespace Org.BouncyCastle.Tsp Asn1.Cms.AttributeTable signedAttr, Asn1.Cms.AttributeTable unsignedAttr) : this( makeInfoGenerator(key, cert, digestOID, signedAttr, unsignedAttr), - DigestFactory.Get(OiwObjectIdentifiers.IdSha1), + Asn1DigestFactory.Get(OiwObjectIdentifiers.IdSha1), tsaPolicyOID != null?new DerObjectIdentifier(tsaPolicyOID):null, false) { -- cgit 1.5.1