From a8a17fd70fc8df3ca7402323ad5c4f36b25cb806 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 9 Nov 2022 01:13:27 +0700 Subject: Dispose cleanup - IDisposable for PemReader, PemWriter, IStreamGenerator --- crypto/src/x509/X509Certificate.cs | 12 +++++------- crypto/src/x509/X509Crl.cs | 14 ++++++-------- crypto/src/x509/X509V2AttributeCertificate.cs | 7 ++++--- 3 files changed, 15 insertions(+), 18 deletions(-) (limited to 'crypto/src/x509') diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs index 510f95b01..5b800efe5 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"); - Asn1Encodable parameters = c.SignatureAlgorithm.Parameters; + byte[] b = GetTbsCertificate(); IStreamCalculator streamCalculator = verifier.CreateCalculator(); - - byte[] b = this.GetTbsCertificate(); - - streamCalculator.Stream.Write(b, 0, b.Length); - - Platform.Dispose(streamCalculator.Stream); + using (var stream = streamCalculator.Stream) + { + stream.Write(b, 0, b.Length); + } if (!streamCalculator.GetResult().IsVerified(this.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 265c2293c..db13f4f2f 100644 --- a/crypto/src/x509/X509Crl.cs +++ b/crypto/src/x509/X509Crl.cs @@ -130,17 +130,15 @@ namespace Org.BouncyCastle.X509 if (!c.SignatureAlgorithm.Equals(c.TbsCertList.Signature)) throw new CrlException("Signature algorithm on CertificateList does not match TbsCertList."); - Asn1Encodable parameters = c.SignatureAlgorithm.Parameters; + byte[] b = GetTbsCertList(); IStreamCalculator streamCalculator = verifier.CreateCalculator(); + using (var stream = streamCalculator.Stream) + { + stream.Write(b, 0, b.Length); + } - byte[] b = this.GetTbsCertList(); - - streamCalculator.Stream.Write(b, 0, b.Length); - - Platform.Dispose(streamCalculator.Stream); - - if (!streamCalculator.GetResult().IsVerified(this.GetSignature())) + if (!streamCalculator.GetResult().IsVerified(GetSignature())) throw new InvalidKeyException("CRL does not verify with supplied public key."); } diff --git a/crypto/src/x509/X509V2AttributeCertificate.cs b/crypto/src/x509/X509V2AttributeCertificate.cs index fbb4fe20f..61702aebd 100644 --- a/crypto/src/x509/X509V2AttributeCertificate.cs +++ b/crypto/src/x509/X509V2AttributeCertificate.cs @@ -192,9 +192,10 @@ namespace Org.BouncyCastle.X509 { byte[] b = this.cert.ACInfo.GetEncoded(); - streamCalculator.Stream.Write(b, 0, b.Length); - - Platform.Dispose(streamCalculator.Stream); + using (var stream = streamCalculator.Stream) + { + stream.Write(b, 0, b.Length); + } } catch (IOException e) { -- cgit 1.4.1