Skip to content

Commit 74e8448

Browse files
add VersionName present in go tls library (#468)
Co-authored-by: Phillip Stephens <phillip@cs.stanford.edu>
1 parent 44a7148 commit 74e8448

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tls/common.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ const (
4242
VersionSSL30 = 0x0300
4343
)
4444

45+
// VersionName returns the name for the provided TLS version number
46+
// (e.g. "TLS 1.3"), or a fallback representation of the value if the
47+
// version is not implemented by this package.
48+
func VersionName(version uint16) string {
49+
switch version {
50+
case VersionSSL30:
51+
return "SSLv3"
52+
case VersionTLS10:
53+
return "TLS 1.0"
54+
case VersionTLS11:
55+
return "TLS 1.1"
56+
case VersionTLS12:
57+
return "TLS 1.2"
58+
case VersionTLS13:
59+
return "TLS 1.3"
60+
default:
61+
return fmt.Sprintf("0x%04X", version)
62+
}
63+
}
64+
4565
const (
4666
maxPlaintext = 16384 // maximum plaintext payload length
4767
maxCiphertext = 16384 + 2048 // maximum ciphertext payload length

0 commit comments

Comments
 (0)