DigestInfo.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  7. {
  8. /**
  9. * The DigestInfo object.
  10. * <pre>
  11. * DigestInfo::=Sequence{
  12. * digestAlgorithm AlgorithmIdentifier,
  13. * digest OCTET STRING }
  14. * </pre>
  15. */
  16. public class DigestInfo
  17. : Asn1Encodable
  18. {
  19. private readonly byte[] digest;
  20. private readonly AlgorithmIdentifier algID;
  21. public static DigestInfo GetInstance(
  22. Asn1TaggedObject obj,
  23. bool explicitly)
  24. {
  25. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  26. }
  27. public static DigestInfo GetInstance(
  28. object obj)
  29. {
  30. if (obj is DigestInfo)
  31. {
  32. return (DigestInfo) obj;
  33. }
  34. if (obj is Asn1Sequence)
  35. {
  36. return new DigestInfo((Asn1Sequence) obj);
  37. }
  38. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  39. }
  40. public DigestInfo(
  41. AlgorithmIdentifier algID,
  42. byte[] digest)
  43. {
  44. this.digest = digest;
  45. this.algID = algID;
  46. }
  47. private DigestInfo(
  48. Asn1Sequence seq)
  49. {
  50. if (seq.Count != 2)
  51. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  52. algID = AlgorithmIdentifier.GetInstance(seq[0]);
  53. digest = Asn1OctetString.GetInstance(seq[1]).GetOctets();
  54. }
  55. public AlgorithmIdentifier AlgorithmID
  56. {
  57. get { return algID; }
  58. }
  59. public byte[] GetDigest()
  60. {
  61. return digest;
  62. }
  63. public override Asn1Object ToAsn1Object()
  64. {
  65. return new DerSequence(algID, new DerOctetString(digest));
  66. }
  67. }
  68. }
  69. #pragma warning restore
  70. #endif