OtherHash.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  7. {
  8. /// <remarks>
  9. /// <code>
  10. /// OtherHash ::= CHOICE {
  11. /// sha1Hash OtherHashValue, -- This contains a SHA-1 hash
  12. /// otherHash OtherHashAlgAndValue
  13. /// }
  14. ///
  15. /// OtherHashValue ::= OCTET STRING
  16. /// </code>
  17. /// </remarks>
  18. public class OtherHash
  19. : Asn1Encodable, IAsn1Choice
  20. {
  21. private readonly Asn1OctetString sha1Hash;
  22. private readonly OtherHashAlgAndValue otherHash;
  23. public static OtherHash GetInstance(
  24. object obj)
  25. {
  26. if (obj == null || obj is OtherHash)
  27. return (OtherHash) obj;
  28. if (obj is Asn1OctetString)
  29. return new OtherHash((Asn1OctetString) obj);
  30. return new OtherHash(
  31. OtherHashAlgAndValue.GetInstance(obj));
  32. }
  33. public OtherHash(
  34. byte[] sha1Hash)
  35. {
  36. if (sha1Hash == null)
  37. throw new ArgumentNullException("sha1Hash");
  38. this.sha1Hash = new DerOctetString(sha1Hash);
  39. }
  40. public OtherHash(
  41. Asn1OctetString sha1Hash)
  42. {
  43. if (sha1Hash == null)
  44. throw new ArgumentNullException("sha1Hash");
  45. this.sha1Hash = sha1Hash;
  46. }
  47. public OtherHash(
  48. OtherHashAlgAndValue otherHash)
  49. {
  50. if (otherHash == null)
  51. throw new ArgumentNullException("otherHash");
  52. this.otherHash = otherHash;
  53. }
  54. public AlgorithmIdentifier HashAlgorithm
  55. {
  56. get
  57. {
  58. return otherHash == null
  59. ? new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1)
  60. : otherHash.HashAlgorithm;
  61. }
  62. }
  63. public byte[] GetHashValue()
  64. {
  65. return otherHash == null
  66. ? sha1Hash.GetOctets()
  67. : otherHash.GetHashValue();
  68. }
  69. public override Asn1Object ToAsn1Object()
  70. {
  71. return otherHash == null
  72. ? sha1Hash
  73. : otherHash.ToAsn1Object();
  74. }
  75. }
  76. }
  77. #pragma warning restore
  78. #endif