OtherHashAlgAndValue.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  7. {
  8. /// <summary>
  9. /// Summary description for OtherHashAlgAndValue.
  10. /// </summary>
  11. /// <remarks>
  12. /// <code>
  13. /// OtherHashAlgAndValue ::= SEQUENCE {
  14. /// hashAlgorithm AlgorithmIdentifier,
  15. /// hashValue OtherHashValue
  16. /// }
  17. ///
  18. /// OtherHashValue ::= OCTET STRING
  19. /// </code>
  20. /// </remarks>
  21. public class OtherHashAlgAndValue
  22. : Asn1Encodable
  23. {
  24. private readonly AlgorithmIdentifier hashAlgorithm;
  25. private readonly Asn1OctetString hashValue;
  26. public static OtherHashAlgAndValue GetInstance(
  27. object obj)
  28. {
  29. if (obj == null || obj is OtherHashAlgAndValue)
  30. return (OtherHashAlgAndValue) obj;
  31. if (obj is Asn1Sequence)
  32. return new OtherHashAlgAndValue((Asn1Sequence) obj);
  33. throw new ArgumentException(
  34. "Unknown object in 'OtherHashAlgAndValue' factory: "
  35. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  36. "obj");
  37. }
  38. private OtherHashAlgAndValue(
  39. Asn1Sequence seq)
  40. {
  41. if (seq == null)
  42. throw new ArgumentNullException("seq");
  43. if (seq.Count != 2)
  44. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  45. this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0].ToAsn1Object());
  46. this.hashValue = (Asn1OctetString) seq[1].ToAsn1Object();
  47. }
  48. public OtherHashAlgAndValue(
  49. AlgorithmIdentifier hashAlgorithm,
  50. byte[] hashValue)
  51. {
  52. if (hashAlgorithm == null)
  53. throw new ArgumentNullException("hashAlgorithm");
  54. if (hashValue == null)
  55. throw new ArgumentNullException("hashValue");
  56. this.hashAlgorithm = hashAlgorithm;
  57. this.hashValue = new DerOctetString(hashValue);
  58. }
  59. public OtherHashAlgAndValue(
  60. AlgorithmIdentifier hashAlgorithm,
  61. Asn1OctetString hashValue)
  62. {
  63. if (hashAlgorithm == null)
  64. throw new ArgumentNullException("hashAlgorithm");
  65. if (hashValue == null)
  66. throw new ArgumentNullException("hashValue");
  67. this.hashAlgorithm = hashAlgorithm;
  68. this.hashValue = hashValue;
  69. }
  70. public AlgorithmIdentifier HashAlgorithm
  71. {
  72. get { return hashAlgorithm; }
  73. }
  74. public byte[] GetHashValue()
  75. {
  76. return hashValue.GetOctets();
  77. }
  78. public override Asn1Object ToAsn1Object()
  79. {
  80. return new DerSequence(hashAlgorithm, hashValue);
  81. }
  82. }
  83. }
  84. #pragma warning restore
  85. #endif