UserNotice.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. public UserNotice(
  60. Asn1Sequence seq)
  61. {
  62. if (seq.Count == 2)
  63. {
  64. noticeRef = NoticeReference.GetInstance(seq[0]);
  65. explicitText = DisplayText.GetInstance(seq[1]);
  66. }
  67. else if (seq.Count == 1)
  68. {
  69. if (seq[0].ToAsn1Object() is Asn1Sequence)
  70. {
  71. noticeRef = NoticeReference.GetInstance(seq[0]);
  72. explicitText = null;
  73. }
  74. else
  75. {
  76. noticeRef = null;
  77. explicitText = DisplayText.GetInstance(seq[0]);
  78. }
  79. }
  80. else if (seq.Count == 0)
  81. {
  82. noticeRef = null; // neither field set!
  83. explicitText = null;
  84. }
  85. else
  86. {
  87. throw new ArgumentException("Bad sequence size: " + seq.Count);
  88. }
  89. }
  90. public static UserNotice GetInstance(object obj)
  91. {
  92. if (obj is UserNotice)
  93. return (UserNotice)obj;
  94. if (obj == null)
  95. return null;
  96. return new UserNotice(Asn1Sequence.GetInstance(obj));
  97. }
  98. public virtual NoticeReference NoticeRef
  99. {
  100. get { return noticeRef; }
  101. }
  102. public virtual DisplayText ExplicitText
  103. {
  104. get { return explicitText; }
  105. }
  106. public override Asn1Object ToAsn1Object()
  107. {
  108. Asn1EncodableVector v = new Asn1EncodableVector();
  109. v.AddOptional(noticeRef, explicitText);
  110. return new DerSequence(v);
  111. }
  112. }
  113. }
  114. #pragma warning restore
  115. #endif