OobCertHash.cs 2.1 KB

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