summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/asn1/cms/RecipientIdentifier.cs80
1 files changed, 33 insertions, 47 deletions
diff --git a/crypto/src/asn1/cms/RecipientIdentifier.cs b/crypto/src/asn1/cms/RecipientIdentifier.cs
index f29fa8d7c..22ac76340 100644
--- a/crypto/src/asn1/cms/RecipientIdentifier.cs
+++ b/crypto/src/asn1/cms/RecipientIdentifier.cs
@@ -7,70 +7,59 @@ namespace Org.BouncyCastle.Asn1.Cms
     public class RecipientIdentifier
         : Asn1Encodable, IAsn1Choice
     {
-        private Asn1Encodable id;
-
-		public RecipientIdentifier(
-            IssuerAndSerialNumber id)
-        {
-            this.id = id;
-        }
-
-		public RecipientIdentifier(
-            Asn1OctetString id)
-        {
-            this.id = new DerTaggedObject(false, 0, id);
-        }
-
-		public RecipientIdentifier(
-            Asn1Object id)
-        {
-            this.id = id;
-        }
-
-		/**
+        /**
          * return a RecipientIdentifier object from the given object.
          *
          * @param o the object we want converted.
          * @exception ArgumentException if the object cannot be converted.
          */
-        public static RecipientIdentifier GetInstance(
-            object o)
+        public static RecipientIdentifier GetInstance(object o)
         {
-            if (o == null || o is RecipientIdentifier)
-                return (RecipientIdentifier)o;
+            if (o == null)
+                return null;
+            if (o is RecipientIdentifier recipientIdentifier)
+                return recipientIdentifier;
+            if (o is IssuerAndSerialNumber issuerAndSerialNumber)
+                return new RecipientIdentifier(issuerAndSerialNumber);
+            if (o is Asn1OctetString asn1OctetString)
+                return new RecipientIdentifier(asn1OctetString);
+            if (o is Asn1Object asn1Object)
+                return new RecipientIdentifier(asn1Object);
 
-			if (o is IssuerAndSerialNumber)
-                return new RecipientIdentifier((IssuerAndSerialNumber) o);
+            throw new ArgumentException("Illegal object in RecipientIdentifier: " + Platform.GetTypeName(o));
+        }
 
-			if (o is Asn1OctetString)
-                return new RecipientIdentifier((Asn1OctetString) o);
+        private readonly Asn1Encodable m_id;
 
-			if (o is Asn1Object)
-                return new RecipientIdentifier((Asn1Object) o);
+		public RecipientIdentifier(IssuerAndSerialNumber id)
+        {
+            m_id = id;
+        }
 
-			throw new ArgumentException(
-              "Illegal object in RecipientIdentifier: " + Platform.GetTypeName(o));
+		public RecipientIdentifier(Asn1OctetString id)
+        {
+            m_id = new DerTaggedObject(false, 0, id);
         }
 
-		public bool IsTagged
-		{
-			get { return (id is Asn1TaggedObject); }
-		}
+		public RecipientIdentifier(Asn1Object id)
+        {
+            m_id = id;
+        }
+
+        public bool IsTagged => m_id is Asn1TaggedObject;
 
 		public Asn1Encodable ID
         {
             get
             {
-                if (id is Asn1TaggedObject)
-                {
-                    return Asn1OctetString.GetInstance((Asn1TaggedObject) id, false);
-                }
+                if (m_id is Asn1TaggedObject taggedObject)
+                    return Asn1OctetString.GetInstance(taggedObject, false);
 
-				return IssuerAndSerialNumber.GetInstance(id);
+				return IssuerAndSerialNumber.GetInstance(m_id);
             }
         }
 
-		/**
+        /**
          * Produce an object suitable for an Asn1OutputStream.
          * <pre>
          * RecipientIdentifier ::= CHOICE {
@@ -81,9 +70,6 @@ namespace Org.BouncyCastle.Asn1.Cms
          * SubjectKeyIdentifier ::= OCTET STRING
          * </pre>
          */
-        public override Asn1Object ToAsn1Object()
-        {
-            return id.ToAsn1Object();
-        }
+        public override Asn1Object ToAsn1Object() => m_id.ToAsn1Object();
     }
 }