1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

internal/tlsconst: Add a package with TLS constants

There are a couple of places where it's handy to print TLS constants in
human-readable form.

To do so, we need functions that take TLS constants (usually in uint16 form)
and give us friendly strings.

Go's crypto/tls package does not provide us with this, so this patch
introduces a new module with that purpose.
This commit is contained in:
Alberto Bertogli
2016-10-01 14:04:10 +01:00
parent e138f0dc05
commit 16d9d45e06
3 changed files with 420 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
// Package tlsconst contains TLS constants for human consumption.
package tlsconst
// Most of the constants get automatically generated from IANA's assignments.
//go:generate ./generate-ciphers.py ciphers.go
import "fmt"
var versionName = map[uint16]string{
0x0300: "SSL-3.0",
0x0301: "TLS-1.0",
0x0302: "TLS-1.1",
0x0303: "TLS-1.2",
}
// VersionName returns a human-readable TLS version name.
func VersionName(v uint16) string {
name, ok := versionName[v]
if !ok {
return fmt.Sprintf("TLS-%#04x", v)
}
return name
}
// CipherSuiteName returns a human-readable TLS cipher suite name.
func CipherSuiteName(s uint16) string {
name, ok := cipherSuiteName[s]
if !ok {
return fmt.Sprintf("TLS_UNKNOWN_CIPHER_SUITE-%#04x", s)
}
return name
}