summary refs log tree commit diff
path: root/crypto/src/pkcs/Pkcs10CertificationRequest.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2018-08-07 20:17:18 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2018-08-07 20:17:18 +0700
commit17484948ae42b7d5fd75a4e96b31a8bb0cb47825 (patch)
tree83f64608d50c999f21b608cc0662fadacd551fd3 /crypto/src/pkcs/Pkcs10CertificationRequest.cs
parentAdd entry explaining DH changes (diff)
downloadBouncyCastle.NET-ed25519-17484948ae42b7d5fd75a4e96b31a8bb0cb47825.tar.xz
Refactoring around Pkcs10CertificationRequest
- see https://github.com/bcgit/bc-csharp/pull/123
Diffstat (limited to '')
-rw-r--r--crypto/src/pkcs/Pkcs10CertificationRequest.cs56
1 files changed, 29 insertions, 27 deletions
diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
index 24dc9b1cc..34bda3815 100644
--- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs
+++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
@@ -210,71 +210,73 @@ namespace Org.BouncyCastle.Pkcs
         /// <param name="publicKey">Public Key to be included in cert reqest.</param>
         /// <param name="attributes">ASN1Set of Attributes.</param>
         /// <param name="signingKey">Matching Private key for nominated (above) public key to be used to sign the request.</param>
-        [Obsolete("Use constructor with an ISignatureFactory")]
         public Pkcs10CertificationRequest(
 			string					signatureAlgorithm,
 			X509Name				subject,
 			AsymmetricKeyParameter	publicKey,
 			Asn1Set					attributes,
 			AsymmetricKeyParameter	signingKey)
+            : this(new Asn1SignatureFactory(signatureAlgorithm, signingKey), subject, publicKey, attributes)
 		{
-			if (signatureAlgorithm == null)
-				throw new ArgumentNullException("signatureAlgorithm");
-			if (subject == null)
-				throw new ArgumentNullException("subject");
-			if (publicKey == null)
-				throw new ArgumentNullException("publicKey");
-			if (publicKey.IsPrivate)
-				throw new ArgumentException("expected public key", "publicKey");
-			if (!signingKey.IsPrivate)
-				throw new ArgumentException("key for signing must be private", "signingKey");
-
-            init(new Asn1SignatureFactory(signatureAlgorithm, signingKey), subject, publicKey, attributes, signingKey);
 		}
 
         /// <summary>
         /// Instantiate a Pkcs10CertificationRequest object with the necessary credentials.
         /// </summary>
-        ///<param name="signatureCalculatorFactory">The factory for signature calculators to sign the PKCS#10 request with.</param>
+        ///<param name="signatureFactory">The factory for signature calculators to sign the PKCS#10 request with.</param>
         /// <param name="subject">X509Name of subject eg OU="My unit." O="My Organisatioin" C="au" </param>
         /// <param name="publicKey">Public Key to be included in cert reqest.</param>
         /// <param name="attributes">ASN1Set of Attributes.</param>
-        /// <param name="signingKey">Matching Private key for nominated (above) public key to be used to sign the request.</param>
+        /// <param name="signingKey">Ignored.</param>
+        [Obsolete("Use constructor without 'signingKey' parameter (ignored here)")]
         public Pkcs10CertificationRequest(
-            ISignatureFactory signatureCalculatorFactory,
+            ISignatureFactory signatureFactory,
             X509Name subject,
             AsymmetricKeyParameter publicKey,
             Asn1Set attributes,
             AsymmetricKeyParameter signingKey)
+            : this(signatureFactory, subject, publicKey, attributes)
         {
-            if (signatureCalculatorFactory == null)
-                throw new ArgumentNullException("signatureCalculator");
+        }
+
+        /// <summary>
+        /// Instantiate a Pkcs10CertificationRequest object with the necessary credentials.
+        /// </summary>
+        ///<param name="signatureFactory">The factory for signature calculators to sign the PKCS#10 request with.</param>
+        /// <param name="subject">X509Name of subject eg OU="My unit." O="My Organisatioin" C="au" </param>
+        /// <param name="publicKey">Public Key to be included in cert reqest.</param>
+        /// <param name="attributes">ASN1Set of Attributes.</param>
+        public Pkcs10CertificationRequest(
+            ISignatureFactory signatureFactory,
+            X509Name subject,
+            AsymmetricKeyParameter publicKey,
+            Asn1Set attributes)
+        {
+            if (signatureFactory == null)
+                throw new ArgumentNullException("signatureFactory");
             if (subject == null)
                 throw new ArgumentNullException("subject");
             if (publicKey == null)
                 throw new ArgumentNullException("publicKey");
             if (publicKey.IsPrivate)
                 throw new ArgumentException("expected public key", "publicKey");
-            if (!signingKey.IsPrivate)
-                throw new ArgumentException("key for signing must be private", "signingKey");
 
-            init(signatureCalculatorFactory, subject, publicKey, attributes, signingKey);
+            Init(signatureFactory, subject, publicKey, attributes);
         }
 
-        private void init(
-            ISignatureFactory signatureCalculator, 
+        private void Init(
+            ISignatureFactory signatureFactory, 
             X509Name subject,
             AsymmetricKeyParameter publicKey,
-            Asn1Set attributes,
-            AsymmetricKeyParameter signingKey)
+            Asn1Set attributes)
         {
-            this.sigAlgId = (AlgorithmIdentifier)signatureCalculator.AlgorithmDetails;
+            this.sigAlgId = (AlgorithmIdentifier)signatureFactory.AlgorithmDetails;
 
             SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
 
             this.reqInfo = new CertificationRequestInfo(subject, pubInfo, attributes);
 
-            IStreamCalculator streamCalculator = signatureCalculator.CreateCalculator();
+            IStreamCalculator streamCalculator = signatureFactory.CreateCalculator();
 
             byte[] reqInfoData = reqInfo.GetDerEncoded();