CertID.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ocsp
  8. {
  9. public class CertID
  10. : Asn1Encodable
  11. {
  12. private readonly AlgorithmIdentifier hashAlgorithm;
  13. private readonly Asn1OctetString issuerNameHash;
  14. private readonly Asn1OctetString issuerKeyHash;
  15. private readonly DerInteger serialNumber;
  16. public static CertID GetInstance(
  17. Asn1TaggedObject obj,
  18. bool explicitly)
  19. {
  20. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  21. }
  22. public static CertID GetInstance(
  23. object obj)
  24. {
  25. if (obj == null || obj is CertID)
  26. {
  27. return (CertID)obj;
  28. }
  29. if (obj is Asn1Sequence)
  30. {
  31. return new CertID((Asn1Sequence)obj);
  32. }
  33. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  34. }
  35. public CertID(
  36. AlgorithmIdentifier hashAlgorithm,
  37. Asn1OctetString issuerNameHash,
  38. Asn1OctetString issuerKeyHash,
  39. DerInteger serialNumber)
  40. {
  41. this.hashAlgorithm = hashAlgorithm;
  42. this.issuerNameHash = issuerNameHash;
  43. this.issuerKeyHash = issuerKeyHash;
  44. this.serialNumber = serialNumber;
  45. }
  46. private CertID(
  47. Asn1Sequence seq)
  48. {
  49. if (seq.Count != 4)
  50. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  51. this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
  52. this.issuerNameHash = Asn1OctetString.GetInstance(seq[1]);
  53. this.issuerKeyHash = Asn1OctetString.GetInstance(seq[2]);
  54. this.serialNumber = DerInteger.GetInstance(seq[3]);
  55. }
  56. public AlgorithmIdentifier HashAlgorithm
  57. {
  58. get { return hashAlgorithm; }
  59. }
  60. public Asn1OctetString IssuerNameHash
  61. {
  62. get { return issuerNameHash; }
  63. }
  64. public Asn1OctetString IssuerKeyHash
  65. {
  66. get { return issuerKeyHash; }
  67. }
  68. public DerInteger SerialNumber
  69. {
  70. get { return serialNumber; }
  71. }
  72. /**
  73. * Produce an object suitable for an Asn1OutputStream.
  74. * <pre>
  75. * CertID ::= Sequence {
  76. * hashAlgorithm AlgorithmIdentifier,
  77. * issuerNameHash OCTET STRING, -- Hash of Issuer's DN
  78. * issuerKeyHash OCTET STRING, -- Hash of Issuers public key
  79. * serialNumber CertificateSerialNumber }
  80. * </pre>
  81. */
  82. public override Asn1Object ToAsn1Object()
  83. {
  84. return new DerSequence(hashAlgorithm, issuerNameHash, issuerKeyHash, serialNumber);
  85. }
  86. }
  87. }
  88. #pragma warning restore
  89. #endif