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

using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Asn1.X509;

namespace Org.BouncyCastle.Asn1.Cmp
{
	public class RevRepContentBuilder
	{
		private readonly Asn1EncodableVector m_status = new Asn1EncodableVector();
		private readonly Asn1EncodableVector m_revCerts = new Asn1EncodableVector();
		private readonly Asn1EncodableVector m_crls = new Asn1EncodableVector();

		public virtual RevRepContentBuilder Add(PkiStatusInfo status)
		{
			m_status.Add(status);
			return this;
		}

		public virtual RevRepContentBuilder Add(PkiStatusInfo status, CertId certId)
		{
			if (m_status.Count != m_revCerts.Count)
				throw new InvalidOperationException("status and revCerts sequence must be in common order");

			m_status.Add(status);
			m_revCerts.Add(certId);
			return this;
		}

		public virtual RevRepContentBuilder AddCrl(CertificateList crl)
		{
			m_crls.Add(crl);
			return this;
		}

		public virtual RevRepContent Build()
		{
			Asn1EncodableVector v = new Asn1EncodableVector(3);

			v.Add(new DerSequence(m_status));

			if (m_revCerts.Count != 0)
			{
				v.Add(new DerTaggedObject(true, 0, new DerSequence(m_revCerts)));
			}

			if (m_crls.Count != 0)
			{
				v.Add(new DerTaggedObject(true, 1, new DerSequence(m_crls)));
			}

			return RevRepContent.GetInstance(new DerSequence(v));
		}
	}
}