summary refs log tree commit diff
path: root/crypto/src/x509/X509Certificate.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-01-18 19:48:36 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-01-18 19:48:36 +0700
commit21169fe008d79b1981bd8f17aeb42e78752882d2 (patch)
treef950d88469fcf82e2741bbd8b1522d14e4070bcf /crypto/src/x509/X509Certificate.cs
parentRefactoring in DerObjectIdentifier (diff)
downloadBouncyCastle.NET-ed25519-21169fe008d79b1981bd8f17aeb42e78752882d2.tar.xz
Lazy creation of SigAlgName
Diffstat (limited to 'crypto/src/x509/X509Certificate.cs')
-rw-r--r--crypto/src/x509/X509Certificate.cs17
1 files changed, 7 insertions, 10 deletions
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index 465899042..316eaad99 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -58,11 +58,12 @@ namespace Org.BouncyCastle.X509
         private readonly X509CertificateStructure c;
         //private Dictionary<> pkcs12Attributes = new Dictionary<>();
         //private List<> pkcs12Ordering = new List<>();
-        private readonly string sigAlgName;
         private readonly byte[] sigAlgParams;
         private readonly BasicConstraints basicConstraints;
         private readonly bool[] keyUsage;
 
+        private string m_sigAlgName = null;
+
         private AsymmetricKeyParameter publicKeyValue;
         private CachedEncoding cachedEncoding;
 
@@ -84,10 +85,8 @@ namespace Org.BouncyCastle.X509
 
             try
             {
-                this.sigAlgName = X509SignatureUtilities.GetSignatureName(c.SignatureAlgorithm);
-
                 Asn1Encodable parameters = c.SignatureAlgorithm.Parameters;
-                this.sigAlgParams = (null == parameters) ? null : parameters.GetEncoded(Asn1Encodable.Der);
+                this.sigAlgParams = parameters?.GetEncoded(Asn1Encodable.Der);
             }
             catch (Exception e)
             {
@@ -288,13 +287,11 @@ namespace Org.BouncyCastle.X509
         }
 
         /// <summary>
-		/// A meaningful version of the Signature Algorithm. (EG SHA1WITHRSA)
+		/// A meaningful version of the Signature Algorithm. (e.g. SHA1WITHRSA)
 		/// </summary>
-		/// <returns>A sting representing the signature algorithm.</returns>
-		public virtual string SigAlgName
-        {
-            get { return sigAlgName; }
-        }
+		/// <returns>A string representing the signature algorithm.</returns>
+		public virtual string SigAlgName => Objects.EnsureSingletonInitialized(ref m_sigAlgName, SignatureAlgorithm,
+            X509SignatureUtilities.GetSignatureName);
 
         /// <summary>
         /// Get the Signature Algorithms Object ID.