summary refs log tree commit diff
path: root/crypto/src/pkcs
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2015-10-16 09:30:29 +1100
committerDavid Hook <dgh@bouncycastle.org>2015-10-16 09:30:29 +1100
commitb18da3a6bc82e3b0119edb7184db15ba3bc12c8a (patch)
treea0e0850341d707010999a6b5317a37eb9ac40242 /crypto/src/pkcs
parentClose files after reading (diff)
downloadBouncyCastle.NET-ed25519-b18da3a6bc82e3b0119edb7184db15ba3bc12c8a.tar.xz
Further work of signature/verification calculators.
Added IBlockResult and IVerifier
Added verifier provider verify methods to X.509 PKCS#10 classes.
Diffstat (limited to 'crypto/src/pkcs')
-rw-r--r--crypto/src/pkcs/Pkcs10CertificationRequest.cs84
1 files changed, 39 insertions, 45 deletions
diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
index 878cb61d3..b68979cad 100644
--- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs
+++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
@@ -273,14 +273,16 @@ namespace Org.BouncyCastle.Pkcs
 
             this.reqInfo = new CertificationRequestInfo(subject, pubInfo, attributes);
 
-            Stream sigStream = signatureCalculator.GetSignatureUpdater();
+            IStreamCalculator streamCalculator = signatureCalculator.CreateCalculator();
 
             byte[] reqInfoData = reqInfo.GetDerEncoded();
 
-            sigStream.Write(reqInfoData, 0, reqInfoData.Length);
+            streamCalculator.Stream.Write(reqInfoData, 0, reqInfoData.Length);
+
+            streamCalculator.Stream.Close();
 
             // Generate Signature.
-            sigBits = new DerBitString(signatureCalculator.Signature());
+            sigBits = new DerBitString(((IBlockResult)streamCalculator.GetResult()).DoFinal());
         }
 
         //        internal Pkcs10CertificationRequest(
@@ -320,55 +322,47 @@ namespace Org.BouncyCastle.Pkcs
 		public bool Verify(
 			AsymmetricKeyParameter publicKey)
 		{
-			ISigner sig;
+            return Verify(new Asn1SignatureVerifierProvider(publicKey));
+		}
 
-			try
-			{
-				sig = SignerUtilities.GetSigner(GetSignatureName(sigAlgId));
-			}
-			catch (Exception e)
-			{
-				// try an alternate
-				string alt = (string) oids[sigAlgId.ObjectID];
+        public bool Verify(
+            ISignatureVerifierProvider verifierProvider)
+        {
+            return Verify(verifierProvider.CreateSignatureVerifier(sigAlgId));
+        }
 
-				if (alt != null)
-				{
-					sig = SignerUtilities.GetSigner(alt);
-				}
-				else
-				{
-					throw e;
-				}
-			}
+        public bool Verify(
+            ISignatureVerifier verifier)
+        {
+            try
+            {
+                byte[] b = reqInfo.GetDerEncoded();
 
-			SetSignatureParameters(sig, sigAlgId.Parameters);
+                IStreamCalculator streamCalculator = verifier.CreateCalculator();
 
-			sig.Init(false, publicKey);
+                streamCalculator.Stream.Write(b, 0, b.Length);
 
-			try
-			{
-				byte[] b = reqInfo.GetDerEncoded();
-				sig.BlockUpdate(b, 0, b.Length);
-			}
-			catch (Exception e)
-			{
-				throw new SignatureException("exception encoding TBS cert request", e);
-			}
+                streamCalculator.Stream.Close();
 
-			return sig.VerifySignature(sigBits.GetBytes());
-		}
+                return ((IVerifier)streamCalculator.GetResult()).IsVerified(sigBits.GetBytes());
+            }
+            catch (Exception e)
+            {
+                throw new SignatureException("exception encoding TBS cert request", e);
+            }
+        }
+
+        //        /// <summary>
+        //        /// Get the Der Encoded Pkcs10 Certification Request.
+        //        /// </summary>
+        //        /// <returns>A byte array.</returns>
+        //        public byte[] GetEncoded()
+        //        {
+        //        	return new CertificationRequest(reqInfo, sigAlgId, sigBits).GetDerEncoded();
+        //        }
 
-//        /// <summary>
-//        /// Get the Der Encoded Pkcs10 Certification Request.
-//        /// </summary>
-//        /// <returns>A byte array.</returns>
-//        public byte[] GetEncoded()
-//        {
-//        	return new CertificationRequest(reqInfo, sigAlgId, sigBits).GetDerEncoded();
-//        }
-
-		// TODO Figure out how to set parameters on an ISigner
-		private void SetSignatureParameters(
+        // TODO Figure out how to set parameters on an ISigner
+        private void SetSignatureParameters(
 			ISigner			signature,
 			Asn1Encodable	asn1Params)
 		{