summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/PollRepContent.cs
blob: e81ce32785ad2f5e2b7a10a75ef7faf0d4f95380 (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
namespace Org.BouncyCastle.Asn1.Cmp
{
    /**
     * PollRepContent ::= SEQUENCE OF SEQUENCE {
     * certReqId    INTEGER,
     * checkAfter   INTEGER,  -- time in seconds
     * reason       PKIFreeText OPTIONAL }
     */
    public class PollRepContent
		: Asn1Encodable
	{
        public static PollRepContent GetInstance(object obj)
        {
            if (obj == null)
                return null;
            if (obj is PollRepContent pollRepContent)
                return pollRepContent;
            return new PollRepContent(Asn1Sequence.GetInstance(obj));
        }

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

        private readonly DerInteger[] m_certReqID;
		private readonly DerInteger[] m_checkAfter;
		private readonly PkiFreeText[] m_reason;

		private PollRepContent(Asn1Sequence seq)
		{
			int count = seq.Count;
			m_certReqID = new DerInteger[count];
			m_checkAfter = new DerInteger[count];
			m_reason = new PkiFreeText[count];

			for (int i = 0; i != count; i++)
			{
				Asn1Sequence s = Asn1Sequence.GetInstance(seq[i]);

				m_certReqID[i] = DerInteger.GetInstance(s[0]);
				m_checkAfter[i] = DerInteger.GetInstance(s[1]);

				if (s.Count > 2)
				{
					m_reason[i] = PkiFreeText.GetInstance(s[2]);
				}
			}
		}

	    public PollRepContent(DerInteger certReqID, DerInteger checkAfter)
			: this(certReqID, checkAfter, null)
	    {
	    }

        public PollRepContent(DerInteger certReqID, DerInteger checkAfter, PkiFreeText reason)
	    {
            m_certReqID = new DerInteger[1]{ certReqID };
            m_checkAfter = new DerInteger[1]{ checkAfter };
            m_reason = new PkiFreeText[1]{ reason };
        }

        public virtual int Count => m_certReqID.Length;

        public virtual DerInteger GetCertReqID(int index) => m_certReqID[index];

		public virtual DerInteger GetCheckAfter(int index) => m_checkAfter[index];

		public virtual PkiFreeText GetReason(int index) => m_reason[index];

		/**
		 * <pre>
		 * PollRepContent ::= SEQUENCE OF SEQUENCE {
		 *         certReqId              INTEGER,
		 *         checkAfter             INTEGER,  -- time in seconds
		 *         reason                 PKIFreeText OPTIONAL
		 *     }
		 * </pre>
		 * @return a basic ASN.1 object representation.
		 */
		public override Asn1Object ToAsn1Object()
		{
			Asn1EncodableVector outer = new Asn1EncodableVector(m_certReqID.Length);

			for (int i = 0; i != m_certReqID.Length; i++)
			{
				Asn1EncodableVector v = new Asn1EncodableVector(3);

				v.Add(m_certReqID[i]);
				v.Add(m_checkAfter[i]);
				v.AddOptional(m_reason[i]);

				outer.Add(new DerSequence(v));
			}

			return new DerSequence(outer);
		}
	}
}