summary refs log tree commit diff
path: root/crypto/src/asn1/cms/MetaData.cs
blob: a0d783d595bd0c46e7fa347be09f91c82ad1d78d (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;

namespace Org.BouncyCastle.Asn1.Cms
{
	public class MetaData
		: Asn1Encodable
	{
        public static MetaData GetInstance(object obj)
        {
			if (obj == null)
				return null;
			if (obj is MetaData metaData)
				return metaData;
            return new MetaData(Asn1Sequence.GetInstance(obj));
        }

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

        private DerBoolean hashProtected;
		private DerUtf8String fileName;
		private DerIA5String  mediaType;
		private Attributes otherMetaData;

		public MetaData(
			DerBoolean		hashProtected,
			DerUtf8String	fileName,
			DerIA5String	mediaType,
			Attributes		otherMetaData)
		{
			this.hashProtected = hashProtected;
			this.fileName = fileName;
			this.mediaType = mediaType;
			this.otherMetaData = otherMetaData;
		}

		private MetaData(Asn1Sequence seq)
		{
			this.hashProtected = DerBoolean.GetInstance(seq[0]);

			int index = 1;

			if (index < seq.Count && seq[index] is DerUtf8String utf8)
			{
				this.fileName = utf8;
				++index;
			}
			if (index < seq.Count && seq[index] is DerIA5String ia5)
			{
				this.mediaType = ia5;
                ++index;
            }
            if (index < seq.Count)
			{
				this.otherMetaData = Attributes.GetInstance(seq[index++]);
			}
		}

		/**
		 * <pre>
		 * MetaData ::= SEQUENCE {
		 *   hashProtected        BOOLEAN,
		 *   fileName             UTF8String OPTIONAL,
		 *   mediaType            IA5String OPTIONAL,
		 *   otherMetaData        Attributes OPTIONAL
		 * }
		 * </pre>
		 * @return
		 */
		public override Asn1Object ToAsn1Object()
		{
			Asn1EncodableVector v = new Asn1EncodableVector(hashProtected);
			v.AddOptional(fileName, mediaType, otherMetaData);
			return new DerSequence(v);
		}

		public virtual bool IsHashProtected
		{
			get { return hashProtected.IsTrue; }
		}

		public virtual DerUtf8String FileName
		{
			get { return fileName; }
		}

		public virtual DerIA5String MediaType
		{
			get { return mediaType; }
		}

		public virtual Attributes OtherMetaData
		{
			get { return otherMetaData; }
		}
	}
}