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

using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Asn1
{
	/**
	 * DER TaggedObject - in ASN.1 notation this is any object preceded by
	 * a [n] where n is some number - these are assumed to follow the construction
	 * rules (as with sequences).
	 */
	public class DerTaggedObject
		: Asn1TaggedObject
	{
		/**
		 * @param tagNo the tag number for this object.
		 * @param obj the tagged object.
		 */
		public DerTaggedObject(
			int				tagNo,
			Asn1Encodable	obj)
			: base(tagNo, obj)
		{
		}

		/**
		 * @param explicitly true if an explicitly tagged object.
		 * @param tagNo the tag number for this object.
		 * @param obj the tagged object.
		 */
		public DerTaggedObject(
			bool			explicitly,
			int				tagNo,
			Asn1Encodable	obj)
			: base(explicitly, tagNo, obj)
		{
		}

		/**
		 * create an implicitly tagged object that contains a zero
		 * length sequence.
		 */
		public DerTaggedObject(
			int tagNo)
			: base(false, tagNo, DerSequence.Empty)
		{
		}

        internal override bool EncodeConstructed()
        {
            throw Platform.CreateNotImplementedException("DerTaggedObject.EncodeConstructed");

            //return IsExplicit() || obj.ToAsn1Object().ToDerObject().EncodeConstructed();
        }

        internal override int EncodedLength(bool withID)
        {
            throw Platform.CreateNotImplementedException("DerTaggedObject.EncodedLength");
        }

        internal override void Encode(Asn1OutputStream asn1Out, bool withID)
		{
			byte[] bytes = obj.GetDerEncoded();

			if (explicitly)
			{
				asn1Out.WriteEncodingDL(withID, Asn1Tags.Constructed | TagClass, TagNo, bytes);
			}
			else
			{
                if (withID)
                {
                    // need to mark constructed types... (preserve Constructed tag)
                    int flags = (bytes[0] & Asn1Tags.Constructed) | TagClass;
                    asn1Out.WriteIdentifier(true, flags, TagNo);
                }

                asn1Out.Write(bytes, 1, bytes.Length - 1);
			}
		}
    }
}