HashAlgorithm.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Tls
  5. {
  6. /// <summary>RFC 5246 7.4.1.4.1</summary>
  7. public abstract class HashAlgorithm
  8. {
  9. public const byte none = 0;
  10. public const byte md5 = 1;
  11. public const byte sha1 = 2;
  12. public const byte sha224 = 3;
  13. public const byte sha256 = 4;
  14. public const byte sha384 = 5;
  15. public const byte sha512 = 6;
  16. public static string GetName(byte hashAlgorithm)
  17. {
  18. switch (hashAlgorithm)
  19. {
  20. case none:
  21. return "none";
  22. case md5:
  23. return "md5";
  24. case sha1:
  25. return "sha1";
  26. case sha224:
  27. return "sha224";
  28. case sha256:
  29. return "sha256";
  30. case sha384:
  31. return "sha384";
  32. case sha512:
  33. return "sha512";
  34. default:
  35. return "UNKNOWN";
  36. }
  37. }
  38. public static string GetText(byte hashAlgorithm)
  39. {
  40. return GetName(hashAlgorithm) + "(" + hashAlgorithm + ")";
  41. }
  42. public static bool IsPrivate(byte hashAlgorithm)
  43. {
  44. return 224 <= hashAlgorithm && hashAlgorithm <= 255;
  45. }
  46. public static bool IsRecognized(byte hashAlgorithm)
  47. {
  48. switch (hashAlgorithm)
  49. {
  50. case md5:
  51. case sha1:
  52. case sha224:
  53. case sha256:
  54. case sha384:
  55. case sha512:
  56. return true;
  57. default:
  58. return false;
  59. }
  60. }
  61. }
  62. }
  63. #pragma warning restore
  64. #endif