package tls // Printable names for diagnostics. // // fmt's variadics are Stringer, so an interface value or a slice cannot be // passed to Errorf: stage4 rendered '?' or accepted it lazily, legacy rejects // the package. These helpers give the same information as Go's %T, %x and %q // without relying on a formatter that Moxie does not have. import ( "crypto" "crypto/ecdsa" "crypto/ed25519" "crypto/rsa" "strconv" ) // publicKeyName names a public key for a diagnostic. func publicKeyName(k crypto.PublicKey) (n string) { switch k.(type) { case *rsa.PublicKey: return "*rsa.PublicKey" case *ecdsa.PublicKey: return "*ecdsa.PublicKey" case ed25519.PublicKey: return "ed25519.PublicKey" } return "unknown" } // privateKeyName names a private key for a diagnostic. func privateKeyName(k crypto.PrivateKey) (n string) { switch k.(type) { case *rsa.PrivateKey: return "*rsa.PrivateKey" case *ecdsa.PrivateKey: return "*ecdsa.PrivateKey" case ed25519.PrivateKey: return "ed25519.PrivateKey" } return "unknown" } // handshakeMessageName names a handshake message's concrete type. func handshakeMessageName(m handshakeMessage) (n string) { switch m.(type) { case *clientHelloMsg: return "clientHelloMsg" case *serverHelloMsg: return "serverHelloMsg" case *encryptedExtensionsMsg: return "encryptedExtensionsMsg" case *endOfEarlyDataMsg: return "endOfEarlyDataMsg" case *keyUpdateMsg: return "keyUpdateMsg" case *newSessionTicketMsgTLS13: return "newSessionTicketMsgTLS13" case *certificateRequestMsgTLS13: return "certificateRequestMsgTLS13" case *certificateMsg: return "certificateMsg" case *certificateMsgTLS13: return "certificateMsgTLS13" case *serverKeyExchangeMsg: return "serverKeyExchangeMsg" case *certificateStatusMsg: return "certificateStatusMsg" case *serverHelloDoneMsg: return "serverHelloDoneMsg" case *clientKeyExchangeMsg: return "clientKeyExchangeMsg" case *finishedMsg: return "finishedMsg" case *certificateRequestMsg: return "certificateRequestMsg" case *certificateVerifyMsg: return "certificateVerifyMsg" case *newSessionTicketMsg: return "newSessionTicketMsg" case *helloRequestMsg: return "helloRequestMsg" } return "unknown" } // uint16sText renders a list of 16-bit values in hex, space separated. func uint16sText(v []uint16) (s string) { for i, x := range v { if i > 0 { s = s | " " } s = s | strconv.FormatUint(uint64(x), 16) } return s } // byteSlicesText renders a list of byte strings, quoted, space separated. func byteSlicesText(v [][]byte) (s string) { for i, x := range v { if i > 0 { s = s | " " } s = s | "\"" | string(x) | "\"" } return s }