Skip to content

Commit efc832b

Browse files
committed
crypto/tls: add {SignatureScheme,CurveID,ClientAuthType}.String()
Fixes #35499 Change-Id: Ieb487782f389f6d80e8f68ee980e584d906cb4da Reviewed-on: https://go-review.googlesource.com/c/go/+/208226 Run-TryBot: Filippo Valsorda <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Katie Hockman <[email protected]>
1 parent f6a0d72 commit efc832b

File tree

4 files changed

+127
-9
lines changed

4 files changed

+127
-9
lines changed

src/crypto/tls/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func typeAndHashFromSignatureScheme(signatureAlgorithm SignatureScheme) (sigType
106106
case Ed25519:
107107
sigType = signatureEd25519
108108
default:
109-
return 0, 0, fmt.Errorf("unsupported signature algorithm: %#04x", signatureAlgorithm)
109+
return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm)
110110
}
111111
switch signatureAlgorithm {
112112
case PKCS1WithSHA1, ECDSAWithSHA1:
@@ -120,7 +120,7 @@ func typeAndHashFromSignatureScheme(signatureAlgorithm SignatureScheme) (sigType
120120
case Ed25519:
121121
hash = directSigning
122122
default:
123-
return 0, 0, fmt.Errorf("unsupported signature algorithm: %#04x", signatureAlgorithm)
123+
return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm)
124124
}
125125
return sigType, hash, nil
126126
}

src/crypto/tls/auth_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestSignatureSelection(t *testing.T) {
6262
t.Errorf("test[%d]: unexpected selectSignatureScheme error: %v", testNo, err)
6363
}
6464
if test.expectedSigAlg != sigAlg {
65-
t.Errorf("test[%d]: expected signature scheme %#x, got %#x", testNo, test.expectedSigAlg, sigAlg)
65+
t.Errorf("test[%d]: expected signature scheme %v, got %v", testNo, test.expectedSigAlg, sigAlg)
6666
}
6767
sigType, hashFunc, err := typeAndHashFromSignatureScheme(sigAlg)
6868
if err != nil {
@@ -115,7 +115,7 @@ func TestSignatureSelection(t *testing.T) {
115115
for testNo, test := range badTests {
116116
sigAlg, err := selectSignatureScheme(test.tlsVersion, test.cert, test.peerSigAlgs)
117117
if err == nil {
118-
t.Errorf("test[%d]: unexpected success, got %#x", testNo, sigAlg)
118+
t.Errorf("test[%d]: unexpected success, got %v", testNo, sigAlg)
119119
}
120120
}
121121
}
@@ -129,7 +129,7 @@ func TestLegacyTypeAndHash(t *testing.T) {
129129
t.Errorf("RSA: expected signature type %#x, got %#x", expectedSigType, sigType)
130130
}
131131
if expectedHashFunc := crypto.MD5SHA1; expectedHashFunc != hashFunc {
132-
t.Errorf("RSA: expected hash %#x, got %#x", expectedHashFunc, sigType)
132+
t.Errorf("RSA: expected hash %#x, got %#x", expectedHashFunc, hashFunc)
133133
}
134134

135135
sigType, hashFunc, err = legacyTypeAndHashFromPublicKey(testECDSAPrivateKey.Public())
@@ -140,7 +140,7 @@ func TestLegacyTypeAndHash(t *testing.T) {
140140
t.Errorf("ECDSA: expected signature type %#x, got %#x", expectedSigType, sigType)
141141
}
142142
if expectedHashFunc := crypto.SHA1; expectedHashFunc != hashFunc {
143-
t.Errorf("ECDSA: expected hash %#x, got %#x", expectedHashFunc, sigType)
143+
t.Errorf("ECDSA: expected hash %#x, got %#x", expectedHashFunc, hashFunc)
144144
}
145145

146146
// Ed25519 is not supported by TLS 1.0 and 1.1.
@@ -156,13 +156,13 @@ func TestSupportedSignatureAlgorithms(t *testing.T) {
156156
for _, sigAlg := range supportedSignatureAlgorithms {
157157
sigType, hash, err := typeAndHashFromSignatureScheme(sigAlg)
158158
if err != nil {
159-
t.Errorf("%#04x: unexpected error: %v", sigAlg, err)
159+
t.Errorf("%v: unexpected error: %v", sigAlg, err)
160160
}
161161
if sigType == 0 {
162-
t.Errorf("%#04x: missing signature type", sigAlg)
162+
t.Errorf("%v: missing signature type", sigAlg)
163163
}
164164
if hash == 0 && sigAlg != Ed25519 {
165-
t.Errorf("%#04x: missing hash", sigAlg)
165+
t.Errorf("%v: missing hash", sigAlg)
166166
}
167167
}
168168
}

src/crypto/tls/common.go

+2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ type ClientSessionCache interface {
299299
Put(sessionKey string, cs *ClientSessionState)
300300
}
301301

302+
//go:generate stringer -type=SignatureScheme,CurveID,ClientAuthType -output=common_string.go
303+
302304
// SignatureScheme identifies a signature algorithm supported by TLS. See
303305
// RFC 8446, Section 4.2.3.
304306
type SignatureScheme uint16

src/crypto/tls/common_string.go

+116
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)