summary refs log tree commit diff
path: root/crypto/src/asn1/x509/V2Form.cs
diff options
context:
space:
mode:
authorOren Novotny <oren@novotny.org>2014-08-26 17:39:02 -0400
committerOren Novotny <oren@novotny.org>2014-08-26 17:39:02 -0400
commit6dbc12162af086bbcfbd583dcaa8144d049c7fcc (patch)
tree3cf9443720ad508eb5ff615130d57fc118cb7145 /crypto/src/asn1/x509/V2Form.cs
parentrename Crypto dir to crypto to match bc-git (diff)
parentRework the nonce-random initialisation and avoid GenerateSeed (diff)
downloadBouncyCastle.NET-ed25519-6dbc12162af086bbcfbd583dcaa8144d049c7fcc.tar.xz
Merge in bc-git to this repo
Diffstat (limited to 'crypto/src/asn1/x509/V2Form.cs')
-rw-r--r--crypto/src/asn1/x509/V2Form.cs84
1 files changed, 48 insertions, 36 deletions
diff --git a/crypto/src/asn1/x509/V2Form.cs b/crypto/src/asn1/x509/V2Form.cs
index a9c43357c..2c6e54a77 100644
--- a/crypto/src/asn1/x509/V2Form.cs
+++ b/crypto/src/asn1/x509/V2Form.cs
@@ -9,55 +9,67 @@ namespace Org.BouncyCastle.Asn1.X509
         internal IssuerSerial        baseCertificateID;
         internal ObjectDigestInfo    objectDigestInfo;
 
-		public static V2Form GetInstance(
+        public static V2Form GetInstance(
             Asn1TaggedObject	obj,
             bool				explicitly)
         {
             return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
         }
 
-		public static V2Form GetInstance(
-            object obj)
+        public static V2Form GetInstance(object obj)
         {
             if (obj is V2Form)
-            {
-                return (V2Form) obj;
-            }
+                return (V2Form)obj;
+            if (obj != null)
+                return new V2Form(Asn1Sequence.GetInstance(obj));
+            return null;
+        }
 
-			if (obj is Asn1Sequence)
-            {
-                return new V2Form((Asn1Sequence) obj);
-            }
+        public V2Form(GeneralNames issuerName)
+            : this(issuerName, null, null)
+        {
+        }
+
+        public V2Form(GeneralNames issuerName, IssuerSerial baseCertificateID)
+            : this(issuerName, baseCertificateID, null)
+        {
+        }
 
-			throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj");
+        public V2Form(GeneralNames issuerName, ObjectDigestInfo objectDigestInfo)
+            : this(issuerName, null, objectDigestInfo)
+        {
         }
 
-		public V2Form(
-            GeneralNames issuerName)
+        public V2Form(
+            GeneralNames issuerName,
+            IssuerSerial baseCertificateID,
+            ObjectDigestInfo objectDigestInfo)
         {
             this.issuerName = issuerName;
+            this.baseCertificateID = baseCertificateID;
+            this.objectDigestInfo = objectDigestInfo;
         }
 
-		private V2Form(
+        private V2Form(
             Asn1Sequence seq)
         {
-			if (seq.Count > 3)
-			{
-				throw new ArgumentException("Bad sequence size: " + seq.Count);
-			}
+            if (seq.Count > 3)
+            {
+                throw new ArgumentException("Bad sequence size: " + seq.Count);
+            }
 
-			int index = 0;
+            int index = 0;
 
-			if (!(seq[0] is Asn1TaggedObject))
+            if (!(seq[0] is Asn1TaggedObject))
             {
                 index++;
                 this.issuerName = GeneralNames.GetInstance(seq[0]);
             }
 
-			for (int i = index; i != seq.Count; i++)
+            for (int i = index; i != seq.Count; i++)
             {
-				Asn1TaggedObject o = Asn1TaggedObject.GetInstance(seq[i]);
-				if (o.TagNo == 0)
+                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(seq[i]);
+                if (o.TagNo == 0)
                 {
                     baseCertificateID = IssuerSerial.GetInstance(o, false);
                 }
@@ -65,29 +77,29 @@ namespace Org.BouncyCastle.Asn1.X509
                 {
                     objectDigestInfo = ObjectDigestInfo.GetInstance(o, false);
                 }
-				else
-				{
-					throw new ArgumentException("Bad tag number: " + o.TagNo);
-				}
-			}
+                else
+                {
+                    throw new ArgumentException("Bad tag number: " + o.TagNo);
+                }
+            }
         }
 
-		public GeneralNames IssuerName
+        public GeneralNames IssuerName
         {
             get { return issuerName; }
         }
 
-		public IssuerSerial BaseCertificateID
+        public IssuerSerial BaseCertificateID
         {
             get { return baseCertificateID; }
         }
 
-		public ObjectDigestInfo ObjectDigestInfo
+        public ObjectDigestInfo ObjectDigestInfo
         {
             get { return objectDigestInfo; }
         }
 
-		/**
+        /**
          * Produce an object suitable for an Asn1OutputStream.
          * <pre>
          *  V2Form ::= Sequence {
@@ -104,22 +116,22 @@ namespace Org.BouncyCastle.Asn1.X509
         {
             Asn1EncodableVector v = new Asn1EncodableVector();
 
-			if (issuerName != null)
+            if (issuerName != null)
             {
                 v.Add(issuerName);
             }
 
-			if (baseCertificateID != null)
+            if (baseCertificateID != null)
             {
                 v.Add(new DerTaggedObject(false, 0, baseCertificateID));
             }
 
-			if (objectDigestInfo != null)
+            if (objectDigestInfo != null)
             {
                 v.Add(new DerTaggedObject(false, 1, objectDigestInfo));
             }
 
-			return new DerSequence(v);
+            return new DerSequence(v);
         }
     }
 }