summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/PollReqContent.cs
blob: 80a39348adc39ffa5b16760044338fc650dbde00 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using Org.BouncyCastle.Math;

namespace Org.BouncyCastle.Asn1.Cmp
{
	public class PollReqContent
		: Asn1Encodable
	{
        public static PollReqContent GetInstance(object obj)
        {
			if (obj is PollReqContent pollReqContent)
				return pollReqContent;

			if (obj != null)
				return new PollReqContent(Asn1Sequence.GetInstance(obj));

			return null;
        }

        private readonly Asn1Sequence m_content;

		private PollReqContent(Asn1Sequence seq)
		{
			m_content = seq;
		}

		/**
		 * Create a pollReqContent for a single certReqId.
		 *
		 * @param certReqId the certificate request ID.
		 */
		public PollReqContent(DerInteger certReqId)
			: this(new DerSequence(new DerSequence(certReqId)))
		{
		}

		/**
		 * Create a pollReqContent for a multiple certReqIds.
		 *
		 * @param certReqIds the certificate request IDs.
		 */
		public PollReqContent(DerInteger[] certReqIds)
			: this(new DerSequence(IntsToSequence(certReqIds)))
		{
		}

		/**
		 * Create a pollReqContent for a single certReqId.
		 *
		 * @param certReqId the certificate request ID.
		 */
		public PollReqContent(BigInteger certReqId)
			: this(new DerInteger(certReqId))
		{
		}

		/**
		 * Create a pollReqContent for a multiple certReqIds.
		 *
		 * @param certReqIds the certificate request IDs.
		 */
		public PollReqContent(BigInteger[] certReqIds)
			: this(IntsToAsn1(certReqIds))
		{
		}

		public virtual DerInteger[][] GetCertReqIDs()
		{
			DerInteger[][] result = new DerInteger[m_content.Count][];
			for (int i = 0; i != result.Length; ++i)
			{
				result[i] = SequenceToDerIntegerArray((Asn1Sequence)m_content[i]);
			}
			return result;
		}

        public virtual BigInteger[] GetCertReqIDValues()
        {
            BigInteger[] result = new BigInteger[m_content.Count];

            for (int i = 0; i != result.Length; i++)
            {
                result[i] = DerInteger.GetInstance(Asn1Sequence.GetInstance(m_content[i])[0]).Value;
            }

            return result;
        }

        /**
		 * <pre>
		 * PollReqContent ::= SEQUENCE OF SEQUENCE {
		 *                        certReqId              INTEGER
		 * }
		 * </pre>
		 * @return a basic ASN.1 object representation.
		 */
        public override Asn1Object ToAsn1Object()
		{
			return m_content;
		}

		private static DerInteger[] SequenceToDerIntegerArray(Asn1Sequence seq)
		{
			return seq.MapElements(DerInteger.GetInstance);
		}

		private static DerSequence[] IntsToSequence(DerInteger[] ids)
		{
			DerSequence[] result = new DerSequence[ids.Length];

			for (int i = 0; i != result.Length; i++)
			{
				result[i] = new DerSequence(ids[i]);
			}

			return result;
		}

		private static DerInteger[] IntsToAsn1(BigInteger[] ids)
		{
			DerInteger[] result = new DerInteger[ids.Length];

			for (int i = 0; i != result.Length; i++)
			{
				result[i] = new DerInteger(ids[i]);
			}

			return result;
		}
	}
}