summary refs log tree commit diff
path: root/crypto/src/pqc/asn1/CmcePublicKey.cs
blob: e811c0d971258e3dce857637ad0a4862c8b2fbe6 (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
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;
            return new CmcePublicKey(Asn1Sequence.GetInstance(o));
        }

        private byte[] t;

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

        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);
        }

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

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