summary refs log tree commit diff
path: root/crypto/src/asn1/pkcs/Attribute.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/pkcs/Attribute.cs')
-rw-r--r--crypto/src/asn1/pkcs/Attribute.cs73
1 files changed, 25 insertions, 48 deletions
diff --git a/crypto/src/asn1/pkcs/Attribute.cs b/crypto/src/asn1/pkcs/Attribute.cs
index 185828596..3bd4aa4e5 100644
--- a/crypto/src/asn1/pkcs/Attribute.cs
+++ b/crypto/src/asn1/pkcs/Attribute.cs
@@ -1,66 +1,46 @@
 using System;
 
-using Org.BouncyCastle.Utilities;
-
 namespace Org.BouncyCastle.Asn1.Pkcs
 {
     public class AttributePkcs
         : Asn1Encodable
     {
-        private readonly DerObjectIdentifier attrType;
-        private readonly Asn1Set attrValues;
-
-		/**
-         * return an Attribute object from the given object.
-         *
-         * @param o the object we want converted.
-         * @exception ArgumentException if the object cannot be converted.
-         */
-        public static AttributePkcs GetInstance(
-            object obj)
+        public static AttributePkcs GetInstance(object obj)
         {
-            AttributePkcs attr = obj as AttributePkcs;
-            if (obj == null || attr != null)
-            {
-                return attr;
-            }
+            if (obj == null)
+                return null;
+            if (obj is AttributePkcs attributePkcs)
+                return attributePkcs;
+            return new AttributePkcs(Asn1Sequence.GetInstance(obj));
+		}
 
-			Asn1Sequence seq = obj as Asn1Sequence;
-            if (seq != null)
-            {
-                return new AttributePkcs(seq);
-            }
+        public static AttributePkcs GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return new AttributePkcs(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
 
-			throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj");
-		}
+        private readonly DerObjectIdentifier m_attrType;
+        private readonly Asn1Set m_attrValues;
 
-		private AttributePkcs(
-            Asn1Sequence seq)
+        private AttributePkcs(Asn1Sequence seq)
         {
-			if (seq.Count != 2)
-				throw new ArgumentException("Wrong number of elements in sequence", "seq");
+            int count = seq.Count;
+            if (count != 2)
+                throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
 
-			attrType = DerObjectIdentifier.GetInstance(seq[0]);
-            attrValues = Asn1Set.GetInstance(seq[1]);
+			m_attrType = DerObjectIdentifier.GetInstance(seq[0]);
+            m_attrValues = Asn1Set.GetInstance(seq[1]);
         }
 
-		public AttributePkcs(
-            DerObjectIdentifier	attrType,
-            Asn1Set				attrValues)
+		public AttributePkcs(DerObjectIdentifier attrType, Asn1Set attrValues)
         {
-            this.attrType = attrType;
-            this.attrValues = attrValues;
+            m_attrType = attrType ?? throw new ArgumentNullException(nameof(attrType));
+            m_attrValues = attrValues ?? throw new ArgumentNullException(nameof(attrValues));
         }
 
-		public DerObjectIdentifier AttrType
-		{
-			get { return attrType; }
-		}
+        public DerObjectIdentifier AttrType => m_attrType;
 
-		public Asn1Set AttrValues
-		{
-			get { return attrValues; }
-		}
+        public Asn1Set AttrValues => m_attrValues;
 
 		/**
          * Produce an object suitable for an Asn1OutputStream.
@@ -71,9 +51,6 @@ namespace Org.BouncyCastle.Asn1.Pkcs
          * }
          * </pre>
          */
-        public override Asn1Object ToAsn1Object()
-        {
-			return new DerSequence(attrType, attrValues);
-        }
+        public override Asn1Object ToAsn1Object() => new DerSequence(m_attrType, m_attrValues);
     }
 }