summary refs log tree commit diff
path: root/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
blob: e7c7f9d99bdcb45b3bb5fc62e657a57ab28e03d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;

using Org.BouncyCastle.Math;

namespace Org.BouncyCastle.Asn1.CryptoPro
{
    public class Gost3410ParamSetParameters
        : Asn1Encodable
    {
		public static Gost3410ParamSetParameters GetInstance(object obj)
        {
            if (obj == null)
                return null;
            if (obj is Gost3410ParamSetParameters gost3410ParamSetParameters)
                return gost3410ParamSetParameters;
            return new Gost3410ParamSetParameters(Asn1Sequence.GetInstance(obj));
        }

        public static Gost3410ParamSetParameters GetInstance(Asn1TaggedObject obj, bool explicitly) =>
            new Gost3410ParamSetParameters(Asn1Sequence.GetInstance(obj, explicitly));

        public static Gost3410ParamSetParameters GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
            new Gost3410ParamSetParameters(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));

        private readonly int m_keySize;
        private readonly DerInteger m_p, m_q, m_a;

		private Gost3410ParamSetParameters(Asn1Sequence seq)
        {
            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]);
        }

        public Gost3410ParamSetParameters(int keySize, BigInteger p, BigInteger q, BigInteger a)
        {
            m_keySize = keySize;
            m_p = new DerInteger(p);
            m_q = new DerInteger(q);
            m_a = new DerInteger(a);
        }

        public int KeySize => m_keySize;

		public BigInteger P => m_p.PositiveValue;

		public BigInteger Q => m_q.PositiveValue;

		public BigInteger A => m_a.PositiveValue;

		public override Asn1Object ToAsn1Object() => new DerSequence(new DerInteger(m_keySize), m_p, m_q, m_a);
    }
}