小编rak*_*koo的帖子

Golang:给定其值的常量的名称

你如何得到一个常数的名称给它的价值?

更具体地说(为了获得更易读的理解),我正在使用该crypto/tls软件包.密码套件定义为常量:

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
)
Run Code Online (Sandbox Code Playgroud)

在与服务器成功握手后,我可以通过连接与Ciphersuite达成一致:

c, _ := tls.Dial("tcp", "somedomain.com:443", nil)
// Suppose everything went right

// This is the Ciphersuite for the conn:
cipher := c.ConnectionState().Ciphersuite
Run Code Online (Sandbox Code Playgroud)

cipher这是一个uint16.有没有办法将其显示为字符串,例如,TLS_RSA_WITH_3DES_EDE_CBC_SHA如果这是商定的?

go

19
推荐指数
3
解决办法
1万
查看次数

标签 统计

go ×1