summary refs log tree commit diff
path: root/crypto/src/asn1/cms
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/cms
parentObsolete unused segmentLimit (diff)
downloadBouncyCastle.NET-ed25519-8ed01d5f6322defa0b3dbb1e149b05736f54f832.tar.xz
Refactoring in Asn1 classes
Diffstat (limited to 'crypto/src/asn1/cms')
-rw-r--r--crypto/src/asn1/cms/AuthEnvelopedData.cs11
-rw-r--r--crypto/src/asn1/cms/AuthenticatedData.cs15
-rw-r--r--crypto/src/asn1/cms/EnvelopedData.cs6
-rw-r--r--crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs17
-rw-r--r--crypto/src/asn1/cms/MetaData.cs14
-rw-r--r--crypto/src/asn1/cms/PasswordRecipientInfo.cs13
-rw-r--r--crypto/src/asn1/cms/RecipientKeyIdentifier.cs34
-rw-r--r--crypto/src/asn1/cms/SCVPReqRes.cs4
-rw-r--r--crypto/src/asn1/cms/TimeStampedData.cs10
9 files changed, 61 insertions, 63 deletions
diff --git a/crypto/src/asn1/cms/AuthEnvelopedData.cs b/crypto/src/asn1/cms/AuthEnvelopedData.cs
index 4ca86e9df..8f980e6ec 100644
--- a/crypto/src/asn1/cms/AuthEnvelopedData.cs
+++ b/crypto/src/asn1/cms/AuthEnvelopedData.cs
@@ -49,8 +49,7 @@ namespace Org.BouncyCastle.Asn1.Cms
 			this.unauthAttrs = unauthAttrs;
 	    }
 
-		private AuthEnvelopedData(
-			Asn1Sequence	seq)
+		private AuthEnvelopedData(Asn1Sequence seq)
 		{
 			int index = 0;
 
@@ -61,9 +60,9 @@ namespace Org.BouncyCastle.Asn1.Cms
 				throw new ArgumentException("AuthEnvelopedData version number must be 0");
 
 			tmp = seq[index++].ToAsn1Object();
-			if (tmp is Asn1TaggedObject)
+			if (tmp is Asn1TaggedObject taggedObject1)
 			{
-				originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
+				originatorInfo = OriginatorInfo.GetInstance(taggedObject1, false);
 				tmp = seq[index++].ToAsn1Object();
 			}
 
@@ -76,9 +75,9 @@ namespace Org.BouncyCastle.Asn1.Cms
 			authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp);
 
 			tmp = seq[index++].ToAsn1Object();
-			if (tmp is Asn1TaggedObject)
+			if (tmp is Asn1TaggedObject taggedObject2)
 			{
-				authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
+				authAttrs = Asn1Set.GetInstance(taggedObject2, false);
 				tmp = seq[index++].ToAsn1Object();
 			}
 			else
diff --git a/crypto/src/asn1/cms/AuthenticatedData.cs b/crypto/src/asn1/cms/AuthenticatedData.cs
index eb9f82031..6ec8061e2 100644
--- a/crypto/src/asn1/cms/AuthenticatedData.cs
+++ b/crypto/src/asn1/cms/AuthenticatedData.cs
@@ -48,17 +48,16 @@ namespace Org.BouncyCastle.Asn1.Cms
 			this.unauthAttrs = unauthAttrs;
 		}
 
-		private AuthenticatedData(
-			Asn1Sequence	seq)
+		private AuthenticatedData(Asn1Sequence seq)
 		{
 			int index = 0;
 
 			version = (DerInteger)seq[index++];
 
 			Asn1Encodable tmp = seq[index++];
-			if (tmp is Asn1TaggedObject)
+			if (tmp is Asn1TaggedObject taggedObject1)
 			{
-				originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
+				originatorInfo = OriginatorInfo.GetInstance(taggedObject1, false);
 				tmp = seq[index++];
 			}
 
@@ -66,18 +65,18 @@ namespace Org.BouncyCastle.Asn1.Cms
 			macAlgorithm = AlgorithmIdentifier.GetInstance(seq[index++]);
 
 			tmp = seq[index++];
-			if (tmp is Asn1TaggedObject)
+			if (tmp is Asn1TaggedObject taggedObject2)
 			{
-				digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)tmp, false);
+				digestAlgorithm = AlgorithmIdentifier.GetInstance(taggedObject2, false);
 				tmp = seq[index++];
 			}
 
 			encapsulatedContentInfo = ContentInfo.GetInstance(tmp);
 
 			tmp = seq[index++];
-			if (tmp is Asn1TaggedObject)
+			if (tmp is Asn1TaggedObject taggedObject3)
 			{
-				authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
+				authAttrs = Asn1Set.GetInstance(taggedObject3, false);
 				tmp = seq[index++];
 			}
 
diff --git a/crypto/src/asn1/cms/EnvelopedData.cs b/crypto/src/asn1/cms/EnvelopedData.cs
index 45e9c5c76..85216a2e8 100644
--- a/crypto/src/asn1/cms/EnvelopedData.cs
+++ b/crypto/src/asn1/cms/EnvelopedData.cs
@@ -45,9 +45,9 @@ namespace Org.BouncyCastle.Asn1.Cms
 
             object tmp = seq[index++];
 
-            if (tmp is Asn1TaggedObject)
+            if (tmp is Asn1TaggedObject taggedObject)
             {
-                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject) tmp, false);
+                originatorInfo = OriginatorInfo.GetInstance(taggedObject, false);
                 tmp = seq[index++];
             }
 
@@ -56,7 +56,7 @@ namespace Org.BouncyCastle.Asn1.Cms
 
             if (seq.Count > index)
             {
-                unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject) seq[index], false);
+                unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
             }
         }
 
diff --git a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs
index 52eb7d4d3..be2d76e2c 100644
--- a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs
+++ b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs
@@ -27,25 +27,22 @@ namespace Org.BouncyCastle.Asn1.Cms
             this.recipientEncryptedKeys = recipientEncryptedKeys;
         }
 
-		public KeyAgreeRecipientInfo(
-            Asn1Sequence seq)
+		public KeyAgreeRecipientInfo(Asn1Sequence seq)
         {
             int index = 0;
 
             version = (DerInteger) seq[index++];
-            originator = OriginatorIdentifierOrKey.GetInstance(
-				(Asn1TaggedObject) seq[index++], true);
+            originator = OriginatorIdentifierOrKey.GetInstance((Asn1TaggedObject)seq[index++], true);
 
-			if (seq[index] is Asn1TaggedObject)
+			if (seq[index] is Asn1TaggedObject taggedObject)
             {
-                ukm = Asn1OctetString.GetInstance(
-					(Asn1TaggedObject) seq[index++], true);
+                ukm = Asn1OctetString.GetInstance(taggedObject, true);
+                ++index;
             }
 
-			keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(
-				seq[index++]);
+			keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[index++]);
 
-			recipientEncryptedKeys = (Asn1Sequence) seq[index++];
+			recipientEncryptedKeys = (Asn1Sequence)seq[index++];
         }
 
 		/**
diff --git a/crypto/src/asn1/cms/MetaData.cs b/crypto/src/asn1/cms/MetaData.cs
index ad2b5c426..6435d4d2e 100644
--- a/crypto/src/asn1/cms/MetaData.cs
+++ b/crypto/src/asn1/cms/MetaData.cs
@@ -28,15 +28,17 @@ namespace Org.BouncyCastle.Asn1.Cms
 
 			int index = 1;
 
-			if (index < seq.Count && seq[index] is DerUtf8String)
+			if (index < seq.Count && seq[index] is DerUtf8String utf8)
 			{
-				this.fileName = DerUtf8String.GetInstance(seq[index++]);
+				this.fileName = utf8;
+				++index;
 			}
-			if (index < seq.Count && seq[index] is DerIA5String)
+			if (index < seq.Count && seq[index] is DerIA5String ia5)
 			{
-				this.mediaType = DerIA5String.GetInstance(seq[index++]);
-			}
-			if (index < seq.Count)
+				this.mediaType = ia5;
+                ++index;
+            }
+            if (index < seq.Count)
 			{
 				this.otherMetaData = Attributes.GetInstance(seq[index++]);
 			}
diff --git a/crypto/src/asn1/cms/PasswordRecipientInfo.cs b/crypto/src/asn1/cms/PasswordRecipientInfo.cs
index 596dd9537..9fb639bf3 100644
--- a/crypto/src/asn1/cms/PasswordRecipientInfo.cs
+++ b/crypto/src/asn1/cms/PasswordRecipientInfo.cs
@@ -33,21 +33,20 @@ namespace Org.BouncyCastle.Asn1.Cms
 			this.encryptedKey = encryptedKey;
 		}
 
-		public PasswordRecipientInfo(
-            Asn1Sequence seq)
+		public PasswordRecipientInfo(Asn1Sequence seq)
         {
-            version = (DerInteger) seq[0];
+            version = (DerInteger)seq[0];
 
-			if (seq[1] is Asn1TaggedObject)
+			if (seq[1] is Asn1TaggedObject taggedObject)
             {
-                keyDerivationAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject) seq[1], false);
+                keyDerivationAlgorithm = AlgorithmIdentifier.GetInstance(taggedObject, false);
                 keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[2]);
-                encryptedKey = (Asn1OctetString) seq[3];
+                encryptedKey = (Asn1OctetString)seq[3];
             }
             else
             {
                 keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
-                encryptedKey = (Asn1OctetString) seq[2];
+                encryptedKey = (Asn1OctetString)seq[2];
             }
         }
 
diff --git a/crypto/src/asn1/cms/RecipientKeyIdentifier.cs b/crypto/src/asn1/cms/RecipientKeyIdentifier.cs
index 512025808..60a6151bf 100644
--- a/crypto/src/asn1/cms/RecipientKeyIdentifier.cs
+++ b/crypto/src/asn1/cms/RecipientKeyIdentifier.cs
@@ -43,24 +43,24 @@ namespace Org.BouncyCastle.Asn1.Cms
 
 			switch(seq.Count)
             {
-				case 1:
-					break;
-				case 2:
-					if (seq[1] is Asn1GeneralizedTime asn1GeneralizedTime)
-					{
-						date = asn1GeneralizedTime;
-					}
-					else
-					{
-						other = OtherKeyAttribute.GetInstance(seq[2]);
-					}
-					break;
-				case 3:
-					date = (Asn1GeneralizedTime)seq[1];
+			case 1:
+				break;
+			case 2:
+				if (seq[1] is Asn1GeneralizedTime asn1GeneralizedTime)
+				{
+					date = asn1GeneralizedTime;
+				}
+				else
+				{
 					other = OtherKeyAttribute.GetInstance(seq[2]);
-					break;
-				default:
-					throw new ArgumentException("Invalid RecipientKeyIdentifier");
+				}
+				break;
+			case 3:
+				date = (Asn1GeneralizedTime)seq[1];
+				other = OtherKeyAttribute.GetInstance(seq[2]);
+				break;
+			default:
+				throw new ArgumentException("Invalid RecipientKeyIdentifier");
             }
         }
 
diff --git a/crypto/src/asn1/cms/SCVPReqRes.cs b/crypto/src/asn1/cms/SCVPReqRes.cs
index 6544c852b..8b5f858a6 100644
--- a/crypto/src/asn1/cms/SCVPReqRes.cs
+++ b/crypto/src/asn1/cms/SCVPReqRes.cs
@@ -19,9 +19,9 @@ namespace Org.BouncyCastle.Asn1.Cms
 
         private ScvpReqRes(Asn1Sequence seq)
         {
-            if (seq[0] is Asn1TaggedObject)
+            if (seq[0] is Asn1TaggedObject taggedObject)
             {
-                this.request = ContentInfo.GetInstance(Asn1TaggedObject.GetInstance(seq[0]), true);
+                this.request = ContentInfo.GetInstance(taggedObject, true);
                 this.response = ContentInfo.GetInstance(seq[1]);
             }
             else
diff --git a/crypto/src/asn1/cms/TimeStampedData.cs b/crypto/src/asn1/cms/TimeStampedData.cs
index 15448a923..f90e5b086 100644
--- a/crypto/src/asn1/cms/TimeStampedData.cs
+++ b/crypto/src/asn1/cms/TimeStampedData.cs
@@ -26,17 +26,19 @@ namespace Org.BouncyCastle.Asn1.Cms
 			this.version = DerInteger.GetInstance(seq[0]);
 			
 			int index = 1;
-			if (seq[index] is DerIA5String)
+			if (seq[index] is DerIA5String ia5)
 			{
-				this.dataUri = DerIA5String.GetInstance(seq[index++]);
+				this.dataUri = ia5;
+				++index;
 			}
 			if (seq[index] is MetaData || seq[index] is Asn1Sequence)
 			{
 				this.metaData = MetaData.GetInstance(seq[index++]);
 			}
-			if (seq[index] is Asn1OctetString)
+			if (seq[index] is Asn1OctetString octets)
 			{
-				this.content = Asn1OctetString.GetInstance(seq[index++]);
+				this.content = octets;
+				++index;
 			}
 			this.temporalEvidence = Evidence.GetInstance(seq[index]);
 		}