CertStatus.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  7. {
  8. public class CertStatus
  9. : Asn1Encodable
  10. {
  11. private readonly Asn1OctetString certHash;
  12. private readonly DerInteger certReqId;
  13. private readonly PkiStatusInfo statusInfo;
  14. private CertStatus(Asn1Sequence seq)
  15. {
  16. certHash = Asn1OctetString.GetInstance(seq[0]);
  17. certReqId = DerInteger.GetInstance(seq[1]);
  18. if (seq.Count > 2)
  19. {
  20. statusInfo = PkiStatusInfo.GetInstance(seq[2]);
  21. }
  22. }
  23. public CertStatus(byte[] certHash, BigInteger certReqId)
  24. {
  25. this.certHash = new DerOctetString(certHash);
  26. this.certReqId = new DerInteger(certReqId);
  27. }
  28. public CertStatus(byte[] certHash, BigInteger certReqId, PkiStatusInfo statusInfo)
  29. {
  30. this.certHash = new DerOctetString(certHash);
  31. this.certReqId = new DerInteger(certReqId);
  32. this.statusInfo = statusInfo;
  33. }
  34. public static CertStatus GetInstance(object obj)
  35. {
  36. if (obj is CertStatus)
  37. return (CertStatus)obj;
  38. if (obj is Asn1Sequence)
  39. return new CertStatus((Asn1Sequence)obj);
  40. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  41. }
  42. public virtual Asn1OctetString CertHash
  43. {
  44. get { return certHash; }
  45. }
  46. public virtual DerInteger CertReqID
  47. {
  48. get { return certReqId; }
  49. }
  50. public virtual PkiStatusInfo StatusInfo
  51. {
  52. get { return statusInfo; }
  53. }
  54. /**
  55. * <pre>
  56. * CertStatus ::= SEQUENCE {
  57. * certHash OCTET STRING,
  58. * -- the hash of the certificate, using the same hash algorithm
  59. * -- as is used to create and verify the certificate signature
  60. * certReqId INTEGER,
  61. * -- to match this confirmation with the corresponding req/rep
  62. * statusInfo PKIStatusInfo OPTIONAL
  63. * }
  64. * </pre>
  65. * @return a basic ASN.1 object representation.
  66. */
  67. public override Asn1Object ToAsn1Object()
  68. {
  69. Asn1EncodableVector v = new Asn1EncodableVector(certHash, certReqId);
  70. v.AddOptional(statusInfo);
  71. return new DerSequence(v);
  72. }
  73. }
  74. }
  75. #pragma warning restore
  76. #endif