TlsExtensions.cs 857 B

12345678910111213141516171819202122232425262728293031
  1. namespace WatsonTcp
  2. {
  3. using System;
  4. using System.Security.Authentication;
  5. /// <summary>
  6. /// TLS extensions.
  7. /// </summary>
  8. public static class TlsExtensions
  9. {
  10. /// <summary>
  11. /// TLS version to SSL protocol version.
  12. /// </summary>
  13. /// <param name="tlsVersion"></param>
  14. /// <returns></returns>
  15. public static SslProtocols ToSslProtocols(this TlsVersion tlsVersion)
  16. {
  17. switch (tlsVersion)
  18. {
  19. case TlsVersion.Tls12:
  20. return SslProtocols.Tls12;
  21. #if NET5_0_OR_GREATER
  22. case TlsVersion.Tls13:
  23. return SslProtocols.Tls13;
  24. #endif
  25. default:
  26. throw new ArgumentOutOfRangeException($"Unsupported TLS version {tlsVersion}.");
  27. }
  28. }
  29. }
  30. }