我正在测试x509 证书验证示例,这(来自示例)有效:const rootPEM = `-----BEGIN CERTIFICATE-----MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT. . .yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx-----END CERTIFICATE-----`const certPEM = `-----BEGIN CERTIFICATE-----MIIDujCCAqKgAwIBAgIIE31FZVaPXTUwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE. . .yE+vPxsiUkvQHdO2fojCkY8jg70jxM+gu59tPDNbw3Uh/2Ij310FgTHsnGQMyA==-----END CERTIFICATE-----`但这不会:const ( rootPEM = ` -----BEGIN CERTIFICATE----- MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT . . . yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx -----END CERTIFICATE-----` certPEM = ` -----BEGIN CERTIFICATE----- MIIDujCCAqKgAwIBAgIIE31FZVaPXTUwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE . . . yE+vPxsiUkvQHdO2fojCkY8jg70jxM+gu59tPDNbw3Uh/2Ij310FgTHsnGQMyA== -----END CERTIFICATE-----`)使用常量块/组时有什么变化?(就这个例子而言,它在panic: failed to parse root certificate使用常量块时失败了)
1 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
“没有”变化,除了你的分组变体是缩进的,所以这意味着原始字符串文字的所有行都以制表符或空格开头,证书解析器可能会冒犯这些。
像这样尝试:
const (
rootPEM = `
-----BEGIN CERTIFICATE-----
MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
. . .
yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx
-----END CERTIFICATE-----`
certPEM = `
-----BEGIN CERTIFICATE-----
MIIDujCCAqKgAwIBAgIIE31FZVaPXTUwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
. . .
yE+vPxsiUkvQHdO2fojCkY8jg70jxM+gu59tPDNbw3Uh/2Ij310FgTHsnGQMyA==
-----END CERTIFICATE-----`
)
(注意:多行原始字符串文字没有缩进。)
- 1 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消