summary refs log tree commit diff
path: root/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs78
1 files changed, 31 insertions, 47 deletions
diff --git a/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs b/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
index ae0cd4f83..e7c7f9d99 100644
--- a/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
+++ b/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
@@ -1,74 +1,58 @@
 using System;
 
 using Org.BouncyCastle.Math;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.CryptoPro
 {
     public class Gost3410ParamSetParameters
         : Asn1Encodable
     {
-        private readonly int keySize;
-        private readonly DerInteger	p, q, a;
-
-		public static Gost3410ParamSetParameters GetInstance(Asn1TaggedObject obj, bool explicitly)
+		public static Gost3410ParamSetParameters GetInstance(object obj)
         {
-            return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
+            if (obj == null)
+                return null;
+            if (obj is Gost3410ParamSetParameters gost3410ParamSetParameters)
+                return gost3410ParamSetParameters;
+            return new Gost3410ParamSetParameters(Asn1Sequence.GetInstance(obj));
         }
 
-		public static Gost3410ParamSetParameters GetInstance(object obj)
-        {
-            if (obj == null || obj is Gost3410ParamSetParameters)
-                return (Gost3410ParamSetParameters) obj;
+        public static Gost3410ParamSetParameters GetInstance(Asn1TaggedObject obj, bool explicitly) =>
+            new Gost3410ParamSetParameters(Asn1Sequence.GetInstance(obj, explicitly));
 
-			if (obj is Asn1Sequence seq)
-                return new Gost3410ParamSetParameters(seq);
+        public static Gost3410ParamSetParameters GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new Gost3410ParamSetParameters(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
 
-            throw new ArgumentException("Invalid GOST3410Parameter: " + Platform.GetTypeName(obj));
-        }
+        private readonly int m_keySize;
+        private readonly DerInteger m_p, m_q, m_a;
 
-		public Gost3410ParamSetParameters(int keySize, BigInteger p, BigInteger q, BigInteger a)
+		private Gost3410ParamSetParameters(Asn1Sequence seq)
         {
-            this.keySize = keySize;
-            this.p = new DerInteger(p);
-            this.q = new DerInteger(q);
-            this.a = new DerInteger(a);
+            int count = seq.Count;
+            if (count != 4)
+                throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
+
+            m_keySize = DerInteger.GetInstance(seq[0]).IntValueExact;
+			m_p = DerInteger.GetInstance(seq[1]);
+            m_q = DerInteger.GetInstance(seq[2]);
+			m_a = DerInteger.GetInstance(seq[3]);
         }
 
-		private Gost3410ParamSetParameters(Asn1Sequence seq)
+        public Gost3410ParamSetParameters(int keySize, BigInteger p, BigInteger q, BigInteger a)
         {
-			if (seq.Count != 4)
-				throw new ArgumentException("Wrong number of elements in sequence", "seq");
-
-            this.keySize = DerInteger.GetInstance(seq[0]).IntValueExact;
-			this.p = DerInteger.GetInstance(seq[1]);
-            this.q = DerInteger.GetInstance(seq[2]);
-			this.a = DerInteger.GetInstance(seq[3]);
+            m_keySize = keySize;
+            m_p = new DerInteger(p);
+            m_q = new DerInteger(q);
+            m_a = new DerInteger(a);
         }
 
-		public int KeySize
-		{
-			get { return keySize; }
-		}
+        public int KeySize => m_keySize;
 
-		public BigInteger P
-		{
-			get { return p.PositiveValue; }
-		}
+		public BigInteger P => m_p.PositiveValue;
 
-		public BigInteger Q
-		{
-			get { return q.PositiveValue; }
-		}
+		public BigInteger Q => m_q.PositiveValue;
 
-		public BigInteger A
-		{
-			get { return a.PositiveValue; }
-		}
+		public BigInteger A => m_a.PositiveValue;
 
-		public override Asn1Object ToAsn1Object()
-        {
-			return new DerSequence(new DerInteger(keySize), p, q, a);
-        }
+		public override Asn1Object ToAsn1Object() => new DerSequence(new DerInteger(m_keySize), m_p, m_q, m_a);
     }
 }