From f8cbf5ad3a60f977753695b13e7e6e52ba319ed4 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 14 Oct 2023 09:17:19 -0400 Subject: [PATCH] crypto/tls: add VersionName Fixes #46308 Change-Id: I5162b26cbce61ae5df5d2e093cf8a28406d15863 Reviewed-on: https://go-review.googlesource.com/c/go/+/497377 Auto-Submit: Filippo Valsorda Reviewed-by: Marten Seemann Reviewed-by: Roland Shoemaker Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Samuli Silvius Reviewed-by: Damien Neil Run-TryBot: Filippo Valsorda --- common.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/common.go b/common.go index 966a487..c801535 100644 --- a/common.go +++ b/common.go @@ -36,6 +36,26 @@ const ( VersionSSL30 = 0x0300 ) +// VersionName returns the name for the provided TLS version number +// (e.g. "TLS 1.3"), or a fallback representation of the value if the +// version is not implemented by this package. +func VersionName(version uint16) string { + switch version { + case VersionSSL30: + return "SSLv3" + case VersionTLS10: + return "TLS 1.0" + case VersionTLS11: + return "TLS 1.1" + case VersionTLS12: + return "TLS 1.2" + case VersionTLS13: + return "TLS 1.3" + default: + return fmt.Sprintf("0x%04X", version) + } +} + const ( maxPlaintext = 16384 // maximum plaintext payload length maxCiphertext = 16384 + 2048 // maximum ciphertext payload length