summary refs log tree commit diff
path: root/crypto/src/asn1/ocsp/ResponderID.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-05-24 23:19:59 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-05-24 23:19:59 +0700
commit7bd081a948b177460a36984bafffa41d1548b3ad (patch)
tree84f37ba48507aa79e91c6cbad2f60d9111669a4c /crypto/src/asn1/ocsp/ResponderID.cs
parentAdd helper methods for optional tagged fields (diff)
downloadBouncyCastle.NET-ed25519-7bd081a948b177460a36984bafffa41d1548b3ad.tar.xz
Refactoring in Asn1.Ocsp
Diffstat (limited to 'crypto/src/asn1/ocsp/ResponderID.cs')
-rw-r--r--crypto/src/asn1/ocsp/ResponderID.cs62
1 files changed, 24 insertions, 38 deletions
diff --git a/crypto/src/asn1/ocsp/ResponderID.cs b/crypto/src/asn1/ocsp/ResponderID.cs
index d677e63b0..aea935e06 100644
--- a/crypto/src/asn1/ocsp/ResponderID.cs
+++ b/crypto/src/asn1/ocsp/ResponderID.cs
@@ -1,6 +1,5 @@
 using System;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 
 namespace Org.BouncyCastle.Asn1.Ocsp
@@ -8,26 +7,23 @@ namespace Org.BouncyCastle.Asn1.Ocsp
     public class ResponderID
         : Asn1Encodable, IAsn1Choice
     {
-        private readonly Asn1Encodable id;
-
 		public static ResponderID GetInstance(object obj)
 		{
-			if (obj == null || obj is ResponderID)
-			{
-				return (ResponderID)obj;
-			}
+			if (obj == null)
+				return null;
 
-			if (obj is Asn1OctetString octets)
-			{
-				return new ResponderID(octets);
-			}
+			if (obj is ResponderID responderID)
+				return responderID;
 
-			if (obj is Asn1TaggedObject o)
+			if (obj is Asn1OctetString asn1OctetString)
+				return new ResponderID(asn1OctetString);
+
+			if (obj is Asn1TaggedObject taggedObject)
 			{
-				if (o.TagNo == 1)
-					return new ResponderID(X509Name.GetInstance(o, true));
+				if (taggedObject.HasContextTag(1))
+					return new ResponderID(X509Name.GetInstance(taggedObject, true));
 
-				return new ResponderID(Asn1OctetString.GetInstance(o, true));
+				return new ResponderID(Asn1OctetString.GetInstance(taggedObject, true));
 			}
 
 			return new ResponderID(X509Name.GetInstance(obj));
@@ -38,28 +34,22 @@ namespace Org.BouncyCastle.Asn1.Ocsp
             return Asn1Utilities.GetInstanceFromChoice(obj, isExplicit, GetInstance);
         }
 
-        public ResponderID(
-            Asn1OctetString id)
-        {
-			if (id == null)
-				throw new ArgumentNullException("id");
+        private readonly Asn1Encodable m_id;
 
-			this.id = id;
+        public ResponderID(Asn1OctetString id)
+        {
+			m_id = id ?? throw new ArgumentNullException(nameof(id));
         }
 
-		public ResponderID(
-            X509Name id)
+		public ResponderID(X509Name id)
         {
-			if (id == null)
-				throw new ArgumentNullException("id");
-
-			this.id = id;
+            m_id = id ?? throw new ArgumentNullException(nameof(id));
         }
 
 		public virtual byte[] GetKeyHash()
 		{
-			if (id is Asn1OctetString octetString)
-				return octetString.GetOctets();
+			if (m_id is Asn1OctetString asn1OctetString)
+				return asn1OctetString.GetOctets();
 
 			return null;
 		}
@@ -68,12 +58,10 @@ namespace Org.BouncyCastle.Asn1.Ocsp
 		{
 			get
 			{
-				if (id is Asn1OctetString)
-				{
+				if (m_id is Asn1OctetString)
 					return null;
-				}
 
-				return X509Name.GetInstance(id);
+				return X509Name.GetInstance(m_id);
 			}
 		}
 
@@ -87,12 +75,10 @@ namespace Org.BouncyCastle.Asn1.Ocsp
          */
         public override Asn1Object ToAsn1Object()
         {
-            if (id is Asn1OctetString)
-            {
-                return new DerTaggedObject(true, 2, id);
-            }
+            if (m_id is Asn1OctetString asn1OctetString)
+                return new DerTaggedObject(true, 2, asn1OctetString);
 
-			return new DerTaggedObject(true, 1, id);
+			return new DerTaggedObject(true, 1, m_id);
         }
     }
 }