CrlValidatedID.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  6. {
  7. /// <remarks>
  8. /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition
  9. /// <code>
  10. /// CrlValidatedID ::= SEQUENCE {
  11. /// crlHash OtherHash,
  12. /// crlIdentifier CrlIdentifier OPTIONAL}
  13. /// </code>
  14. /// </remarks>
  15. public class CrlValidatedID
  16. : Asn1Encodable
  17. {
  18. private readonly OtherHash crlHash;
  19. private readonly CrlIdentifier crlIdentifier;
  20. public static CrlValidatedID GetInstance(
  21. object obj)
  22. {
  23. if (obj == null || obj is CrlValidatedID)
  24. return (CrlValidatedID) obj;
  25. if (obj is Asn1Sequence)
  26. return new CrlValidatedID((Asn1Sequence) obj);
  27. throw new ArgumentException(
  28. "Unknown object in 'CrlValidatedID' factory: "
  29. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  30. "obj");
  31. }
  32. private CrlValidatedID(
  33. Asn1Sequence seq)
  34. {
  35. if (seq == null)
  36. throw new ArgumentNullException("seq");
  37. if (seq.Count < 1 || seq.Count > 2)
  38. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  39. this.crlHash = OtherHash.GetInstance(seq[0].ToAsn1Object());
  40. if (seq.Count > 1)
  41. {
  42. this.crlIdentifier = CrlIdentifier.GetInstance(seq[1].ToAsn1Object());
  43. }
  44. }
  45. public CrlValidatedID(
  46. OtherHash crlHash)
  47. : this(crlHash, null)
  48. {
  49. }
  50. public CrlValidatedID(
  51. OtherHash crlHash,
  52. CrlIdentifier crlIdentifier)
  53. {
  54. if (crlHash == null)
  55. throw new ArgumentNullException("crlHash");
  56. this.crlHash = crlHash;
  57. this.crlIdentifier = crlIdentifier;
  58. }
  59. public OtherHash CrlHash
  60. {
  61. get { return crlHash; }
  62. }
  63. public CrlIdentifier CrlIdentifier
  64. {
  65. get { return crlIdentifier; }
  66. }
  67. public override Asn1Object ToAsn1Object()
  68. {
  69. Asn1EncodableVector v = new Asn1EncodableVector(crlHash.ToAsn1Object());
  70. if (crlIdentifier != null)
  71. {
  72. v.Add(crlIdentifier.ToAsn1Object());
  73. }
  74. return new DerSequence(v);
  75. }
  76. }
  77. }
  78. #pragma warning restore
  79. #endif