summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-01-05 13:30:09 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-01-05 13:30:09 +0700
commita216f62bd14a9962eccb5ce7daf7820ccadadc23 (patch)
tree15aa2bd6aec9a20caf54eb0f1a5c691f9725f33e
parentRefactor SendSignatureInput and callers (diff)
downloadBouncyCastle.NET-ed25519-a216f62bd14a9962eccb5ce7daf7820ccadadc23.tar.xz
Avoid intermediate allocations
-rw-r--r--crypto/src/x509/X509Certificate.cs6
-rw-r--r--crypto/src/x509/X509Crl.cs4
-rw-r--r--crypto/src/x509/X509V1CertificateGenerator.cs2
-rw-r--r--crypto/src/x509/X509V2AttributeCertificate.cs6
-rw-r--r--crypto/src/x509/X509V2AttributeCertificateGenerator.cs2
-rw-r--r--crypto/src/x509/X509V2CRLGenerator.cs2
-rw-r--r--crypto/src/x509/X509V3CertificateGenerator.cs2
7 files changed, 9 insertions, 15 deletions
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index 5b800efe5..b6749d505 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -680,15 +680,13 @@ namespace Org.BouncyCastle.X509
             if (!IsAlgIDEqual(c.SignatureAlgorithm, c.TbsCertificate.Signature))
                 throw new CertificateException("signature algorithm in TBS cert not same as outer cert");
 
-            byte[] b = GetTbsCertificate();
-
             IStreamCalculator<IVerifier> streamCalculator = verifier.CreateCalculator();
             using (var stream = streamCalculator.Stream)
             {
-                stream.Write(b, 0, b.Length);
+                c.TbsCertificate.EncodeTo(stream, Asn1Encodable.Der);
             }
 
-            if (!streamCalculator.GetResult().IsVerified(this.GetSignature()))
+            if (!streamCalculator.GetResult().IsVerified(GetSignature()))
                 throw new InvalidKeyException("Public key presented not for certificate signature");
         }
 
diff --git a/crypto/src/x509/X509Crl.cs b/crypto/src/x509/X509Crl.cs
index db13f4f2f..027813562 100644
--- a/crypto/src/x509/X509Crl.cs
+++ b/crypto/src/x509/X509Crl.cs
@@ -130,12 +130,10 @@ namespace Org.BouncyCastle.X509
             if (!c.SignatureAlgorithm.Equals(c.TbsCertList.Signature))
                 throw new CrlException("Signature algorithm on CertificateList does not match TbsCertList.");
 
-            byte[] b = GetTbsCertList();
-
             IStreamCalculator<IVerifier> streamCalculator = verifier.CreateCalculator();
 			using (var stream = streamCalculator.Stream)
 			{
-				stream.Write(b, 0, b.Length);
+				c.TbsCertList.EncodeTo(stream, Asn1Encodable.Der);
             }
 
             if (!streamCalculator.GetResult().IsVerified(GetSignature()))
diff --git a/crypto/src/x509/X509V1CertificateGenerator.cs b/crypto/src/x509/X509V1CertificateGenerator.cs
index d95f522e8..93ec03ea3 100644
--- a/crypto/src/x509/X509V1CertificateGenerator.cs
+++ b/crypto/src/x509/X509V1CertificateGenerator.cs
@@ -125,7 +125,7 @@ namespace Org.BouncyCastle.X509
 			TbsCertificateStructure tbsCert = tbsGen.GenerateTbsCertificate();
 
 			IStreamCalculator<IBlockResult> streamCalculator = signatureFactory.CreateCalculator();
-			using (Stream sigStream = streamCalculator.Stream)
+			using (var sigStream = streamCalculator.Stream)
 			{
 				tbsCert.EncodeTo(sigStream, Asn1Encodable.Der);
 			}
diff --git a/crypto/src/x509/X509V2AttributeCertificate.cs b/crypto/src/x509/X509V2AttributeCertificate.cs
index 61702aebd..b5a316d76 100644
--- a/crypto/src/x509/X509V2AttributeCertificate.cs
+++ b/crypto/src/x509/X509V2AttributeCertificate.cs
@@ -190,11 +190,9 @@ namespace Org.BouncyCastle.X509
 
 			try
 			{
-                byte[] b = this.cert.ACInfo.GetEncoded();
-
 				using (var stream = streamCalculator.Stream)
 				{
-                    stream.Write(b, 0, b.Length);
+					cert.ACInfo.EncodeTo(stream);
                 }
             }
 			catch (IOException e)
@@ -202,7 +200,7 @@ namespace Org.BouncyCastle.X509
 				throw new SignatureException("Exception encoding certificate info object", e);
 			}
 
-			if (!streamCalculator.GetResult().IsVerified(this.GetSignature()))
+			if (!streamCalculator.GetResult().IsVerified(GetSignature()))
 				throw new InvalidKeyException("Public key presented not for certificate signature");
 		}
 
diff --git a/crypto/src/x509/X509V2AttributeCertificateGenerator.cs b/crypto/src/x509/X509V2AttributeCertificateGenerator.cs
index 3a0a02ea9..f1f4c0473 100644
--- a/crypto/src/x509/X509V2AttributeCertificateGenerator.cs
+++ b/crypto/src/x509/X509V2AttributeCertificateGenerator.cs
@@ -120,7 +120,7 @@ namespace Org.BouncyCastle.X509
             AttributeCertificateInfo acInfo = acInfoGen.GenerateAttributeCertificateInfo();
 
 			IStreamCalculator<IBlockResult> streamCalculator = signatureFactory.CreateCalculator();
-			using (Stream sigStream = streamCalculator.Stream)
+			using (var sigStream = streamCalculator.Stream)
 			{
 				acInfo.EncodeTo(sigStream, Asn1Encodable.Der);
 			}
diff --git a/crypto/src/x509/X509V2CRLGenerator.cs b/crypto/src/x509/X509V2CRLGenerator.cs
index a57383613..3d8b96ad2 100644
--- a/crypto/src/x509/X509V2CRLGenerator.cs
+++ b/crypto/src/x509/X509V2CRLGenerator.cs
@@ -188,7 +188,7 @@ namespace Org.BouncyCastle.X509
 			TbsCertificateList tbsCertList = tbsGen.GenerateTbsCertList();
 
             IStreamCalculator<IBlockResult> streamCalculator = signatureFactory.CreateCalculator();
-			using (Stream sigStream = streamCalculator.Stream)
+			using (var sigStream = streamCalculator.Stream)
 			{
 				tbsCertList.EncodeTo(sigStream, Asn1Encodable.Der);
 			}
diff --git a/crypto/src/x509/X509V3CertificateGenerator.cs b/crypto/src/x509/X509V3CertificateGenerator.cs
index 1854ac3b4..ee35b9479 100644
--- a/crypto/src/x509/X509V3CertificateGenerator.cs
+++ b/crypto/src/x509/X509V3CertificateGenerator.cs
@@ -260,7 +260,7 @@ namespace Org.BouncyCastle.X509
             TbsCertificateStructure tbsCert = tbsGen.GenerateTbsCertificate();
 
 			IStreamCalculator<IBlockResult> streamCalculator = signatureFactory.CreateCalculator();
-			using (Stream sigStream = streamCalculator.Stream)
+			using (var sigStream = streamCalculator.Stream)
             {
 				tbsCert.EncodeTo(sigStream, Asn1Encodable.Der);
 			}