summary refs log tree commit diff
path: root/crypto/src/pqc/asn1/CmcePublicKey.cs
blob: c9feebdf5a5d0d86679fdf9256a44eccc773d1ee (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
using System;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Pqc.Asn1
{
    // TODO[api] Should only be Asn1Encodable
    public class CmcePublicKey
        : Asn1Object
    {
        public static CmcePublicKey GetInstance(Object o)
        {
            if (o == null)
                return null;
            if (o is CmcePublicKey cmcePublicKey)
                return cmcePublicKey;
#pragma warning disable CS0618 // Type or member is obsolete
            return new CmcePublicKey(Asn1Sequence.GetInstance(o));
#pragma warning restore CS0618 // Type or member is obsolete
        }

        public static CmcePublicKey GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
        {
            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
        }

        private byte[] t;

        public CmcePublicKey(byte[] t)
        {
            this.t = t;
        }

        [Obsolete("Use 'GetInstance' instead")]
        public CmcePublicKey(Asn1Sequence seq)
        {
            t = Arrays.Clone(Asn1OctetString.GetInstance(seq[0]).GetOctets());
        }

        public byte[] T => Arrays.Clone(t);

        public Asn1Object ToAsn1Primitive()
        {
            return new DerSequence(new DerOctetString(t));
        }

        internal override IAsn1Encoding GetEncoding(int encoding)
        {
            return ToAsn1Primitive().GetEncoding(encoding);
        }

        internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
        {
            return ToAsn1Primitive().GetEncodingImplicit(encoding, tagClass, tagNo);
        }

        internal override DerEncoding GetEncodingDer()
        {
            return ToAsn1Primitive().GetEncodingDer();
        }

        internal override DerEncoding GetEncodingDerImplicit(int tagClass, int tagNo)
        {
            return ToAsn1Primitive().GetEncodingDerImplicit(tagClass, tagNo);
        }

        protected override bool Asn1Equals(Asn1Object asn1Object)
        {
            return ToAsn1Primitive().CallAsn1Equals(asn1Object);
        }

        protected override int Asn1GetHashCode()
        {
            return ToAsn1Primitive().CallAsn1GetHashCode();
        }
    }
}