RespID.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.Ocsp;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  8. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  9. using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
  10. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Ocsp
  11. {
  12. /**
  13. * Carrier for a ResponderID.
  14. */
  15. public class RespID
  16. {
  17. internal readonly ResponderID id;
  18. public RespID(
  19. ResponderID id)
  20. {
  21. this.id = id;
  22. }
  23. public RespID(
  24. X509Name name)
  25. {
  26. this.id = new ResponderID(name);
  27. }
  28. public RespID(
  29. AsymmetricKeyParameter publicKey)
  30. {
  31. try
  32. {
  33. SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
  34. byte[] keyHash = DigestUtilities.CalculateDigest("SHA1", info.PublicKeyData.GetBytes());
  35. this.id = new ResponderID(new DerOctetString(keyHash));
  36. }
  37. catch (Exception e)
  38. {
  39. throw new OcspException("problem creating ID: " + e, e);
  40. }
  41. }
  42. public ResponderID ToAsn1Object()
  43. {
  44. return id;
  45. }
  46. public override bool Equals(
  47. object obj)
  48. {
  49. if (obj == this)
  50. return true;
  51. RespID other = obj as RespID;
  52. if (other == null)
  53. return false;
  54. return id.Equals(other.id);
  55. }
  56. public override int GetHashCode()
  57. {
  58. return id.GetHashCode();
  59. }
  60. }
  61. }
  62. #pragma warning restore
  63. #endif