summary refs log tree commit diff
path: root/crypto/src/asn1/x9/X962Parameters.cs
blob: b863f4bfd81d141220cc6ec4c65e04d02804c9b6 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;

using Org.BouncyCastle.Asn1;

namespace Org.BouncyCastle.Asn1.X9
{
    public class X962Parameters
        : Asn1Encodable, IAsn1Choice
    {
        private readonly Asn1Object _params;

		public static X962Parameters GetInstance(
			object obj)
		{
			if (obj == null || obj is X962Parameters) 
			{
				return (X962Parameters)obj;
			}

			if (obj is Asn1Object) 
			{
				return new X962Parameters((Asn1Object)obj);
			}

			if (obj is byte[])
			{
				try
				{
					return new X962Parameters(Asn1Object.FromByteArray((byte[])obj));
				}
				catch (Exception e)
				{
					throw new ArgumentException("unable to parse encoded data: " + e.Message, e);
				}
			}

			throw new ArgumentException("unknown object in getInstance()");
		}

		public X962Parameters(
            X9ECParameters ecParameters)
        {
            this._params = ecParameters.ToAsn1Object();
        }

		public X962Parameters(
            DerObjectIdentifier namedCurve)
        {
            this._params = namedCurve;
        }

        public X962Parameters(
            Asn1Null obj)
        {
            this._params = obj;
        }

        private X962Parameters(Asn1Object obj)
        {
            this._params = obj;
        }

		public bool IsNamedCurve
        {
			get { return (_params is DerObjectIdentifier); }
        }

		public bool IsImplicitlyCA
        {
			get { return (_params is Asn1Null); }
        }

		public Asn1Object Parameters
        {
            get { return _params; }
        }

		/**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * Parameters ::= CHOICE {
         *    ecParameters ECParameters,
         *    namedCurve   CURVES.&amp;id({CurveNames}),
         *    implicitlyCA Null
         * }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            return _params;
        }
    }
}