HashAlgorithm.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. namespace Org.BouncyCastle.Crypto.Tls
  4. {
  5. /// <summary>RFC 5246 7.4.1.4.1</summary>
  6. public abstract class HashAlgorithm
  7. {
  8. public const byte none = 0;
  9. public const byte md5 = 1;
  10. public const byte sha1 = 2;
  11. public const byte sha224 = 3;
  12. public const byte sha256 = 4;
  13. public const byte sha384 = 5;
  14. public const byte sha512 = 6;
  15. public static string GetName(byte hashAlgorithm)
  16. {
  17. switch (hashAlgorithm)
  18. {
  19. case none:
  20. return "none";
  21. case md5:
  22. return "md5";
  23. case sha1:
  24. return "sha1";
  25. case sha224:
  26. return "sha224";
  27. case sha256:
  28. return "sha256";
  29. case sha384:
  30. return "sha384";
  31. case sha512:
  32. return "sha512";
  33. default:
  34. return "UNKNOWN";
  35. }
  36. }
  37. public static string GetText(byte hashAlgorithm)
  38. {
  39. return GetName(hashAlgorithm) + "(" + hashAlgorithm + ")";
  40. }
  41. public static bool IsPrivate(byte hashAlgorithm)
  42. {
  43. return 224 <= hashAlgorithm && hashAlgorithm <= 255;
  44. }
  45. }
  46. }
  47. #endif