summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/asn1/mozilla/PublicKeyAndChallenge.cs105
1 files changed, 51 insertions, 54 deletions
diff --git a/crypto/src/asn1/mozilla/PublicKeyAndChallenge.cs b/crypto/src/asn1/mozilla/PublicKeyAndChallenge.cs
index ff2a1199f..eafbfd72b 100644
--- a/crypto/src/asn1/mozilla/PublicKeyAndChallenge.cs
+++ b/crypto/src/asn1/mozilla/PublicKeyAndChallenge.cs
@@ -1,68 +1,65 @@
 using System;
 
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Mozilla
 {
-	/**
-	 * This is designed to parse
-	 * the PublicKeyAndChallenge created by the KEYGEN tag included by
-	 * Mozilla based browsers.
-	 *  <pre>
-	 *  PublicKeyAndChallenge ::= SEQUENCE {
-	 *    spki SubjectPublicKeyInfo,
-	 *    challenge IA5STRING
-	 *  }
-	 *
-	 *  </pre>
-	 */
-	public class PublicKeyAndChallenge
-		: Asn1Encodable
-	{
-		private Asn1Sequence			pkacSeq;
-		private SubjectPublicKeyInfo	spki;
-		private DerIA5String			challenge;
+    /// <summary>
+    /// For parsing the PublicKeyAndChallenge created by the KEYGEN tag included by Mozilla based browsers.
+    /// </summary>
+    /// <remarks>
+    /// <code>
+    /// PublicKeyAndChallenge ::= SEQUENCE
+    /// {
+    ///     spki        SubjectPublicKeyInfo,
+    ///     challenge   IA5STRING
+    /// }
+    /// </code>
+    /// </remarks>
+    public class PublicKeyAndChallenge
+        : Asn1Encodable
+    {
+        private readonly SubjectPublicKeyInfo m_spki;
+		private readonly DerIA5String m_challenge;
 
-		public static PublicKeyAndChallenge GetInstance(
-			object obj)
-		{
-			if (obj is PublicKeyAndChallenge)
-			{
-				return (PublicKeyAndChallenge) obj;
-			}
+        public static PublicKeyAndChallenge GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is PublicKeyAndChallenge publicKeyAndChallenge)
+                return publicKeyAndChallenge;
+#pragma warning disable CS0618 // Type or member is obsolete
+            return new PublicKeyAndChallenge(Asn1Sequence.GetInstance(obj));
+#pragma warning restore CS0618 // Type or member is obsolete
+        }
 
-			if (obj is Asn1Sequence)
-			{
-				return new PublicKeyAndChallenge((Asn1Sequence) obj);
-			}
+        public static PublicKeyAndChallenge GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+#pragma warning disable CS0618 // Type or member is obsolete
+            return new PublicKeyAndChallenge(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+#pragma warning restore CS0618 // Type or member is obsolete
+        }
 
-			throw new ArgumentException(
-				"unknown object in 'PublicKeyAndChallenge' factory : "
-                + Platform.GetTypeName(obj) + ".");
-		}
+        public PublicKeyAndChallenge(SubjectPublicKeyInfo spki, DerIA5String challenge)
+        {
+            m_spki = spki ?? throw new ArgumentNullException(nameof(spki));
+            m_challenge = challenge ?? throw new ArgumentNullException(nameof(m_challenge));
+        }
 
-		public PublicKeyAndChallenge(
-			Asn1Sequence seq)
-		{
-			pkacSeq = seq;
-			spki = SubjectPublicKeyInfo.GetInstance(seq[0]);
-			challenge = DerIA5String.GetInstance(seq[1]);
-		}
+        [Obsolete("Use 'GetInstance' instead")]
+        public PublicKeyAndChallenge(Asn1Sequence seq)
+        {
+            m_spki = SubjectPublicKeyInfo.GetInstance(seq[0]);
+            m_challenge = DerIA5String.GetInstance(seq[1]);
+        }
 
-		public override Asn1Object ToAsn1Object()
-		{
-			return pkacSeq;
-		}
+        public DerIA5String Challenge => m_challenge;
 
-		public SubjectPublicKeyInfo SubjectPublicKeyInfo
-		{
-			get { return spki; }
-		}
+        public SubjectPublicKeyInfo Spki => m_spki;
 
-		public DerIA5String Challenge
-		{
-			get { return challenge; }
-		}
-	}
+        [Obsolete("Use 'Spki' instead")]
+        public SubjectPublicKeyInfo SubjectPublicKeyInfo => m_spki;
+
+        public override Asn1Object ToAsn1Object() => new DerSequence(m_spki, m_challenge);
+    }
 }