OobCertHash.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  8. {
  9. /**
  10. * <pre>
  11. * OOBCertHash ::= SEQUENCE {
  12. * hashAlg [0] AlgorithmIdentifier OPTIONAL,
  13. * certId [1] CertId OPTIONAL,
  14. * hashVal BIT STRING
  15. * -- hashVal is calculated over the DER encoding of the
  16. * -- self-signed certificate with the identifier certID.
  17. * }
  18. * </pre>
  19. */
  20. public class OobCertHash
  21. : Asn1Encodable
  22. {
  23. public static OobCertHash GetInstance(object obj)
  24. {
  25. if (obj is OobCertHash oobCertHash)
  26. return oobCertHash;
  27. if (obj != null)
  28. return new OobCertHash(Asn1Sequence.GetInstance(obj));
  29. return null;
  30. }
  31. private readonly AlgorithmIdentifier m_hashAlg;
  32. private readonly CertId m_certId;
  33. private readonly DerBitString m_hashVal;
  34. private OobCertHash(Asn1Sequence seq)
  35. {
  36. int index = seq.Count - 1;
  37. m_hashVal = DerBitString.GetInstance(seq[index--]);
  38. for (int i = index; i >= 0; i--)
  39. {
  40. Asn1TaggedObject tObj = (Asn1TaggedObject)seq[i];
  41. if (tObj.TagNo == 0)
  42. {
  43. m_hashAlg = AlgorithmIdentifier.GetInstance(tObj, true);
  44. }
  45. else
  46. {
  47. m_certId = CertId.GetInstance(tObj, true);
  48. }
  49. }
  50. }
  51. public virtual CertId CertID => m_certId;
  52. public virtual AlgorithmIdentifier HashAlg => m_hashAlg;
  53. public virtual DerBitString HashVal => m_hashVal;
  54. /**
  55. * <pre>
  56. * OobCertHash ::= SEQUENCE {
  57. * hashAlg [0] AlgorithmIdentifier OPTIONAL,
  58. * certId [1] CertId OPTIONAL,
  59. * hashVal BIT STRING
  60. * -- hashVal is calculated over the Der encoding of the
  61. * -- self-signed certificate with the identifier certID.
  62. * }
  63. * </pre>
  64. * @return a basic ASN.1 object representation.
  65. */
  66. public override Asn1Object ToAsn1Object()
  67. {
  68. Asn1EncodableVector v = new Asn1EncodableVector();
  69. v.AddOptionalTagged(true, 0, m_hashAlg);
  70. v.AddOptionalTagged(true, 1, m_certId);
  71. v.Add(m_hashVal);
  72. return new DerSequence(v);
  73. }
  74. }
  75. }
  76. #pragma warning restore
  77. #endif