NoticeReference.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  7. {
  8. /**
  9. * <code>NoticeReference</code> class, used in
  10. * <code>CertificatePolicies</code> X509 V3 extensions
  11. * (in policy qualifiers).
  12. *
  13. * <pre>
  14. * NoticeReference ::= Sequence {
  15. * organization DisplayText,
  16. * noticeNumbers Sequence OF Integer }
  17. *
  18. * </pre>
  19. *
  20. * @see PolicyQualifierInfo
  21. * @see PolicyInformation
  22. */
  23. public class NoticeReference
  24. : Asn1Encodable
  25. {
  26. private readonly DisplayText organization;
  27. private readonly Asn1Sequence noticeNumbers;
  28. private static Asn1EncodableVector ConvertVector(IList numbers)
  29. {
  30. Asn1EncodableVector av = new Asn1EncodableVector();
  31. foreach (object o in numbers)
  32. {
  33. DerInteger di;
  34. if (o is BigInteger)
  35. {
  36. di = new DerInteger((BigInteger)o);
  37. }
  38. else if (o is int)
  39. {
  40. di = new DerInteger((int)o);
  41. }
  42. else
  43. {
  44. throw new ArgumentException();
  45. }
  46. av.Add(di);
  47. }
  48. return av;
  49. }
  50. /**
  51. * Creates a new <code>NoticeReference</code> instance.
  52. *
  53. * @param organization a <code>String</code> value
  54. * @param numbers a <code>Vector</code> value
  55. */
  56. public NoticeReference(string organization, IList numbers)
  57. : this(organization, ConvertVector(numbers))
  58. {
  59. }
  60. /**
  61. * Creates a new <code>NoticeReference</code> instance.
  62. *
  63. * @param organization a <code>String</code> value
  64. * @param noticeNumbers an <code>ASN1EncodableVector</code> value
  65. */
  66. public NoticeReference(string organization, Asn1EncodableVector noticeNumbers)
  67. : this(new DisplayText(organization), noticeNumbers)
  68. {
  69. }
  70. /**
  71. * Creates a new <code>NoticeReference</code> instance.
  72. *
  73. * @param organization displayText
  74. * @param noticeNumbers an <code>ASN1EncodableVector</code> value
  75. */
  76. public NoticeReference(DisplayText organization, Asn1EncodableVector noticeNumbers)
  77. {
  78. this.organization = organization;
  79. this.noticeNumbers = new DerSequence(noticeNumbers);
  80. }
  81. /**
  82. * Creates a new <code>NoticeReference</code> instance.
  83. * <p>Useful for reconstructing a <code>NoticeReference</code>
  84. * instance from its encodable/encoded form.</p>
  85. *
  86. * @param as an <code>Asn1Sequence</code> value obtained from either
  87. * calling @{link ToAsn1Object()} for a <code>NoticeReference</code>
  88. * instance or from parsing it from a Der-encoded stream.
  89. */
  90. private NoticeReference(Asn1Sequence seq)
  91. {
  92. if (seq.Count != 2)
  93. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  94. organization = DisplayText.GetInstance(seq[0]);
  95. noticeNumbers = Asn1Sequence.GetInstance(seq[1]);
  96. }
  97. public static NoticeReference GetInstance(object obj)
  98. {
  99. if (obj is NoticeReference)
  100. return (NoticeReference)obj;
  101. if (obj == null)
  102. return null;
  103. return new NoticeReference(Asn1Sequence.GetInstance(obj));
  104. }
  105. public virtual DisplayText Organization
  106. {
  107. get { return organization; }
  108. }
  109. public virtual DerInteger[] GetNoticeNumbers()
  110. {
  111. DerInteger[] tmp = new DerInteger[noticeNumbers.Count];
  112. for (int i = 0; i != noticeNumbers.Count; ++i)
  113. {
  114. tmp[i] = DerInteger.GetInstance(noticeNumbers[i]);
  115. }
  116. return tmp;
  117. }
  118. /**
  119. * Describe <code>ToAsn1Object</code> method here.
  120. *
  121. * @return a <code>Asn1Object</code> value
  122. */
  123. public override Asn1Object ToAsn1Object()
  124. {
  125. return new DerSequence(organization, noticeNumbers);
  126. }
  127. }
  128. }
  129. #pragma warning restore
  130. #endif