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

namespace Org.BouncyCastle.Asn1.Cms
{
	/**
	* Produce an object suitable for an Asn1OutputStream.
	* <pre>
	* ContentInfo ::= SEQUENCE {
	*          contentType ContentType,
	*          content
	*          [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
	* </pre>
	*/
	public class ContentInfoParser
	{
		private readonly DerObjectIdentifier m_contentType;
		private readonly Asn1TaggedObjectParser m_content;

		public ContentInfoParser(Asn1SequenceParser seq)
		{
			m_contentType = (DerObjectIdentifier)seq.ReadObject();
			m_content = (Asn1TaggedObjectParser)seq.ReadObject();
		}

		public DerObjectIdentifier ContentType => m_contentType;

		public IAsn1Convertible GetContent(int tag)
		{
			if (null == m_content)
				return null;

            // TODO[cms] Ideally we could enforce the claimed tag
            //return Asn1Utilities.ParseContextBaseUniversal(content, 0, true, tag);
            return Asn1Utilities.ParseExplicitContextBaseObject(m_content, 0);
        }
	}
}