summary refs log tree commit diff
path: root/crypto/src/asn1/cms
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cms')
-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
6 files changed, 57 insertions, 64 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 {