UserNotice.cs 3.8 KB

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