summary refs log tree commit diff
path: root/crypto/src/asn1/esf/OtherHashAlgAndValue.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-05-26 22:58:57 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-05-26 22:58:57 +0700
commit46c46cecd4f62abf854576314751e44b320168ba (patch)
tree6bafc67dbf0f5480d9814e7764e770faad233f66 /crypto/src/asn1/esf/OtherHashAlgAndValue.cs
parentAuto-adjust DateTime precision for GeneralizedTime in X.509 (and OCSP) (diff)
downloadBouncyCastle.NET-ed25519-46c46cecd4f62abf854576314751e44b320168ba.tar.xz
Refactoring in Asn1.Esf
Diffstat (limited to 'crypto/src/asn1/esf/OtherHashAlgAndValue.cs')
-rw-r--r--crypto/src/asn1/esf/OtherHashAlgAndValue.cs114
1 files changed, 46 insertions, 68 deletions
diff --git a/crypto/src/asn1/esf/OtherHashAlgAndValue.cs b/crypto/src/asn1/esf/OtherHashAlgAndValue.cs
index 00eb24c54..a99888a84 100644
--- a/crypto/src/asn1/esf/OtherHashAlgAndValue.cs
+++ b/crypto/src/asn1/esf/OtherHashAlgAndValue.cs
@@ -1,95 +1,73 @@
 using System;
 
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Esf
 {
-	/// <summary>
-	/// Summary description for OtherHashAlgAndValue.
-	/// </summary>
-	/// <remarks>
-	/// <code>
-	/// OtherHashAlgAndValue ::= SEQUENCE {
-	///		hashAlgorithm	AlgorithmIdentifier,
-	/// 	hashValue		OtherHashValue
-	/// }
-	/// 
-	/// OtherHashValue ::= OCTET STRING
-	/// </code>
-	/// </remarks>
-	public class OtherHashAlgAndValue
+    /// <summary>
+    /// Summary description for OtherHashAlgAndValue.
+    /// </summary>
+    /// <remarks>
+    /// <code>
+    /// OtherHashAlgAndValue ::= SEQUENCE {
+    ///		hashAlgorithm	AlgorithmIdentifier,
+    /// 	hashValue		OtherHashValue
+    /// }
+    /// 
+    /// OtherHashValue ::= OCTET STRING
+    /// </code>
+    /// </remarks>
+    public class OtherHashAlgAndValue
 		: Asn1Encodable
 	{
-		private readonly AlgorithmIdentifier	hashAlgorithm;
-		private readonly Asn1OctetString		hashValue;
+        public static OtherHashAlgAndValue GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is OtherHashAlgAndValue otherHashAlgAndValue)
+                return otherHashAlgAndValue;
+            return new OtherHashAlgAndValue(Asn1Sequence.GetInstance(obj));
+        }
 
-		public static OtherHashAlgAndValue GetInstance(
-			object obj)
-		{
-			if (obj == null || obj is OtherHashAlgAndValue)
-				return (OtherHashAlgAndValue) obj;
-
-			if (obj is Asn1Sequence)
-				return new OtherHashAlgAndValue((Asn1Sequence) obj);
+        public static OtherHashAlgAndValue GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return new OtherHashAlgAndValue(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
 
-			throw new ArgumentException(
-				"Unknown object in 'OtherHashAlgAndValue' factory: "
-                    + Platform.GetTypeName(obj),
-				"obj");
-		}
+        private readonly AlgorithmIdentifier m_hashAlgorithm;
+        private readonly Asn1OctetString m_hashValue;
 
-		private OtherHashAlgAndValue(
-			Asn1Sequence seq)
+        private OtherHashAlgAndValue(Asn1Sequence seq)
 		{
-			if (seq == null)
-				throw new ArgumentNullException("seq");
-			if (seq.Count != 2)
-				throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
+			int count = seq.Count;
+			if (count != 2)
+				throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
 
-			this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0].ToAsn1Object());
-			this.hashValue = (Asn1OctetString) seq[1].ToAsn1Object();
+			m_hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
+			m_hashValue = Asn1OctetString.GetInstance(seq[1]);
 		}
 
-		public OtherHashAlgAndValue(
-			AlgorithmIdentifier	hashAlgorithm,
-			byte[]				hashValue)
+		public OtherHashAlgAndValue(AlgorithmIdentifier	hashAlgorithm, byte[] hashValue)
 		{
 			if (hashAlgorithm == null)
-				throw new ArgumentNullException("hashAlgorithm");
+				throw new ArgumentNullException(nameof(hashAlgorithm));
 			if (hashValue == null)
-				throw new ArgumentNullException("hashValue");
+				throw new ArgumentNullException(nameof(hashValue));
 
-			this.hashAlgorithm = hashAlgorithm;
-			this.hashValue = new DerOctetString(hashValue);
+			m_hashAlgorithm = hashAlgorithm;
+			m_hashValue = new DerOctetString(hashValue);
 		}
 
-		public OtherHashAlgAndValue(
-			AlgorithmIdentifier	hashAlgorithm,
-			Asn1OctetString		hashValue)
-		{
-			if (hashAlgorithm == null)
-				throw new ArgumentNullException("hashAlgorithm");
-			if (hashValue == null)
-				throw new ArgumentNullException("hashValue");
-
-			this.hashAlgorithm = hashAlgorithm;
-			this.hashValue = hashValue;
+        public OtherHashAlgAndValue(AlgorithmIdentifier hashAlgorithm, Asn1OctetString hashValue)
+        {
+			m_hashAlgorithm = hashAlgorithm ?? throw new ArgumentNullException(nameof(hashAlgorithm));
+            m_hashValue = hashValue ?? throw new ArgumentNullException(nameof(hashValue));
 		}
 
-		public AlgorithmIdentifier HashAlgorithm
-		{
-			get { return hashAlgorithm; }
-		}
+		public AlgorithmIdentifier HashAlgorithm => m_hashAlgorithm;
 
-		public byte[] GetHashValue()
-		{
-			return hashValue.GetOctets();
-		}
+		public byte[] GetHashValue() => m_hashValue.GetOctets();
 
-		public override Asn1Object ToAsn1Object()
-		{
-			return new DerSequence(hashAlgorithm, hashValue);
-		}
+		public override Asn1Object ToAsn1Object() => new DerSequence(m_hashAlgorithm, m_hashValue);
 	}
 }