summary refs log tree commit diff
path: root/crypto/src/asn1/x509
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-05-26 23:37:18 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-05-26 23:37:18 +0700
commit2337fe276d9abf4e382c5e373c70aa144554d8c1 (patch)
tree3a4bd9da1e0eab04bc5521e1223568d42fb61ca7 /crypto/src/asn1/x509
parentRefactoring in Asn1.Esf (diff)
downloadBouncyCastle.NET-ed25519-2337fe276d9abf4e382c5e373c70aa144554d8c1.tar.xz
Refactoring in ASN.1 classes
Diffstat (limited to 'crypto/src/asn1/x509')
-rw-r--r--crypto/src/asn1/x509/IssuerSerial.cs37
-rw-r--r--crypto/src/asn1/x509/PolicyInformation.cs25
-rw-r--r--crypto/src/asn1/x509/X509Extensions.cs9
-rw-r--r--crypto/src/asn1/x509/X509Name.cs4
4 files changed, 33 insertions, 42 deletions
diff --git a/crypto/src/asn1/x509/IssuerSerial.cs b/crypto/src/asn1/x509/IssuerSerial.cs
index 2c26339bd..09b6dae18 100644
--- a/crypto/src/asn1/x509/IssuerSerial.cs
+++ b/crypto/src/asn1/x509/IssuerSerial.cs
@@ -1,40 +1,29 @@
 using System;
 
-using Org.BouncyCastle.Utilities;
-
 namespace Org.BouncyCastle.Asn1.X509
 {
     public class IssuerSerial
         : Asn1Encodable
     {
-        internal readonly GeneralNames	issuer;
-        internal readonly DerInteger	serial;
-        internal readonly DerBitString	issuerUid;
-
-		public static IssuerSerial GetInstance(
-            object obj)
+		public static IssuerSerial GetInstance(object obj)
         {
-            if (obj == null || obj is IssuerSerial)
-            {
-                return (IssuerSerial) obj;
-            }
-
-			if (obj is Asn1Sequence)
-            {
-                return new IssuerSerial((Asn1Sequence) obj);
-            }
-
-            throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
+            if (obj == null)
+                return null;
+            if (obj is IssuerSerial issuerSerial)
+                return issuerSerial;
+            return new IssuerSerial(Asn1Sequence.GetInstance(obj));
 		}
 
-        public static IssuerSerial GetInstance(
-            Asn1TaggedObject	obj,
-            bool				explicitly)
+        public static IssuerSerial GetInstance(Asn1TaggedObject obj, bool explicitly)
         {
-            return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
+            return new IssuerSerial(Asn1Sequence.GetInstance(obj, explicitly));
         }
 
-		private IssuerSerial(
+        private readonly GeneralNames issuer;
+        private readonly DerInteger serial;
+        private readonly DerBitString issuerUid;
+
+        private IssuerSerial(
             Asn1Sequence seq)
         {
 			if (seq.Count != 2 && seq.Count != 3)
diff --git a/crypto/src/asn1/x509/PolicyInformation.cs b/crypto/src/asn1/x509/PolicyInformation.cs
index 90db29a36..fca5fd03b 100644
--- a/crypto/src/asn1/x509/PolicyInformation.cs
+++ b/crypto/src/asn1/x509/PolicyInformation.cs
@@ -5,6 +5,20 @@ namespace Org.BouncyCastle.Asn1.X509
     public class PolicyInformation
         : Asn1Encodable
     {
+        public static PolicyInformation GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is PolicyInformation policyInformation)
+                return policyInformation;
+            return new PolicyInformation(Asn1Sequence.GetInstance(obj));
+        }
+
+        public static PolicyInformation GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return new PolicyInformation(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
+
         private readonly DerObjectIdentifier	policyIdentifier;
         private readonly Asn1Sequence			policyQualifiers;
 
@@ -38,17 +52,6 @@ namespace Org.BouncyCastle.Asn1.X509
             this.policyQualifiers = policyQualifiers;
         }
 
-		public static PolicyInformation GetInstance(
-            object obj)
-        {
-            if (obj == null || obj is PolicyInformation)
-            {
-                return (PolicyInformation) obj;
-            }
-
-			return new PolicyInformation(Asn1Sequence.GetInstance(obj));
-        }
-
 		public DerObjectIdentifier PolicyIdentifier
 		{
 			get { return policyIdentifier; }
diff --git a/crypto/src/asn1/x509/X509Extensions.cs b/crypto/src/asn1/x509/X509Extensions.cs
index 5d83ecdc6..2893f8b79 100644
--- a/crypto/src/asn1/x509/X509Extensions.cs
+++ b/crypto/src/asn1/x509/X509Extensions.cs
@@ -233,17 +233,16 @@ namespace Org.BouncyCastle.Asn1.X509
 
 			foreach (Asn1Encodable ae in seq)
 			{
-				Asn1Sequence s = Asn1Sequence.GetInstance(ae.ToAsn1Object());
+				Asn1Sequence s = Asn1Sequence.GetInstance(ae);
 
 				if (s.Count < 2 || s.Count > 3)
 					throw new ArgumentException("Bad sequence size: " + s.Count);
 
-				DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(s[0].ToAsn1Object());
+				DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(s[0]);
 
-				bool isCritical = s.Count == 3
-					&& DerBoolean.GetInstance(s[1].ToAsn1Object()).IsTrue;
+				bool isCritical = s.Count == 3 && DerBoolean.GetInstance(s[1]).IsTrue;
 
-				Asn1OctetString octets = Asn1OctetString.GetInstance(s[s.Count - 1].ToAsn1Object());
+				Asn1OctetString octets = Asn1OctetString.GetInstance(s[s.Count - 1]);
 
                 if (m_extensions.ContainsKey(oid))
                     throw new ArgumentException("repeated extension found: " + oid);
diff --git a/crypto/src/asn1/x509/X509Name.cs b/crypto/src/asn1/x509/X509Name.cs
index 6135ad2fa..8f25e49ef 100644
--- a/crypto/src/asn1/x509/X509Name.cs
+++ b/crypto/src/asn1/x509/X509Name.cs
@@ -360,7 +360,7 @@ namespace Org.BouncyCastle.Asn1.X509
             foreach (Asn1Encodable asn1Obj in seq)
             {
                 // RelativeDistinguishedName ::= SET SIZE(1..MAX) OF AttributeTypeAndValue
-                Asn1Set rdn = Asn1Set.GetInstance(asn1Obj.ToAsn1Object());
+                Asn1Set rdn = Asn1Set.GetInstance(asn1Obj);
 
                 // TODO Apply this check? (Currently "breaks" CertificateTest.CheckDudCertificate)
                 //if (rdn.Count < 1)
@@ -368,7 +368,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
                 for (int i = 0; i < rdn.Count; ++i)
                 {
-                    Asn1Sequence attributeTypeAndValue = Asn1Sequence.GetInstance(rdn[i].ToAsn1Object());
+                    Asn1Sequence attributeTypeAndValue = Asn1Sequence.GetInstance(rdn[i]);
                     if (attributeTypeAndValue.Count != 2)
                         throw new ArgumentException("badly sized AttributeTypeAndValue");