MacAlgorithm.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
  5. {
  6. /// <summary>RFC 2246</summary>
  7. /// <remarks>
  8. /// Note that the values here are implementation-specific and arbitrary. It is recommended not to depend on the
  9. /// particular values (e.g. serialization).
  10. /// </remarks>
  11. public abstract class MacAlgorithm
  12. {
  13. public const int cls_null = 0;
  14. public const int md5 = 1;
  15. public const int sha = 2;
  16. /*
  17. * RFC 5246
  18. */
  19. public const int hmac_md5 = md5;
  20. public const int hmac_sha1 = sha;
  21. public const int hmac_sha256 = 3;
  22. public const int hmac_sha384 = 4;
  23. public const int hmac_sha512 = 5;
  24. public static string GetName(int macAlgorithm)
  25. {
  26. switch (macAlgorithm)
  27. {
  28. case cls_null:
  29. return "null";
  30. case hmac_md5:
  31. return "hmac_md5";
  32. case hmac_sha1:
  33. return "hmac_sha1";
  34. case hmac_sha256:
  35. return "hmac_sha256";
  36. case hmac_sha384:
  37. return "hmac_sha384";
  38. case hmac_sha512:
  39. return "hmac_sha512";
  40. default:
  41. return "UNKNOWN";
  42. }
  43. }
  44. public static string GetText(int macAlgorithm)
  45. {
  46. return GetName(macAlgorithm) + "(" + macAlgorithm + ")";
  47. }
  48. public static bool IsHmac(int macAlgorithm)
  49. {
  50. switch (macAlgorithm)
  51. {
  52. case hmac_md5:
  53. case hmac_sha1:
  54. case hmac_sha256:
  55. case hmac_sha384:
  56. case hmac_sha512:
  57. return true;
  58. default:
  59. return false;
  60. }
  61. }
  62. }
  63. }
  64. #pragma warning restore
  65. #endif