PollReqContent.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  5. {
  6. public class PollReqContent
  7. : Asn1Encodable
  8. {
  9. public static PollReqContent GetInstance(object obj)
  10. {
  11. if (obj is PollReqContent pollReqContent)
  12. return pollReqContent;
  13. if (obj != null)
  14. return new PollReqContent(Asn1Sequence.GetInstance(obj));
  15. return null;
  16. }
  17. private readonly Asn1Sequence m_content;
  18. private PollReqContent(Asn1Sequence seq)
  19. {
  20. m_content = seq;
  21. }
  22. /**
  23. * Create a pollReqContent for a single certReqId.
  24. *
  25. * @param certReqId the certificate request ID.
  26. */
  27. public PollReqContent(DerInteger certReqId)
  28. : this(new DerSequence(new DerSequence(certReqId)))
  29. {
  30. }
  31. /**
  32. * Create a pollReqContent for a multiple certReqIds.
  33. *
  34. * @param certReqIds the certificate request IDs.
  35. */
  36. public PollReqContent(DerInteger[] certReqIds)
  37. : this(new DerSequence(IntsToSequence(certReqIds)))
  38. {
  39. }
  40. /**
  41. * Create a pollReqContent for a single certReqId.
  42. *
  43. * @param certReqId the certificate request ID.
  44. */
  45. public PollReqContent(BigInteger certReqId)
  46. : this(new DerInteger(certReqId))
  47. {
  48. }
  49. /**
  50. * Create a pollReqContent for a multiple certReqIds.
  51. *
  52. * @param certReqIds the certificate request IDs.
  53. */
  54. public PollReqContent(BigInteger[] certReqIds)
  55. : this(IntsToAsn1(certReqIds))
  56. {
  57. }
  58. public virtual DerInteger[][] GetCertReqIDs()
  59. {
  60. DerInteger[][] result = new DerInteger[m_content.Count][];
  61. for (int i = 0; i != result.Length; ++i)
  62. {
  63. result[i] = SequenceToDerIntegerArray((Asn1Sequence)m_content[i]);
  64. }
  65. return result;
  66. }
  67. public virtual BigInteger[] GetCertReqIDValues()
  68. {
  69. BigInteger[] result = new BigInteger[m_content.Count];
  70. for (int i = 0; i != result.Length; i++)
  71. {
  72. result[i] = DerInteger.GetInstance(Asn1Sequence.GetInstance(m_content[i])[0]).Value;
  73. }
  74. return result;
  75. }
  76. /**
  77. * <pre>
  78. * PollReqContent ::= SEQUENCE OF SEQUENCE {
  79. * certReqId INTEGER
  80. * }
  81. * </pre>
  82. * @return a basic ASN.1 object representation.
  83. */
  84. public override Asn1Object ToAsn1Object()
  85. {
  86. return m_content;
  87. }
  88. private static DerInteger[] SequenceToDerIntegerArray(Asn1Sequence seq)
  89. {
  90. return seq.MapElements(DerInteger.GetInstance);
  91. }
  92. private static DerSequence[] IntsToSequence(DerInteger[] ids)
  93. {
  94. DerSequence[] result = new DerSequence[ids.Length];
  95. for (int i = 0; i != result.Length; i++)
  96. {
  97. result[i] = new DerSequence(ids[i]);
  98. }
  99. return result;
  100. }
  101. private static DerInteger[] IntsToAsn1(BigInteger[] ids)
  102. {
  103. DerInteger[] result = new DerInteger[ids.Length];
  104. for (int i = 0; i != result.Length; i++)
  105. {
  106. result[i] = new DerInteger(ids[i]);
  107. }
  108. return result;
  109. }
  110. }
  111. }
  112. #pragma warning restore
  113. #endif