summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/asn1/cms/AuthenticatedData.cs8
-rw-r--r--crypto/src/asn1/cms/Evidence.cs8
-rw-r--r--crypto/src/asn1/cms/OriginatorIdentifierOrKey.cs23
-rw-r--r--crypto/src/asn1/cms/RecipientInfo.cs66
-rw-r--r--crypto/src/asn1/cms/SignedData.cs4
-rw-r--r--crypto/src/asn1/cms/SignerIdentifier.cs12
-rw-r--r--crypto/src/asn1/crmf/PKIArchiveOptions.cs8
-rw-r--r--crypto/src/asn1/crmf/PopoSigningKey.cs11
-rw-r--r--crypto/src/asn1/crmf/PopoSigningKeyInput.cs8
-rw-r--r--crypto/src/asn1/crmf/ProofOfPossession.cs8
-rw-r--r--crypto/src/asn1/isismtt/ocsp/RequestedCertificate.cs20
-rw-r--r--crypto/src/asn1/ocsp/CertStatus.cs20
-rw-r--r--crypto/src/asn1/ocsp/TBSRequest.cs9
-rw-r--r--crypto/src/asn1/x509/AttCertIssuer.cs49
-rw-r--r--crypto/src/asn1/x509/Holder.cs27
-rw-r--r--crypto/src/asn1/x509/IetfAttrSyntax.cs4
-rw-r--r--crypto/src/asn1/x509/Target.cs25
-rw-r--r--crypto/src/asn1/x509/X509Extensions.cs28
18 files changed, 152 insertions, 186 deletions
diff --git a/crypto/src/asn1/cms/AuthenticatedData.cs b/crypto/src/asn1/cms/AuthenticatedData.cs
index 6ec8061e2..709617063 100644
--- a/crypto/src/asn1/cms/AuthenticatedData.cs
+++ b/crypto/src/asn1/cms/AuthenticatedData.cs
@@ -214,10 +214,8 @@ namespace Org.BouncyCastle.Asn1.Cms
 
 			foreach (object obj in origInfo.Certificates)
 			{
-				if (obj is Asn1TaggedObject)
+				if (obj is Asn1TaggedObject tag)
 				{
-					Asn1TaggedObject tag = (Asn1TaggedObject)obj;
-
 					if (tag.TagNo == 2)
 					{
 						ver = 1;
@@ -232,10 +230,8 @@ namespace Org.BouncyCastle.Asn1.Cms
 
 			foreach (object obj in origInfo.Crls)
 			{
-				if (obj is Asn1TaggedObject)
+				if (obj is Asn1TaggedObject tag)
 				{
-					Asn1TaggedObject tag = (Asn1TaggedObject)obj;
-
 					if (tag.TagNo == 1)
 					{
 						ver = 3;
diff --git a/crypto/src/asn1/cms/Evidence.cs b/crypto/src/asn1/cms/Evidence.cs
index b12f090a9..2e39054d6 100644
--- a/crypto/src/asn1/cms/Evidence.cs
+++ b/crypto/src/asn1/cms/Evidence.cs
@@ -37,11 +37,11 @@ namespace Org.BouncyCastle.Asn1.Cms
 
 		public static Evidence GetInstance(object obj)
 		{
-			if (obj is Evidence)
-				return (Evidence)obj;
+			if (obj is Evidence evidence)
+				return evidence;
 
-			if (obj is Asn1TaggedObject)
-				return new Evidence(Asn1TaggedObject.GetInstance(obj));
+			if (obj is Asn1TaggedObject taggedObject)
+				return new Evidence(taggedObject);
 
 			throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
 		}
diff --git a/crypto/src/asn1/cms/OriginatorIdentifierOrKey.cs b/crypto/src/asn1/cms/OriginatorIdentifierOrKey.cs
index 296cadf94..01c5a31a1 100644
--- a/crypto/src/asn1/cms/OriginatorIdentifierOrKey.cs
+++ b/crypto/src/asn1/cms/OriginatorIdentifierOrKey.cs
@@ -62,20 +62,23 @@ namespace Org.BouncyCastle.Asn1.Cms
         public static OriginatorIdentifierOrKey GetInstance(
             object o)
         {
-            if (o == null || o is OriginatorIdentifierOrKey)
-                return (OriginatorIdentifierOrKey)o;
+            if (o == null)
+                return null;
 
-			if (o is IssuerAndSerialNumber)
-				return new OriginatorIdentifierOrKey((IssuerAndSerialNumber)o);
+            if (o is OriginatorIdentifierOrKey originatorIdentifierOrKey)
+                return originatorIdentifierOrKey;
 
-			if (o is SubjectKeyIdentifier)
-				return new OriginatorIdentifierOrKey((SubjectKeyIdentifier)o);
+			if (o is IssuerAndSerialNumber issuerAndSerialNumber)
+				return new OriginatorIdentifierOrKey(issuerAndSerialNumber);
 
-			if (o is OriginatorPublicKey)
-				return new OriginatorIdentifierOrKey((OriginatorPublicKey)o);
+			if (o is SubjectKeyIdentifier subjectKeyIdentifier)
+				return new OriginatorIdentifierOrKey(subjectKeyIdentifier);
 
-			if (o is Asn1TaggedObject)
-				return new OriginatorIdentifierOrKey((Asn1TaggedObject)o);
+			if (o is OriginatorPublicKey originatorPublicKey)
+				return new OriginatorIdentifierOrKey(originatorPublicKey);
+
+			if (o is Asn1TaggedObject taggedObject)
+				return new OriginatorIdentifierOrKey(taggedObject);
 
             throw new ArgumentException("Invalid OriginatorIdentifierOrKey: " + Platform.GetTypeName(o));
         }
diff --git a/crypto/src/asn1/cms/RecipientInfo.cs b/crypto/src/asn1/cms/RecipientInfo.cs
index c03ad907f..3f5ccea5b 100644
--- a/crypto/src/asn1/cms/RecipientInfo.cs
+++ b/crypto/src/asn1/cms/RecipientInfo.cs
@@ -45,17 +45,19 @@ namespace Org.BouncyCastle.Asn1.Cms
             this.info = info;
         }
 
-		public static RecipientInfo GetInstance(
-            object o)
+		public static RecipientInfo GetInstance(object o)
         {
-            if (o == null || o is RecipientInfo)
-                return (RecipientInfo) o;
+			if (o == null)
+				return null;
 
-			if (o is Asn1Sequence)
-                return new RecipientInfo((Asn1Sequence) o);
+            if (o is RecipientInfo recipientInfo)
+                return recipientInfo;
 
-			if (o is Asn1TaggedObject)
-                return new RecipientInfo((Asn1TaggedObject) o);
+			if (o is Asn1Sequence sequence)
+                return new RecipientInfo(sequence);
+
+			if (o is Asn1TaggedObject taggedObject)
+                return new RecipientInfo(taggedObject);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(o));
         }
@@ -64,22 +66,20 @@ namespace Org.BouncyCastle.Asn1.Cms
         {
 			get
 			{
-				if (info is Asn1TaggedObject)
+				if (info is Asn1TaggedObject o)
 				{
-					Asn1TaggedObject o = (Asn1TaggedObject) info;
-
 					switch (o.TagNo)
 					{
-						case 1:
-							return KeyAgreeRecipientInfo.GetInstance(o, false).Version;
-						case 2:
-							return GetKekInfo(o).Version;
-						case 3:
-							return PasswordRecipientInfo.GetInstance(o, false).Version;
-						case 4:
-							return new DerInteger(0);    // no syntax version for OtherRecipientInfo
-						default:
-							throw new InvalidOperationException("unknown tag");
+					case 1:
+						return KeyAgreeRecipientInfo.GetInstance(o, false).Version;
+					case 2:
+						return GetKekInfo(o).Version;
+					case 3:
+						return PasswordRecipientInfo.GetInstance(o, false).Version;
+					case 4:
+						return new DerInteger(0);    // no syntax version for OtherRecipientInfo
+					default:
+						throw new InvalidOperationException("unknown tag");
 					}
 				}
 
@@ -96,22 +96,20 @@ namespace Org.BouncyCastle.Asn1.Cms
         {
 			get
 			{
-				if (info is Asn1TaggedObject)
+				if (info is Asn1TaggedObject o)
 				{
-					Asn1TaggedObject o = (Asn1TaggedObject) info;
-
 					switch (o.TagNo)
 					{
-						case 1:
-							return KeyAgreeRecipientInfo.GetInstance(o, false);
-						case 2:
-							return GetKekInfo(o);
-						case 3:
-							return PasswordRecipientInfo.GetInstance(o, false);
-						case 4:
-							return OtherRecipientInfo.GetInstance(o, false);
-						default:
-							throw new InvalidOperationException("unknown tag");
+					case 1:
+						return KeyAgreeRecipientInfo.GetInstance(o, false);
+					case 2:
+						return GetKekInfo(o);
+					case 3:
+						return PasswordRecipientInfo.GetInstance(o, false);
+					case 4:
+						return OtherRecipientInfo.GetInstance(o, false);
+					default:
+						throw new InvalidOperationException("unknown tag");
 					}
 				}
 
diff --git a/crypto/src/asn1/cms/SignedData.cs b/crypto/src/asn1/cms/SignedData.cs
index 6b07e5128..9018bc6fd 100644
--- a/crypto/src/asn1/cms/SignedData.cs
+++ b/crypto/src/asn1/cms/SignedData.cs
@@ -81,10 +81,8 @@ namespace Org.BouncyCastle.Asn1.Cms
             {
                 foreach (object obj in certs)
                 {
-                    if (obj is Asn1TaggedObject)
+                    if (obj is Asn1TaggedObject tagged)
                     {
-                        Asn1TaggedObject tagged = (Asn1TaggedObject)obj;
-
                         if (tagged.TagNo == 1)
                         {
                             attrCertV1Found = true;
diff --git a/crypto/src/asn1/cms/SignerIdentifier.cs b/crypto/src/asn1/cms/SignerIdentifier.cs
index 195ab741f..9edf6a8c8 100644
--- a/crypto/src/asn1/cms/SignerIdentifier.cs
+++ b/crypto/src/asn1/cms/SignerIdentifier.cs
@@ -57,20 +57,18 @@ namespace Org.BouncyCastle.Asn1.Cms
 			get { return (id is Asn1TaggedObject); }
 		}
 
-		public Asn1Encodable ID
+        public Asn1Encodable ID
         {
             get
             {
-                if (id is Asn1TaggedObject)
-                {
-                    return Asn1OctetString.GetInstance((Asn1TaggedObject)id, false);
-                }
+                if (id is Asn1TaggedObject taggedObject)
+                    return Asn1OctetString.GetInstance(taggedObject, false);
 
-				return id;
+                return id;
             }
         }
 
-		/**
+        /**
          * Produce an object suitable for an Asn1OutputStream.
          * <pre>
          * SignerIdentifier ::= CHOICE {
diff --git a/crypto/src/asn1/crmf/PKIArchiveOptions.cs b/crypto/src/asn1/crmf/PKIArchiveOptions.cs
index 1813d87a7..e546fb3bb 100644
--- a/crypto/src/asn1/crmf/PKIArchiveOptions.cs
+++ b/crypto/src/asn1/crmf/PKIArchiveOptions.cs
@@ -15,11 +15,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
 
         public static PkiArchiveOptions GetInstance(object obj)
         {
-            if (obj is PkiArchiveOptions)
-                return (PkiArchiveOptions)obj;
+            if (obj is PkiArchiveOptions pkiArchiveOptions)
+                return pkiArchiveOptions;
 
-            if (obj is Asn1TaggedObject)
-                return new PkiArchiveOptions((Asn1TaggedObject)obj);
+            if (obj is Asn1TaggedObject taggedObject)
+                return new PkiArchiveOptions(taggedObject);
 
             throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
         }
diff --git a/crypto/src/asn1/crmf/PopoSigningKey.cs b/crypto/src/asn1/crmf/PopoSigningKey.cs
index 93e14e30d..caa226b56 100644
--- a/crypto/src/asn1/crmf/PopoSigningKey.cs
+++ b/crypto/src/asn1/crmf/PopoSigningKey.cs
@@ -16,14 +16,13 @@ namespace Org.BouncyCastle.Asn1.Crmf
         {
             int index = 0;
 
-            if (seq[index] is Asn1TaggedObject)
+            if (seq[index] is Asn1TaggedObject tagObj)
             {
-                Asn1TaggedObject tagObj
-                    = (Asn1TaggedObject) seq[index++];
+                index++;
+
                 if (tagObj.TagNo != 0)
-                {
-                    throw new ArgumentException( "Unknown PopoSigningKeyInput tag: " + tagObj.TagNo, "seq");
-                }
+                    throw new ArgumentException( "Unknown PopoSigningKeyInput tag: " + tagObj.TagNo, nameof(seq));
+
                 poposkInput = PopoSigningKeyInput.GetInstance(tagObj.GetObject());
             }
             algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[index++]);
diff --git a/crypto/src/asn1/crmf/PopoSigningKeyInput.cs b/crypto/src/asn1/crmf/PopoSigningKeyInput.cs
index 30d017475..f2517aa57 100644
--- a/crypto/src/asn1/crmf/PopoSigningKeyInput.cs
+++ b/crypto/src/asn1/crmf/PopoSigningKeyInput.cs
@@ -16,13 +16,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
         {
             Asn1Encodable authInfo = (Asn1Encodable)seq[0];
 
-            if (authInfo is Asn1TaggedObject)
+            if (authInfo is Asn1TaggedObject tagObj)
             {
-                Asn1TaggedObject tagObj = (Asn1TaggedObject)authInfo;
                 if (tagObj.TagNo != 0)
-                {
-                    throw new ArgumentException("Unknown authInfo tag: " + tagObj.TagNo, "seq");
-                }
+                    throw new ArgumentException("Unknown authInfo tag: " + tagObj.TagNo, nameof(seq));
+
                 sender = GeneralName.GetInstance(tagObj.GetObject());
             }
             else
diff --git a/crypto/src/asn1/crmf/ProofOfPossession.cs b/crypto/src/asn1/crmf/ProofOfPossession.cs
index 7ba7251a1..6ef62efda 100644
--- a/crypto/src/asn1/crmf/ProofOfPossession.cs
+++ b/crypto/src/asn1/crmf/ProofOfPossession.cs
@@ -38,11 +38,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
 
         public static ProofOfPossession GetInstance(object obj)
         {
-            if (obj is ProofOfPossession)
-                return (ProofOfPossession)obj;
+            if (obj is ProofOfPossession proofOfPossession)
+                return proofOfPossession;
 
-            if (obj is Asn1TaggedObject)
-                return new ProofOfPossession((Asn1TaggedObject)obj);
+            if (obj is Asn1TaggedObject taggedObject)
+                return new ProofOfPossession(taggedObject);
 
             throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
         }
diff --git a/crypto/src/asn1/isismtt/ocsp/RequestedCertificate.cs b/crypto/src/asn1/isismtt/ocsp/RequestedCertificate.cs
index 413b3bd7f..0348b0916 100644
--- a/crypto/src/asn1/isismtt/ocsp/RequestedCertificate.cs
+++ b/crypto/src/asn1/isismtt/ocsp/RequestedCertificate.cs
@@ -53,23 +53,19 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.Ocsp
 		private readonly byte[]						publicKeyCert;
 		private readonly byte[]						attributeCert;
 
-		public static RequestedCertificate GetInstance(
-			object obj)
+		public static RequestedCertificate GetInstance(object obj)
 		{
-			if (obj == null || obj is RequestedCertificate)
-			{
-				return (RequestedCertificate) obj;
-			}
+			if (obj == null)
+				return null;
+
+			if (obj is RequestedCertificate requestedCertificate)
+				return requestedCertificate;
 
 			if (obj is Asn1Sequence)
-			{
 				return new RequestedCertificate(X509CertificateStructure.GetInstance(obj));
-			}
 
-			if (obj is Asn1TaggedObject)
-			{
-				return new RequestedCertificate((Asn1TaggedObject) obj);
-			}
+            if (obj is Asn1TaggedObject taggedObject)
+                return new RequestedCertificate(taggedObject);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
 		}
diff --git a/crypto/src/asn1/ocsp/CertStatus.cs b/crypto/src/asn1/ocsp/CertStatus.cs
index 8a4d2242d..65f11fc7f 100644
--- a/crypto/src/asn1/ocsp/CertStatus.cs
+++ b/crypto/src/asn1/ocsp/CertStatus.cs
@@ -54,23 +54,21 @@ namespace Org.BouncyCastle.Asn1.Ocsp
             }
         }
 
-		public static CertStatus GetInstance(
-            object obj)
+        public static CertStatus GetInstance(object obj)
         {
-            if (obj == null || obj is CertStatus)
-            {
-                return (CertStatus)obj;
-            }
+            if (obj == null)
+                return null;
 
-			if (obj is Asn1TaggedObject)
-            {
-                return new CertStatus((Asn1TaggedObject)obj);
-            }
+            if (obj is CertStatus certStatus)
+                return certStatus;
+
+            if (obj is Asn1TaggedObject taggedObject)
+                return new CertStatus(taggedObject);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
         }
 
-		public int TagNo
+        public int TagNo
 		{
 			get { return tagNo; }
 		}
diff --git a/crypto/src/asn1/ocsp/TBSRequest.cs b/crypto/src/asn1/ocsp/TBSRequest.cs
index fd5f153d7..8e3373f87 100644
--- a/crypto/src/asn1/ocsp/TBSRequest.cs
+++ b/crypto/src/asn1/ocsp/TBSRequest.cs
@@ -57,10 +57,8 @@ namespace Org.BouncyCastle.Asn1.Ocsp
             int index = 0;
 
 			Asn1Encodable enc = seq[0];
-			if (enc is Asn1TaggedObject)
+			if (enc is Asn1TaggedObject o)
             {
-                Asn1TaggedObject o = (Asn1TaggedObject) enc;
-
 				if (o.TagNo == 0)
                 {
 					versionSet = true;
@@ -77,9 +75,10 @@ namespace Org.BouncyCastle.Asn1.Ocsp
                 version = V1;
             }
 
-			if (seq[index] is Asn1TaggedObject)
+			if (seq[index] is Asn1TaggedObject taggedObject)
             {
-                requestorName = GeneralName.GetInstance((Asn1TaggedObject) seq[index++], true);
+                index++;
+                requestorName = GeneralName.GetInstance(taggedObject, true);
             }
 
 			requestList = (Asn1Sequence) seq[index++];
diff --git a/crypto/src/asn1/x509/AttCertIssuer.cs b/crypto/src/asn1/x509/AttCertIssuer.cs
index 407c4ae7a..9d74f631e 100644
--- a/crypto/src/asn1/x509/AttCertIssuer.cs
+++ b/crypto/src/asn1/x509/AttCertIssuer.cs
@@ -10,34 +10,33 @@ namespace Org.BouncyCastle.Asn1.X509
         internal readonly Asn1Encodable	obj;
         internal readonly Asn1Object	choiceObj;
 
-		public static AttCertIssuer GetInstance(
-			object obj)
-		{
-			if (obj is AttCertIssuer)
-			{
-				return (AttCertIssuer)obj;
-			}
-			else if (obj is V2Form)
-			{
-				return new AttCertIssuer(V2Form.GetInstance(obj));
-			}
-			else if (obj is GeneralNames)
-			{
-				return new AttCertIssuer((GeneralNames)obj);
-			}
-			else if (obj is Asn1TaggedObject)
-			{
-				return new AttCertIssuer(V2Form.GetInstance((Asn1TaggedObject)obj, false));
-			}
-			else if (obj is Asn1Sequence)
-			{
-				return new AttCertIssuer(GeneralNames.GetInstance(obj));
-			}
+        public static AttCertIssuer GetInstance(object obj)
+        {
+            if (obj is AttCertIssuer attrCertIssuer)
+            {
+                return attrCertIssuer;
+            }
+            else if (obj is V2Form v2Form)
+            {
+                return new AttCertIssuer(v2Form);
+            }
+            else if (obj is GeneralNames generalNames)
+            {
+                return new AttCertIssuer(generalNames);
+            }
+            else if (obj is Asn1TaggedObject taggedObject)
+            {
+                return new AttCertIssuer(V2Form.GetInstance(taggedObject, false));
+            }
+            else if (obj is Asn1Sequence)
+            {
+                return new AttCertIssuer(GeneralNames.GetInstance(obj));
+            }
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
-		}
+        }
 
-		public static AttCertIssuer GetInstance(
+        public static AttCertIssuer GetInstance(
 			Asn1TaggedObject	obj,
 			bool				isExplicit)
 		{
diff --git a/crypto/src/asn1/x509/Holder.cs b/crypto/src/asn1/x509/Holder.cs
index 90df75a0f..3da57f70f 100644
--- a/crypto/src/asn1/x509/Holder.cs
+++ b/crypto/src/asn1/x509/Holder.cs
@@ -42,33 +42,26 @@ namespace Org.BouncyCastle.Asn1.X509
         internal readonly ObjectDigestInfo	objectDigestInfo;
 		private readonly int version;
 
-		public static Holder GetInstance(
-            object obj)
+        public static Holder GetInstance(object obj)
         {
-            if (obj is Holder)
-            {
-                return (Holder) obj;
-            }
+            if (obj is Holder holder)
+                return holder;
 
-			if (obj is Asn1Sequence)
-            {
-                return new Holder((Asn1Sequence) obj);
-            }
+            if (obj is Asn1Sequence sequence)
+                return new Holder(sequence);
 
-			if (obj is Asn1TaggedObject)
-			{
-				return new Holder((Asn1TaggedObject) obj);
-			}
+            if (obj is Asn1TaggedObject taggedObject)
+                return new Holder(taggedObject);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
-		}
+        }
 
-		/**
+        /**
 		 * Constructor for a holder for an v1 attribute certificate.
 		 * 
 		 * @param tagObj The ASN.1 tagged holder object.
 		 */
-		public Holder(
+        public Holder(
 			Asn1TaggedObject tagObj)
 		{
 			switch (tagObj.TagNo)
diff --git a/crypto/src/asn1/x509/IetfAttrSyntax.cs b/crypto/src/asn1/x509/IetfAttrSyntax.cs
index 024c8dd68..a59877163 100644
--- a/crypto/src/asn1/x509/IetfAttrSyntax.cs
+++ b/crypto/src/asn1/x509/IetfAttrSyntax.cs
@@ -25,9 +25,9 @@ namespace Org.BouncyCastle.Asn1.X509
         {
             int i = 0;
 
-            if (seq[0] is Asn1TaggedObject)
+            if (seq[0] is Asn1TaggedObject taggedObject)
             {
-                policyAuthority = GeneralNames.GetInstance(((Asn1TaggedObject)seq[0]), false);
+                policyAuthority = GeneralNames.GetInstance(taggedObject, false);
                 i++;
             }
             else if (seq.Count == 2)
diff --git a/crypto/src/asn1/x509/Target.cs b/crypto/src/asn1/x509/Target.cs
index 7c4f9db7e..eff740143 100644
--- a/crypto/src/asn1/x509/Target.cs
+++ b/crypto/src/asn1/x509/Target.cs
@@ -32,7 +32,7 @@ namespace Org.BouncyCastle.Asn1.X509
 		private readonly GeneralName targetName;
 		private readonly GeneralName targetGroup;
 
-		/**
+        /**
 		* Creates an instance of a Target from the given object.
 		* <p>
 		* <code>obj</code> can be a Target or a {@link Asn1TaggedObject}</p>
@@ -42,29 +42,24 @@ namespace Org.BouncyCastle.Asn1.X509
 		* @throws ArgumentException if the given object cannot be
 		*             interpreted as Target.
 		*/
-		public static Target GetInstance(
-			object obj)
-		{
-			if (obj is Target)
-			{
-				return (Target) obj;
-			}
+        public static Target GetInstance(object obj)
+        {
+            if (obj is Target target)
+                return target;
 
-			if (obj is Asn1TaggedObject)
-			{
-				return new Target((Asn1TaggedObject) obj);
-			}
+            if (obj is Asn1TaggedObject taggedObject)
+                return new Target(taggedObject);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
-		}
+        }
 
-		/**
+        /**
 		 * Constructor from Asn1TaggedObject.
 		 * 
 		 * @param tagObj The tagged object.
 		 * @throws ArgumentException if the encoding is wrong.
 		 */
-		private Target(
+        private Target(
 			Asn1TaggedObject tagObj)
 		{
 			switch ((Choice) tagObj.TagNo)
diff --git a/crypto/src/asn1/x509/X509Extensions.cs b/crypto/src/asn1/x509/X509Extensions.cs
index 62291a829..390bf46b7 100644
--- a/crypto/src/asn1/x509/X509Extensions.cs
+++ b/crypto/src/asn1/x509/X509Extensions.cs
@@ -203,28 +203,24 @@ namespace Org.BouncyCastle.Asn1.X509
             return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
-		public static X509Extensions GetInstance(
-            object obj)
+        public static X509Extensions GetInstance(object obj)
         {
-            if (obj == null || obj is X509Extensions)
-            {
-                return (X509Extensions) obj;
-            }
+            if (obj == null)
+                return null;
 
-			if (obj is Asn1Sequence)
-            {
-                return new X509Extensions((Asn1Sequence) obj);
-            }
+            if (obj is X509Extensions x509Extensions)
+                return x509Extensions;
 
-			if (obj is Asn1TaggedObject)
-            {
-                return GetInstance(((Asn1TaggedObject) obj).GetObject());
-            }
+            if (obj is Asn1Sequence sequence)
+                return new X509Extensions(sequence);
+
+            if (obj is Asn1TaggedObject taggedObject)
+                return GetInstance(taggedObject.GetObject());
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
-		}
+        }
 
-		/**
+        /**
          * Constructor from Asn1Sequence.
          *
          * the extensions are a list of constructed sequences, either with (Oid, OctetString) or (Oid, Boolean, OctetString)