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

namespace Org.BouncyCastle.Asn1
{
    internal abstract class DerEncoding
        : IAsn1Encoding, IComparable<DerEncoding>
    {
        protected internal readonly int m_tagClass;
        protected internal readonly int m_tagNo;

        protected internal DerEncoding(int tagClass, int tagNo)
        {
            Debug.Assert((tagClass & Asn1Tags.Private) == tagClass);
            Debug.Assert(tagNo >= 0);
            m_tagClass = tagClass;
            m_tagNo = tagNo;
        }

        protected internal abstract int CompareLengthAndContents(DerEncoding other);

        public int CompareTo(DerEncoding other)
        {
            Debug.Assert(other != null);
            if (other == null)
                return 1;
            if (m_tagClass != other.m_tagClass)
                return m_tagClass - other.m_tagClass;
            if (m_tagNo != other.m_tagNo)
                return m_tagNo - other.m_tagNo;
            return CompareLengthAndContents(other);
        }

        public abstract void Encode(Asn1OutputStream asn1Out);

        public abstract int GetLength();
    }
}