summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/OobCertHash.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-09-20 14:07:11 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-09-20 14:07:11 +0700
commitc17e29d769cf8a87402ff4d819d334389a7faca4 (patch)
treee60811ecfc45b6c229ce2e87d8b4a6db6d9f2da9 /crypto/src/asn1/cmp/OobCertHash.cs
parentadded randomized signing (diff)
downloadBouncyCastle.NET-ed25519-c17e29d769cf8a87402ff4d819d334389a7faca4.tar.xz
Update Asn1.Cmp from bc-java
Diffstat (limited to 'crypto/src/asn1/cmp/OobCertHash.cs')
-rw-r--r--crypto/src/asn1/cmp/OobCertHash.cs65
1 files changed, 36 insertions, 29 deletions
diff --git a/crypto/src/asn1/cmp/OobCertHash.cs b/crypto/src/asn1/cmp/OobCertHash.cs
index 434939c0e..a18ff300d 100644
--- a/crypto/src/asn1/cmp/OobCertHash.cs
+++ b/crypto/src/asn1/cmp/OobCertHash.cs
@@ -6,18 +6,40 @@ using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Cmp
 {
-	public class OobCertHash
+    /**
+     * <pre>
+     * OOBCertHash ::= SEQUENCE {
+     * hashAlg     [0] AlgorithmIdentifier     OPTIONAL,
+     * certId      [1] CertId                  OPTIONAL,
+     * hashVal         BIT STRING
+     * -- hashVal is calculated over the DER encoding of the
+     * -- self-signed certificate with the identifier certID.
+     * }
+     * </pre>
+     */
+    public class OobCertHash
 		: Asn1Encodable
 	{
-		private readonly AlgorithmIdentifier hashAlg;
-		private readonly CertId certId;
-		private readonly DerBitString  hashVal;
+        public static OobCertHash GetInstance(object obj)
+        {
+			if (obj is OobCertHash oobCertHash)
+				return oobCertHash;
+
+			if (obj != null)
+				return new OobCertHash(Asn1Sequence.GetInstance(obj));
+
+			return null;
+        }
+
+        private readonly AlgorithmIdentifier m_hashAlg;
+		private readonly CertId m_certId;
+		private readonly DerBitString m_hashVal;
 
 		private OobCertHash(Asn1Sequence seq)
 		{
 			int index = seq.Count - 1;
 
-			hashVal = DerBitString.GetInstance(seq[index--]);
+			m_hashVal = DerBitString.GetInstance(seq[index--]);
 
 			for (int i = index; i >= 0; i--)
 			{
@@ -25,36 +47,21 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
 				if (tObj.TagNo == 0)
 				{
-					hashAlg = AlgorithmIdentifier.GetInstance(tObj, true);
+					m_hashAlg = AlgorithmIdentifier.GetInstance(tObj, true);
 				}
 				else
 				{
-					certId = CertId.GetInstance(tObj, true);
+					m_certId = CertId.GetInstance(tObj, true);
 				}
 			}
 		}
 
-		public static OobCertHash GetInstance(object obj)
-		{
-			if (obj is OobCertHash)
-				return (OobCertHash)obj;
+		public virtual CertId CertID => m_certId;
 
-			if (obj is Asn1Sequence)
-				return new OobCertHash((Asn1Sequence)obj);
+        public virtual AlgorithmIdentifier HashAlg => m_hashAlg;
+
+		public virtual DerBitString HashVal => m_hashVal;
 
-            throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
-		}
-		
-		public virtual AlgorithmIdentifier HashAlg
-		{
-			get { return hashAlg; }
-		}
-		
-		public virtual CertId CertID
-		{
-			get { return certId; }
-		}
-		
 		/**
 		 * <pre>
 		 * OobCertHash ::= SEQUENCE {
@@ -70,9 +77,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector();
-            v.AddOptionalTagged(true, 0, hashAlg);
-            v.AddOptionalTagged(true, 1, certId);
-			v.Add(hashVal);
+            v.AddOptionalTagged(true, 0, m_hashAlg);
+            v.AddOptionalTagged(true, 1, m_certId);
+			v.Add(m_hashVal);
 			return new DerSequence(v);
 		}
 	}