summary refs log tree commit diff
path: root/crypto/src/asn1/x509/AlgorithmIdentifier.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/x509/AlgorithmIdentifier.cs')
-rw-r--r--crypto/src/asn1/x509/AlgorithmIdentifier.cs64
1 files changed, 20 insertions, 44 deletions
diff --git a/crypto/src/asn1/x509/AlgorithmIdentifier.cs b/crypto/src/asn1/x509/AlgorithmIdentifier.cs
index c6f4af5bf..00e7ad8bc 100644
--- a/crypto/src/asn1/x509/AlgorithmIdentifier.cs
+++ b/crypto/src/asn1/x509/AlgorithmIdentifier.cs
@@ -5,9 +5,8 @@ namespace Org.BouncyCastle.Asn1.X509
     public class AlgorithmIdentifier
         : Asn1Encodable
     {
-        private readonly DerObjectIdentifier	objectID;
+        private readonly DerObjectIdentifier	algorithm;
         private readonly Asn1Encodable			parameters;
-        private readonly bool					parametersDefined;
 
         public static AlgorithmIdentifier GetInstance(
             Asn1TaggedObject	obj,
@@ -19,39 +18,32 @@ namespace Org.BouncyCastle.Asn1.X509
         public static AlgorithmIdentifier GetInstance(
             object obj)
         {
-            if (obj == null || obj is AlgorithmIdentifier)
-                return (AlgorithmIdentifier) obj;
-
-            // TODO: delete
-            if (obj is DerObjectIdentifier)
-                return new AlgorithmIdentifier((DerObjectIdentifier) obj);
-
-            // TODO: delete
-            if (obj is string)
-                return new AlgorithmIdentifier((string) obj);
-
+            if (obj == null)
+                return null;
+            if (obj is AlgorithmIdentifier)
+                return (AlgorithmIdentifier)obj;
             return new AlgorithmIdentifier(Asn1Sequence.GetInstance(obj));
         }
 
         public AlgorithmIdentifier(
-            DerObjectIdentifier objectID)
+            DerObjectIdentifier algorithm)
         {
-            this.objectID = objectID;
+            this.algorithm = algorithm;
         }
 
+        [Obsolete("Use version taking a DerObjectIdentifier")]
         public AlgorithmIdentifier(
-            string objectID)
+            string algorithm)
         {
-            this.objectID = new DerObjectIdentifier(objectID);
+            this.algorithm = new DerObjectIdentifier(algorithm);
         }
 
         public AlgorithmIdentifier(
-            DerObjectIdentifier	objectID,
+            DerObjectIdentifier algorithm,
             Asn1Encodable		parameters)
         {
-            this.objectID = objectID;
+            this.algorithm = algorithm;
             this.parameters = parameters;
-            this.parametersDefined = true;
         }
 
         internal AlgorithmIdentifier(
@@ -60,13 +52,8 @@ namespace Org.BouncyCastle.Asn1.X509
             if (seq.Count < 1 || seq.Count > 2)
                 throw new ArgumentException("Bad sequence size: " + seq.Count);
 
-            this.objectID = DerObjectIdentifier.GetInstance(seq[0]);
-            this.parametersDefined = (seq.Count == 2);
-
-            if (parametersDefined)
-            {
-                this.parameters = seq[1];
-            }
+            this.algorithm = DerObjectIdentifier.GetInstance(seq[0]);
+            this.parameters = seq.Count < 2 ? null : seq[1];
         }
 
         /// <summary>
@@ -74,18 +61,19 @@ namespace Org.BouncyCastle.Asn1.X509
         /// </summary>
 		public virtual DerObjectIdentifier Algorithm
 		{
-			get { return objectID; }
+			get { return algorithm; }
 		}
 
+        [Obsolete("Use 'Algorithm' property instead")]
         public virtual DerObjectIdentifier ObjectID
         {
-            get { return objectID; }
+            get { return algorithm; }
         }
 
         /// <summary>
         /// Return the parameters structure in the Parameters entry of this identifier.
         /// </summary>
-        public Asn1Encodable Parameters
+        public virtual Asn1Encodable Parameters
         {
             get { return parameters; }
         }
@@ -100,20 +88,8 @@ namespace Org.BouncyCastle.Asn1.X509
          */
         public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector(objectID);
-
-            if (parametersDefined)
-            {
-                if (parameters != null)
-                {
-                    v.Add(parameters);
-                }
-                else
-                {
-                    v.Add(DerNull.Instance);
-                }
-            }
-
+            Asn1EncodableVector v = new Asn1EncodableVector(algorithm);
+            v.AddOptional(parameters);
             return new DerSequence(v);
         }
     }