diff options
Diffstat (limited to 'crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs')
-rw-r--r-- | crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs | 96 |
1 files changed, 47 insertions, 49 deletions
diff --git a/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs b/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs index 2c494c526..ac3a43f9d 100644 --- a/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs +++ b/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs @@ -1,79 +1,77 @@ using System; using Org.BouncyCastle.Math; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.CryptoPro { public class ECGost3410ParamSetParameters : Asn1Encodable { - internal readonly DerInteger p, q, a, b, x, y; + public static ECGost3410ParamSetParameters GetInstance(object obj) + { + if (obj == null) + return null; + if (obj is ECGost3410ParamSetParameters ecGost3410ParamSetParameters) + return ecGost3410ParamSetParameters; +#pragma warning disable CS0618 // Type or member is obsolete + return new ECGost3410ParamSetParameters(Asn1Sequence.GetInstance(obj)); +#pragma warning restore CS0618 // Type or member is obsolete + } public static ECGost3410ParamSetParameters GetInstance(Asn1TaggedObject obj, bool explicitly) { - return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); +#pragma warning disable CS0618 // Type or member is obsolete + return new ECGost3410ParamSetParameters(Asn1Sequence.GetInstance(obj, explicitly)); +#pragma warning restore CS0618 // Type or member is obsolete } - public static ECGost3410ParamSetParameters GetInstance(object obj) + public static ECGost3410ParamSetParameters GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { - if (obj == null || obj is ECGost3410ParamSetParameters) - return (ECGost3410ParamSetParameters)obj; +#pragma warning disable CS0618 // Type or member is obsolete + return new ECGost3410ParamSetParameters(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); +#pragma warning restore CS0618 // Type or member is obsolete + } + + private readonly DerInteger m_a, m_b, m_p, m_q, m_x, m_y; - if (obj is Asn1Sequence seq) - return new ECGost3410ParamSetParameters(seq); + [Obsolete("Use 'GetInstance' instead")] + public ECGost3410ParamSetParameters(Asn1Sequence seq) + { + int count = seq.Count; + if (count != 6) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - throw new ArgumentException("Invalid GOST3410Parameter: " + Platform.GetTypeName(obj)); + m_a = DerInteger.GetInstance(seq[0]); + m_b = DerInteger.GetInstance(seq[1]); + m_p = DerInteger.GetInstance(seq[2]); + m_q = DerInteger.GetInstance(seq[3]); + m_x = DerInteger.GetInstance(seq[4]); + m_y = DerInteger.GetInstance(seq[5]); } - public ECGost3410ParamSetParameters( - BigInteger a, - BigInteger b, - BigInteger p, - BigInteger q, - int x, + public ECGost3410ParamSetParameters(BigInteger a, BigInteger b, BigInteger p, BigInteger q, int x, BigInteger y) { - this.a = new DerInteger(a); - this.b = new DerInteger(b); - this.p = new DerInteger(p); - this.q = new DerInteger(q); - this.x = new DerInteger(x); - this.y = new DerInteger(y); + m_a = new DerInteger(a); + m_b = new DerInteger(b); + m_p = new DerInteger(p); + m_q = new DerInteger(q); + m_x = new DerInteger(x); + m_y = new DerInteger(y); } - public ECGost3410ParamSetParameters( - Asn1Sequence seq) - { - if (seq.Count != 6) - throw new ArgumentException("Wrong number of elements in sequence", "seq"); + public BigInteger A => m_a.PositiveValue; - this.a = DerInteger.GetInstance(seq[0]); - this.b = DerInteger.GetInstance(seq[1]); - this.p = DerInteger.GetInstance(seq[2]); - this.q = DerInteger.GetInstance(seq[3]); - this.x = DerInteger.GetInstance(seq[4]); - this.y = DerInteger.GetInstance(seq[5]); - } + public BigInteger B => m_b.PositiveValue; - 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; } - } + int X => m_x.IntPositiveValueExact; - public override Asn1Object ToAsn1Object() - { - return new DerSequence(a, b, p, q, x, y); - } + public BigInteger Y => m_y.PositiveValue; + + public override Asn1Object ToAsn1Object() => new DerSequence(m_a, m_b, m_p, m_q, m_x, m_y); } } |