CrlIdentifier.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  8. {
  9. /// <remarks>
  10. /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition
  11. /// <code>
  12. /// CrlIdentifier ::= SEQUENCE
  13. /// {
  14. /// crlissuer Name,
  15. /// crlIssuedTime UTCTime,
  16. /// crlNumber INTEGER OPTIONAL
  17. /// }
  18. /// </code>
  19. /// </remarks>
  20. public class CrlIdentifier
  21. : Asn1Encodable
  22. {
  23. private readonly X509Name crlIssuer;
  24. private readonly DerUtcTime crlIssuedTime;
  25. private readonly DerInteger crlNumber;
  26. public static CrlIdentifier GetInstance(
  27. object obj)
  28. {
  29. if (obj == null || obj is CrlIdentifier)
  30. return (CrlIdentifier) obj;
  31. if (obj is Asn1Sequence)
  32. return new CrlIdentifier((Asn1Sequence) obj);
  33. throw new ArgumentException(
  34. "Unknown object in 'CrlIdentifier' factory: "
  35. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  36. "obj");
  37. }
  38. private CrlIdentifier(
  39. Asn1Sequence seq)
  40. {
  41. if (seq == null)
  42. throw new ArgumentNullException("seq");
  43. if (seq.Count < 2 || seq.Count > 3)
  44. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  45. this.crlIssuer = X509Name.GetInstance(seq[0]);
  46. this.crlIssuedTime = DerUtcTime.GetInstance(seq[1]);
  47. if (seq.Count > 2)
  48. {
  49. this.crlNumber = DerInteger.GetInstance(seq[2]);
  50. }
  51. }
  52. public CrlIdentifier(
  53. X509Name crlIssuer,
  54. DateTime crlIssuedTime)
  55. : this(crlIssuer, crlIssuedTime, null)
  56. {
  57. }
  58. public CrlIdentifier(
  59. X509Name crlIssuer,
  60. DateTime crlIssuedTime,
  61. BigInteger crlNumber)
  62. {
  63. if (crlIssuer == null)
  64. throw new ArgumentNullException("crlIssuer");
  65. this.crlIssuer = crlIssuer;
  66. this.crlIssuedTime = new DerUtcTime(crlIssuedTime);
  67. if (crlNumber != null)
  68. {
  69. this.crlNumber = new DerInteger(crlNumber);
  70. }
  71. }
  72. public X509Name CrlIssuer
  73. {
  74. get { return crlIssuer; }
  75. }
  76. public DateTime CrlIssuedTime
  77. {
  78. get { return crlIssuedTime.ToAdjustedDateTime(); }
  79. }
  80. public BigInteger CrlNumber
  81. {
  82. get { return crlNumber == null ? null : crlNumber.Value; }
  83. }
  84. public override Asn1Object ToAsn1Object()
  85. {
  86. Asn1EncodableVector v = new Asn1EncodableVector(crlIssuer.ToAsn1Object(), crlIssuedTime);
  87. v.AddOptional(crlNumber);
  88. return new DerSequence(v);
  89. }
  90. }
  91. }
  92. #pragma warning restore
  93. #endif