How do you get the name of a constant given its value ?
More specifically (and to get a more readable understanding), I’m working with the
crypto/tls package. Cipher suites are defined as constants:
const ( TLS_RSA_WITH_RC4_128_SHA uint16 = 0x0005 TLS_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0x000a TLS_RSA_WITH_AES_128_CBC_SHA uint16 = 0x002f TLS_RSA_WITH_AES_256_CBC_SHA uint16 = 0x0035 TLS_ECDHE_RSA_WITH_RC4_128_SHA uint16 = 0xc011 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0xc012 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA uint16 = 0xc013 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA uint16 = 0xc014 )
After a successful handshake with a server, I can get to the Ciphersuite agreed on through the connection:
c, _ := tls.Dial("tcp", "somedomain.com:443", nil) // Suppose everything went right // This is the Ciphersuite for the conn: cipher := c.ConnectionState().Ciphersuite
cipher here is an uint16. Is there a way to display it as a string, for instance
TLS_RSA_WITH_3DES_EDE_CBC_SHA if that’s what was agreed upon ?