summary refs log tree commit diff
path: root/crypto/src/asn1/cms/KeyAgreeRecipientIdentifier.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cms/KeyAgreeRecipientIdentifier.cs')
-rw-r--r--crypto/src/asn1/cms/KeyAgreeRecipientIdentifier.cs62
1 files changed, 25 insertions, 37 deletions
diff --git a/crypto/src/asn1/cms/KeyAgreeRecipientIdentifier.cs b/crypto/src/asn1/cms/KeyAgreeRecipientIdentifier.cs
index 0256c2dc2..9e6e3bd5a 100644
--- a/crypto/src/asn1/cms/KeyAgreeRecipientIdentifier.cs
+++ b/crypto/src/asn1/cms/KeyAgreeRecipientIdentifier.cs
@@ -4,48 +4,36 @@ using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Cms
 {
-	public class KeyAgreeRecipientIdentifier
+    public class KeyAgreeRecipientIdentifier
 		: Asn1Encodable, IAsn1Choice
 	{
-		/**
-		 * return an KeyAgreeRecipientIdentifier object from a tagged object.
-		 *
-		 * @param obj the tagged object holding the object we want.
-		 * @param isExplicit true if the object is meant to be explicitly
-		 *              tagged false otherwise.
-		 * @exception ArgumentException if the object held by the
-		 *          tagged object cannot be converted.
-		 */
-		public static KeyAgreeRecipientIdentifier GetInstance(
-			Asn1TaggedObject	obj,
-			bool				isExplicit)
-		{
-			return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
-		}
-    
-		/**
-		 * return an KeyAgreeRecipientIdentifier object from the given object.
-		 *
-		 * @param obj the object we want converted.
-		 * @exception ArgumentException if the object cannot be converted.
-		 */
-		public static KeyAgreeRecipientIdentifier GetInstance(
-			object obj)
-		{
-			if (obj == null || obj is KeyAgreeRecipientIdentifier)
-				return (KeyAgreeRecipientIdentifier)obj;
+        public static KeyAgreeRecipientIdentifier GetInstance(object obj)
+        {
+			if (obj == null)
+				return null;
 
-			if (obj is Asn1Sequence)
-				return new KeyAgreeRecipientIdentifier(IssuerAndSerialNumber.GetInstance(obj));
+			if (obj is KeyAgreeRecipientIdentifier keyAgreeRecipientIdentifier)
+				return keyAgreeRecipientIdentifier;
 
-			if (obj is Asn1TaggedObject && ((Asn1TaggedObject)obj).TagNo == 0)
-			{
-				return new KeyAgreeRecipientIdentifier(RecipientKeyIdentifier.GetInstance(
-					(Asn1TaggedObject)obj, false));
-			}
+			if (obj is IssuerAndSerialNumber issuerAndSerialNumber)
+				return new KeyAgreeRecipientIdentifier(issuerAndSerialNumber);
+
+            if (obj is Asn1Sequence sequence)
+                return new KeyAgreeRecipientIdentifier(IssuerAndSerialNumber.GetInstance(sequence));
+
+            if (obj is Asn1TaggedObject taggedObject)
+            {
+                if (taggedObject.HasContextTag(0))
+                    return new KeyAgreeRecipientIdentifier(RecipientKeyIdentifier.GetInstance(taggedObject, false));
+            }
 
-			throw new ArgumentException("Invalid KeyAgreeRecipientIdentifier: " + Platform.GetTypeName(obj), "obj");
-		} 
+			throw new ArgumentException("Invalid KeyAgreeRecipientIdentifier: " + Platform.GetTypeName(obj), nameof(obj));
+        }
+
+        public static KeyAgreeRecipientIdentifier GetInstance(Asn1TaggedObject obj, bool isExplicit)
+		{
+            return Asn1Utilities.GetInstanceFromChoice(obj, isExplicit, GetInstance);
+		}
 
 		private readonly IssuerAndSerialNumber issuerSerial;
 		private readonly RecipientKeyIdentifier rKeyID;