From 0b0a6567a14b9d74780dc5ee1f26de46278e416a Mon Sep 17 00:00:00 2001 From: David Hook Date: Sat, 24 Oct 2015 10:42:38 +1100 Subject: renamed ISignatureCalculator to ISignatureCalculatorFactory --- crypto/src/cms/CMSSignedDataGenerator.cs | 6 +++--- crypto/src/cms/SignerInfoGenerator.cs | 14 ++++++------- crypto/src/crypto/ISignatureCalculator.cs | 23 ---------------------- crypto/src/crypto/ISignatureCalculatorFactory.cs | 23 ++++++++++++++++++++++ crypto/src/crypto/operators/Asn1Signature.cs | 6 +++--- crypto/src/ocsp/BasicOCSPRespGenerator.cs | 6 +++--- crypto/src/pkcs/Pkcs10CertificationRequest.cs | 8 ++++---- crypto/src/x509/X509V1CertificateGenerator.cs | 10 +++++----- .../x509/X509V2AttributeCertificateGenerator.cs | 10 +++++----- crypto/src/x509/X509V2CRLGenerator.cs | 10 +++++----- crypto/src/x509/X509V3CertificateGenerator.cs | 10 +++++----- crypto/test/src/cms/test/SignedDataTest.cs | 4 ++-- 12 files changed, 65 insertions(+), 65 deletions(-) delete mode 100644 crypto/src/crypto/ISignatureCalculator.cs create mode 100644 crypto/src/crypto/ISignatureCalculatorFactory.cs (limited to 'crypto') diff --git a/crypto/src/cms/CMSSignedDataGenerator.cs b/crypto/src/cms/CMSSignedDataGenerator.cs index f4720597d..60d723d60 100644 --- a/crypto/src/cms/CMSSignedDataGenerator.cs +++ b/crypto/src/cms/CMSSignedDataGenerator.cs @@ -43,7 +43,7 @@ namespace Org.BouncyCastle.Cms { private readonly CmsSignedGenerator outer; - private readonly ISignatureCalculator sigCalc; + private readonly ISignatureCalculatorFactory sigCalc; private readonly SignerIdentifier signerIdentifier; private readonly string digestOID; private readonly string encOID; @@ -66,7 +66,7 @@ namespace Org.BouncyCastle.Cms string signatureName = digestName + "with" + Helper.GetEncryptionAlgName(encOID); this.outer = outer; - this.sigCalc = new Asn1SignatureCalculator(signatureName, key); + this.sigCalc = new Asn1SignatureCalculatorFactory(signatureName, key); this.signerIdentifier = signerIdentifier; this.digestOID = digestOID; this.encOID = encOID; @@ -77,7 +77,7 @@ namespace Org.BouncyCastle.Cms internal SignerInf( CmsSignedGenerator outer, - ISignatureCalculator sigCalc, + ISignatureCalculatorFactory sigCalc, SignerIdentifier signerIdentifier, CmsAttributeTableGenerator sAttr, CmsAttributeTableGenerator unsAttr, diff --git a/crypto/src/cms/SignerInfoGenerator.cs b/crypto/src/cms/SignerInfoGenerator.cs index 62db40ad8..69196bdd1 100644 --- a/crypto/src/cms/SignerInfoGenerator.cs +++ b/crypto/src/cms/SignerInfoGenerator.cs @@ -17,18 +17,18 @@ namespace Org.BouncyCastle.Cms public class SignerInfoGenerator { internal X509Certificate certificate; - internal ISignatureCalculator contentSigner; + internal ISignatureCalculatorFactory contentSigner; internal SignerIdentifier sigId; internal CmsAttributeTableGenerator signedGen; internal CmsAttributeTableGenerator unsignedGen; private bool isDirectSignature; - internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureCalculator contentSigner): this(sigId, contentSigner, false) + internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureCalculatorFactory contentSigner): this(sigId, contentSigner, false) { } - internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureCalculator contentSigner, bool isDirectSignature) + internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureCalculatorFactory contentSigner, bool isDirectSignature) { this.sigId = sigId; this.contentSigner = contentSigner; @@ -45,7 +45,7 @@ namespace Org.BouncyCastle.Cms } } - internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureCalculator contentSigner, CmsAttributeTableGenerator signedGen, CmsAttributeTableGenerator unsignedGen) + internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureCalculatorFactory contentSigner, CmsAttributeTableGenerator signedGen, CmsAttributeTableGenerator unsignedGen) { this.sigId = sigId; this.contentSigner = contentSigner; @@ -117,7 +117,7 @@ namespace Org.BouncyCastle.Cms * @return a SignerInfoGenerator * @throws OperatorCreationException if the generator cannot be built. */ - public SignerInfoGenerator Build(ISignatureCalculator contentSigner, X509Certificate certificate) + public SignerInfoGenerator Build(ISignatureCalculatorFactory contentSigner, X509Certificate certificate) { SignerIdentifier sigId = new SignerIdentifier(new IssuerAndSerialNumber(certificate.IssuerDN, new DerInteger(certificate.SerialNumber))); @@ -137,14 +137,14 @@ namespace Org.BouncyCastle.Cms * @return a SignerInfoGenerator * @throws OperatorCreationException if the generator cannot be built. */ - public SignerInfoGenerator Build(ISignatureCalculator contentSigner, byte[] subjectKeyIdentifier) + public SignerInfoGenerator Build(ISignatureCalculatorFactory contentSigner, byte[] subjectKeyIdentifier) { SignerIdentifier sigId = new SignerIdentifier(new DerOctetString(subjectKeyIdentifier)); return CreateGenerator(contentSigner, sigId); } - private SignerInfoGenerator CreateGenerator(ISignatureCalculator contentSigner, SignerIdentifier sigId) + private SignerInfoGenerator CreateGenerator(ISignatureCalculatorFactory contentSigner, SignerIdentifier sigId) { if (directSignature) { diff --git a/crypto/src/crypto/ISignatureCalculator.cs b/crypto/src/crypto/ISignatureCalculator.cs deleted file mode 100644 index bb733818d..000000000 --- a/crypto/src/crypto/ISignatureCalculator.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace Org.BouncyCastle.Crypto -{ - /// - /// Base interface for operators that serve as stream-based signature calculators. - /// - public interface ISignatureCalculator - { - /// The algorithm details object for this calculator. - Object AlgorithmDetails { get ; } - - /// - /// Create a stream calculator for this signature calculator. The stream - /// calculator is used for the actual operation of entering the data to be signed - /// and producing the signature block. - /// - /// A calculator producing an IBlockResult with a signature in it. - IStreamCalculator CreateCalculator(); - } -} - - diff --git a/crypto/src/crypto/ISignatureCalculatorFactory.cs b/crypto/src/crypto/ISignatureCalculatorFactory.cs new file mode 100644 index 000000000..b60adb168 --- /dev/null +++ b/crypto/src/crypto/ISignatureCalculatorFactory.cs @@ -0,0 +1,23 @@ +using System; + +namespace Org.BouncyCastle.Crypto +{ + /// + /// Base interface for operators that serve as stream-based signature calculators. + /// + public interface ISignatureCalculatorFactory + { + /// The algorithm details object for this calculator. + Object AlgorithmDetails { get ; } + + /// + /// Create a stream calculator for this signature calculator. The stream + /// calculator is used for the actual operation of entering the data to be signed + /// and producing the signature block. + /// + /// A calculator producing an IBlockResult with a signature in it. + IStreamCalculator CreateCalculator(); + } +} + + diff --git a/crypto/src/crypto/operators/Asn1Signature.cs b/crypto/src/crypto/operators/Asn1Signature.cs index 9e66b6f0c..92a33e596 100644 --- a/crypto/src/crypto/operators/Asn1Signature.cs +++ b/crypto/src/crypto/operators/Asn1Signature.cs @@ -329,7 +329,7 @@ namespace Org.BouncyCastle.Crypto.Operators /// Calculator class for signature generation in ASN.1 based profiles that use an AlgorithmIdentifier to preserve /// signature algorithm details. /// - public class Asn1SignatureCalculator: ISignatureCalculator + public class Asn1SignatureCalculatorFactory: ISignatureCalculatorFactory { private readonly AlgorithmIdentifier algID; private readonly string algorithm; @@ -341,7 +341,7 @@ namespace Org.BouncyCastle.Crypto.Operators /// /// The name of the signature algorithm to use. /// The private key to be used in the signing operation. - public Asn1SignatureCalculator (string algorithm, AsymmetricKeyParameter privateKey): this(algorithm, privateKey, null) + public Asn1SignatureCalculatorFactory (string algorithm, AsymmetricKeyParameter privateKey): this(algorithm, privateKey, null) { } @@ -351,7 +351,7 @@ namespace Org.BouncyCastle.Crypto.Operators /// The name of the signature algorithm to use. /// The private key to be used in the signing operation. /// The source of randomness to be used in signature calculation. - public Asn1SignatureCalculator (string algorithm, AsymmetricKeyParameter privateKey, SecureRandom random) + public Asn1SignatureCalculatorFactory (string algorithm, AsymmetricKeyParameter privateKey, SecureRandom random) { DerObjectIdentifier sigOid = X509Utilities.GetAlgorithmOid (algorithm); diff --git a/crypto/src/ocsp/BasicOCSPRespGenerator.cs b/crypto/src/ocsp/BasicOCSPRespGenerator.cs index 9735ba177..14307c3ee 100644 --- a/crypto/src/ocsp/BasicOCSPRespGenerator.cs +++ b/crypto/src/ocsp/BasicOCSPRespGenerator.cs @@ -185,7 +185,7 @@ namespace Org.BouncyCastle.Ocsp } private BasicOcspResp GenerateResponse( - ISignatureCalculator signatureCalculator, + ISignatureCalculatorFactory signatureCalculator, X509Certificate[] chain, DateTime producedAt) { @@ -277,7 +277,7 @@ namespace Org.BouncyCastle.Ocsp throw new ArgumentException("no signing algorithm specified"); } - return GenerateResponse(new Asn1SignatureCalculator(signingAlgorithm, privateKey, random), chain, producedAt); + return GenerateResponse(new Asn1SignatureCalculatorFactory(signingAlgorithm, privateKey, random), chain, producedAt); } /// @@ -288,7 +288,7 @@ namespace Org.BouncyCastle.Ocsp /// "produced at" date. /// public BasicOcspResp Generate( - ISignatureCalculator signatureCalculator, + ISignatureCalculatorFactory signatureCalculator, X509Certificate[] chain, DateTime producedAt) { diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs index 6c6b4c87d..1638dcb23 100644 --- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs +++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs @@ -209,7 +209,7 @@ namespace Org.BouncyCastle.Pkcs /// Public Key to be included in cert reqest. /// ASN1Set of Attributes. /// Matching Private key for nominated (above) public key to be used to sign the request. - [Obsolete("Use constructor with an ISignatureCalculator")] + [Obsolete("Use constructor with an ISignatureCalculatorFactory")] public Pkcs10CertificationRequest( string signatureAlgorithm, X509Name subject, @@ -228,7 +228,7 @@ namespace Org.BouncyCastle.Pkcs if (!signingKey.IsPrivate) throw new ArgumentException("key for signing must be private", "signingKey"); - init(new Asn1SignatureCalculator(signatureAlgorithm, signingKey), subject, publicKey, attributes, signingKey); + init(new Asn1SignatureCalculatorFactory(signatureAlgorithm, signingKey), subject, publicKey, attributes, signingKey); } /// @@ -240,7 +240,7 @@ namespace Org.BouncyCastle.Pkcs /// ASN1Set of Attributes. /// Matching Private key for nominated (above) public key to be used to sign the request. public Pkcs10CertificationRequest( - ISignatureCalculator signatureCalculator, + ISignatureCalculatorFactory signatureCalculator, X509Name subject, AsymmetricKeyParameter publicKey, Asn1Set attributes, @@ -261,7 +261,7 @@ namespace Org.BouncyCastle.Pkcs } private void init( - ISignatureCalculator signatureCalculator, + ISignatureCalculatorFactory signatureCalculator, X509Name subject, AsymmetricKeyParameter publicKey, Asn1Set attributes, diff --git a/crypto/src/x509/X509V1CertificateGenerator.cs b/crypto/src/x509/X509V1CertificateGenerator.cs index 2279767e3..92829eac3 100644 --- a/crypto/src/x509/X509V1CertificateGenerator.cs +++ b/crypto/src/x509/X509V1CertificateGenerator.cs @@ -121,7 +121,7 @@ namespace Org.BouncyCastle.X509 /// This can be either a name or an OID, names are treated as case insensitive. /// /// string representation of the algorithm name - [Obsolete("Not needed if Generate used with an ISignatureCalculator")] + [Obsolete("Not needed if Generate used with an ISignatureCalculatorFactory")] public void SetSignatureAlgorithm( string signatureAlgorithm) { @@ -146,7 +146,7 @@ namespace Org.BouncyCastle.X509 /// /// The private key of the issuer used to sign this certificate. /// An X509Certificate. - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public X509Certificate Generate( AsymmetricKeyParameter privateKey) { @@ -159,12 +159,12 @@ namespace Org.BouncyCastle.X509 /// The private key of the issuer used to sign this certificate. /// The Secure Random you want to use. /// An X509Certificate. - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public X509Certificate Generate( AsymmetricKeyParameter privateKey, SecureRandom random) { - return Generate(new Asn1SignatureCalculator(signatureAlgorithm, privateKey, random)); + return Generate(new Asn1SignatureCalculatorFactory(signatureAlgorithm, privateKey, random)); } /// @@ -172,7 +172,7 @@ namespace Org.BouncyCastle.X509 /// /// A signature calculator with the necessary algorithm details. /// An X509Certificate. - public X509Certificate Generate(ISignatureCalculator signatureCalculator) + public X509Certificate Generate(ISignatureCalculatorFactory signatureCalculator) { tbsGen.SetSignature ((AlgorithmIdentifier)signatureCalculator.AlgorithmDetails); diff --git a/crypto/src/x509/X509V2AttributeCertificateGenerator.cs b/crypto/src/x509/X509V2AttributeCertificateGenerator.cs index b6ab45c64..28db75d0f 100644 --- a/crypto/src/x509/X509V2AttributeCertificateGenerator.cs +++ b/crypto/src/x509/X509V2AttributeCertificateGenerator.cs @@ -73,7 +73,7 @@ namespace Org.BouncyCastle.X509 /// are treated as case insensitive. /// /// The algorithm name. - [Obsolete("Not needed if Generate used with an ISignatureCalculator")] + [Obsolete("Not needed if Generate used with an ISignatureCalculatorFactory")] public void SetSignatureAlgorithm( string signatureAlgorithm) { @@ -133,7 +133,7 @@ namespace Org.BouncyCastle.X509 /// /// Generate an X509 certificate, based on the current issuer and subject. /// - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public IX509AttributeCertificate Generate( AsymmetricKeyParameter privateKey) { @@ -144,12 +144,12 @@ namespace Org.BouncyCastle.X509 /// Generate an X509 certificate, based on the current issuer and subject, /// using the supplied source of randomness, if required. /// - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public IX509AttributeCertificate Generate( AsymmetricKeyParameter privateKey, SecureRandom random) { - return Generate(new Asn1SignatureCalculator(signatureAlgorithm, privateKey, random)); + return Generate(new Asn1SignatureCalculatorFactory(signatureAlgorithm, privateKey, random)); } /// @@ -157,7 +157,7 @@ namespace Org.BouncyCastle.X509 /// /// A signature calculator with the necessary algorithm details. /// An IX509AttributeCertificate. - public IX509AttributeCertificate Generate(ISignatureCalculator signatureCalculator) + public IX509AttributeCertificate Generate(ISignatureCalculatorFactory signatureCalculator) { if (!extGenerator.IsEmpty) { diff --git a/crypto/src/x509/X509V2CRLGenerator.cs b/crypto/src/x509/X509V2CRLGenerator.cs index 869722219..4504d39a6 100644 --- a/crypto/src/x509/X509V2CRLGenerator.cs +++ b/crypto/src/x509/X509V2CRLGenerator.cs @@ -134,7 +134,7 @@ namespace Org.BouncyCastle.X509 /// Set the signature algorithm that will be used to sign this CRL. /// /// - [Obsolete("Not needed if Generate used with an ISignatureCalculator")] + [Obsolete("Not needed if Generate used with an ISignatureCalculatorFactory")] public void SetSignatureAlgorithm( string signatureAlgorithm) { @@ -203,7 +203,7 @@ namespace Org.BouncyCastle.X509 /// /// The private key of the issuer that is signing this certificate. /// An X509Crl. - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public X509Crl Generate( AsymmetricKeyParameter privateKey) { @@ -216,12 +216,12 @@ namespace Org.BouncyCastle.X509 /// The private key of the issuer that is signing this certificate. /// Your Secure Random instance. /// An X509Crl. - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public X509Crl Generate( AsymmetricKeyParameter privateKey, SecureRandom random) { - return Generate(new Asn1SignatureCalculator(signatureAlgorithm, privateKey, random)); + return Generate(new Asn1SignatureCalculatorFactory(signatureAlgorithm, privateKey, random)); } /// @@ -229,7 +229,7 @@ namespace Org.BouncyCastle.X509 /// /// A signature calculator with the necessary algorithm details. /// An X509Crl. - public X509Crl Generate(ISignatureCalculator signatureCalculator) + public X509Crl Generate(ISignatureCalculatorFactory signatureCalculator) { tbsGen.SetSignature((AlgorithmIdentifier)signatureCalculator.AlgorithmDetails); diff --git a/crypto/src/x509/X509V3CertificateGenerator.cs b/crypto/src/x509/X509V3CertificateGenerator.cs index d8cdc7521..b046838e8 100644 --- a/crypto/src/x509/X509V3CertificateGenerator.cs +++ b/crypto/src/x509/X509V3CertificateGenerator.cs @@ -112,7 +112,7 @@ namespace Org.BouncyCastle.X509 /// Set the signature algorithm that will be used to sign this certificate. /// /// - [Obsolete("Not needed if Generate used with an ISignatureCalculator")] + [Obsolete("Not needed if Generate used with an ISignatureCalculatorFactory")] public void SetSignatureAlgorithm( string signatureAlgorithm) { @@ -277,7 +277,7 @@ namespace Org.BouncyCastle.X509 /// /// The private key of the issuer that is signing this certificate. /// An X509Certificate. - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public X509Certificate Generate( AsymmetricKeyParameter privateKey) { @@ -290,12 +290,12 @@ namespace Org.BouncyCastle.X509 /// The private key of the issuer that is signing this certificate. /// You Secure Random instance. /// An X509Certificate. - [Obsolete("Use Generate with an ISignatureCalculator")] + [Obsolete("Use Generate with an ISignatureCalculatorFactory")] public X509Certificate Generate( AsymmetricKeyParameter privateKey, SecureRandom random) { - return Generate(new Asn1SignatureCalculator(signatureAlgorithm, privateKey, random)); + return Generate(new Asn1SignatureCalculatorFactory(signatureAlgorithm, privateKey, random)); } /// @@ -303,7 +303,7 @@ namespace Org.BouncyCastle.X509 /// /// A signature calculator with the necessary algorithm details. /// An X509Certificate. - public X509Certificate Generate(ISignatureCalculator signatureCalculator) + public X509Certificate Generate(ISignatureCalculatorFactory signatureCalculator) { tbsGen.SetSignature ((AlgorithmIdentifier)signatureCalculator.AlgorithmDetails); diff --git a/crypto/test/src/cms/test/SignedDataTest.cs b/crypto/test/src/cms/test/SignedDataTest.cs index 2b5d147f6..2c6f217da 100644 --- a/crypto/test/src/cms/test/SignedDataTest.cs +++ b/crypto/test/src/cms/test/SignedDataTest.cs @@ -532,9 +532,9 @@ namespace Org.BouncyCastle.Cms.Tests CmsSignedDataGenerator gen = new CmsSignedDataGenerator(); gen.AddSignerInfoGenerator(new SignerInfoGeneratorBuilder().Build( - new Asn1SignatureCalculator("SHA1withRSA", OrigKP.Private), OrigCert)); + new Asn1SignatureCalculatorFactory("SHA1withRSA", OrigKP.Private), OrigCert)); gen.AddSignerInfoGenerator(new SignerInfoGeneratorBuilder().Build( - new Asn1SignatureCalculator("MD5withRSA", OrigKP.Private), OrigCert)); + new Asn1SignatureCalculatorFactory("MD5withRSA", OrigKP.Private), OrigCert)); gen.AddCertificates(x509Certs); -- cgit 1.5.1