UserNotice.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.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. private UserNotice(Asn1Sequence seq)
  51. {
  52. if (seq.Count == 2)
  53. {
  54. noticeRef = NoticeReference.GetInstance(seq[0]);
  55. explicitText = DisplayText.GetInstance(seq[1]);
  56. }
  57. else if (seq.Count == 1)
  58. {
  59. if (seq[0].ToAsn1Object() is Asn1Sequence)
  60. {
  61. noticeRef = NoticeReference.GetInstance(seq[0]);
  62. explicitText = null;
  63. }
  64. else
  65. {
  66. noticeRef = null;
  67. explicitText = DisplayText.GetInstance(seq[0]);
  68. }
  69. }
  70. else if (seq.Count == 0)
  71. {
  72. noticeRef = null; // neither field set!
  73. explicitText = null;
  74. }
  75. else
  76. {
  77. throw new ArgumentException("Bad sequence size: " + seq.Count);
  78. }
  79. }
  80. public static UserNotice GetInstance(object obj)
  81. {
  82. if (obj is UserNotice)
  83. return (UserNotice)obj;
  84. if (obj == null)
  85. return null;
  86. return new UserNotice(Asn1Sequence.GetInstance(obj));
  87. }
  88. public virtual NoticeReference NoticeRef
  89. {
  90. get { return noticeRef; }
  91. }
  92. public virtual DisplayText ExplicitText
  93. {
  94. get { return explicitText; }
  95. }
  96. public override Asn1Object ToAsn1Object()
  97. {
  98. Asn1EncodableVector v = new Asn1EncodableVector();
  99. v.AddOptional(noticeRef, explicitText);
  100. return new DerSequence(v);
  101. }
  102. }
  103. }
  104. #pragma warning restore
  105. #endif