summary refs log tree commit diff
path: root/crypto/src/asn1/x509
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-03-11 23:36:32 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-03-11 23:36:32 +0700
commit8ed01d5f6322defa0b3dbb1e149b05736f54f832 (patch)
treefde48f03f14134ecd9b9ece814309bda07e85371 /crypto/src/asn1/x509
parentObsolete unused segmentLimit (diff)
downloadBouncyCastle.NET-ed25519-8ed01d5f6322defa0b3dbb1e149b05736f54f832.tar.xz
Refactoring in Asn1 classes
Diffstat (limited to 'crypto/src/asn1/x509')
-rw-r--r--crypto/src/asn1/x509/AttributeCertificateInfo.cs6
-rw-r--r--crypto/src/asn1/x509/BasicConstraints.cs4
-rw-r--r--crypto/src/asn1/x509/NoticeReference.cs9
-rw-r--r--crypto/src/asn1/x509/TBSCertList.cs10
-rw-r--r--crypto/src/asn1/x509/TBSCertificateStructure.cs6
5 files changed, 13 insertions, 22 deletions
diff --git a/crypto/src/asn1/x509/AttributeCertificateInfo.cs b/crypto/src/asn1/x509/AttributeCertificateInfo.cs
index d466bbd14..dde432ee6 100644
--- a/crypto/src/asn1/x509/AttributeCertificateInfo.cs
+++ b/crypto/src/asn1/x509/AttributeCertificateInfo.cs
@@ -69,11 +69,11 @@ namespace Org.BouncyCastle.Asn1.X509
 
 			for (int i = start + 6; i < seq.Count; i++)
             {
-                Asn1Encodable obj = (Asn1Encodable) seq[i];
+                Asn1Encodable obj = seq[i];
 
-				if (obj is DerBitString)
+				if (obj is DerBitString bitString)
                 {
-                    this.issuerUniqueID = DerBitString.GetInstance(seq[i]);
+                    this.issuerUniqueID = bitString;
                 }
                 else if (obj is Asn1Sequence || obj is X509Extensions)
                 {
diff --git a/crypto/src/asn1/x509/BasicConstraints.cs b/crypto/src/asn1/x509/BasicConstraints.cs
index deecae241..acc8766a7 100644
--- a/crypto/src/asn1/x509/BasicConstraints.cs
+++ b/crypto/src/asn1/x509/BasicConstraints.cs
@@ -37,9 +37,9 @@ namespace Org.BouncyCastle.Asn1.X509
         {
 			if (seq.Count > 0)
 			{
-				if (seq[0] is DerBoolean)
+				if (seq[0] is DerBoolean derBoolean)
 				{
-					this.cA = DerBoolean.GetInstance(seq[0]);
+					this.cA = derBoolean;
 				}
 				else
 				{
diff --git a/crypto/src/asn1/x509/NoticeReference.cs b/crypto/src/asn1/x509/NoticeReference.cs
index 2fb275d8f..22bb35b71 100644
--- a/crypto/src/asn1/x509/NoticeReference.cs
+++ b/crypto/src/asn1/x509/NoticeReference.cs
@@ -120,14 +120,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
         public virtual DerInteger[] GetNoticeNumbers()
         {
-            DerInteger[] tmp = new DerInteger[noticeNumbers.Count];
-
-            for (int i = 0; i != noticeNumbers.Count; ++i)
-            {
-                tmp[i] = DerInteger.GetInstance(noticeNumbers[i]);
-            }
-
-            return tmp;
+            return noticeNumbers.MapElements(DerInteger.GetInstance);
         }
 
         /**
diff --git a/crypto/src/asn1/x509/TBSCertList.cs b/crypto/src/asn1/x509/TBSCertList.cs
index 009773e79..4cfb44c90 100644
--- a/crypto/src/asn1/x509/TBSCertList.cs
+++ b/crypto/src/asn1/x509/TBSCertList.cs
@@ -169,21 +169,19 @@ namespace Org.BouncyCastle.Asn1.X509
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
         }
 
-		internal TbsCertificateList(
-            Asn1Sequence seq)
+		internal TbsCertificateList(Asn1Sequence seq)
         {
 			if (seq.Count < 3 || seq.Count > 7)
-			{
 				throw new ArgumentException("Bad sequence size: " + seq.Count);
-			}
 
 			int seqPos = 0;
 
 			this.seq = seq;
 
-			if (seq[seqPos] is DerInteger)
+			if (seq[seqPos] is DerInteger derInteger)
             {
-				version = DerInteger.GetInstance(seq[seqPos++]);
+				version = derInteger;
+				++seqPos;
 			}
             else
             {
diff --git a/crypto/src/asn1/x509/TBSCertificateStructure.cs b/crypto/src/asn1/x509/TBSCertificateStructure.cs
index 5e3bf2601..e1fba2488 100644
--- a/crypto/src/asn1/x509/TBSCertificateStructure.cs
+++ b/crypto/src/asn1/x509/TBSCertificateStructure.cs
@@ -66,11 +66,11 @@ namespace Org.BouncyCastle.Asn1.X509
 			this.seq = seq;
 
 			//
-			// some certficates don't include a version number - we assume v1
+			// some certificates don't include a version number - we assume v1
 			//
-			if (seq[0] is Asn1TaggedObject)
+			if (seq[0] is Asn1TaggedObject taggedObject)
 			{
-				version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], true);
+				version = DerInteger.GetInstance(taggedObject, true);
 			}
 			else
 			{