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

using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Asn1
{
    /**
     * We insert one of these when we find a tag we don't recognise.
     */
    public class DerUnknownTag
        : Asn1Object
    {
		private readonly bool	isConstructed;
        private readonly int	tag;
        private readonly byte[]	data;

        /**
         * @param tag the tag value.
         * @param data the contents octets.
         */
        public DerUnknownTag(
            int		tag,
            byte[]	data)
			: this(false, tag, data)
        {
        }

		public DerUnknownTag(
			bool	isConstructed,
			int		tag,
			byte[]	data)
		{
			if (data == null)
				throw new ArgumentNullException("data");

			this.isConstructed = isConstructed;
			this.tag = tag;
			this.data = data;
		}

		public bool IsConstructed
		{
			get { return isConstructed; }
		}

		public int Tag
        {
			get { return tag; }
        }

		public byte[] GetData()
        {
            return data;
        }

        internal override void Encode(
            DerOutputStream derOut)
        {
			derOut.WriteEncoded(isConstructed ? Asn1Tags.Constructed : 0, tag, data);
        }

		protected override bool Asn1Equals(
			Asn1Object asn1Object)
		{
			DerUnknownTag other = asn1Object as DerUnknownTag;

			if (other == null)
				return false;

			return this.isConstructed == other.isConstructed
				&& this.tag == other.tag
				&& Arrays.AreEqual(this.data, other.data);
        }

		protected override int Asn1GetHashCode()
		{
			return isConstructed.GetHashCode() ^ tag.GetHashCode() ^ Arrays.GetHashCode(data);
        }
    }
}