X Tutup
Skip to content

Commit 0e9ac0c

Browse files
authored
Use bytes.Equal instead of bytes.Compare == 0 (letsencrypt#4758)
staticcheck cleanup: https://staticcheck.io/docs/checks#S1004
1 parent de8855f commit 0e9ac0c

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

cmd/boulder-wfe2/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestLoadCertificateChains(t *testing.T) {
184184
test.AssertEquals(t, len(resultMap), len(tc.ExpectedMap))
185185
test.AssertEquals(t, len(issuers), len(tc.ExpectedMap))
186186
for url, chain := range resultMap {
187-
test.Assert(t, bytes.Compare(chain, tc.ExpectedMap[url]) == 0, "Chain bytes did not match expected")
187+
test.Assert(t, bytes.Equal(chain, tc.ExpectedMap[url]), "Chain bytes did not match expected")
188188
}
189189
})
190190
}

cmd/ceremony/cert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ func newSigner(ctx pkcs11helpers.PKCtx, session pkcs11.SessionHandle, label stri
296296
var keyType pkcs11helpers.KeyType
297297
switch {
298298
// 0x00000000, CKK_RSA
299-
case bytes.Compare(attrs[0].Value, []byte{0, 0, 0, 0, 0, 0, 0, 0}) == 0:
299+
case bytes.Equal(attrs[0].Value, []byte{0, 0, 0, 0, 0, 0, 0, 0}):
300300
keyType = pkcs11helpers.RSAKey
301301
pub, err = pkcs11helpers.GetRSAPublicKey(ctx, session, pubHandle)
302302
if err != nil {
303303
return nil, fmt.Errorf("failed to retrieve public key: %s", err)
304304
}
305305
// 0x00000003, CKK_ECDSA
306-
case bytes.Compare(attrs[0].Value, []byte{3, 0, 0, 0, 0, 0, 0, 0}) == 0:
306+
case bytes.Equal(attrs[0].Value, []byte{3, 0, 0, 0, 0, 0, 0, 0}):
307307
keyType = pkcs11helpers.ECDSAKey
308308
pub, err = pkcs11helpers.GetECDSAPublicKey(ctx, session, pubHandle)
309309
if err != nil {

cmd/ceremony/cert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func TestGetKey(t *testing.T) {
299299
return []*pkcs11.Attribute{pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_EC)}, nil
300300
}
301301
ctx.FindObjectsInitFunc = func(_ pkcs11.SessionHandle, tmpl []*pkcs11.Attribute) error {
302-
if bytes.Compare(tmpl[0].Value, []byte{2, 0, 0, 0, 0, 0, 0, 0}) == 0 {
302+
if bytes.Equal(tmpl[0].Value, []byte{2, 0, 0, 0, 0, 0, 0, 0}) {
303303
return errors.New("broken")
304304
}
305305
return nil

cmd/key-hash-backfill/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestBackfill(t *testing.T) {
102102
test.AssertEquals(t, keyHashes[0].CertNotAfter, expires)
103103
test.AssertEquals(t, keyHashes[1].CertNotAfter, expires)
104104
test.AssertEquals(t, keyHashes[2].CertNotAfter, expires)
105-
test.Assert(t, bytes.Compare(keyHashes[0].KeyHash, spkiHash[:]) == 0, "SPKI hash mismatch")
106-
test.Assert(t, bytes.Compare(keyHashes[1].KeyHash, spkiHash[:]) == 0, "SPKI hash mismatch")
107-
test.Assert(t, bytes.Compare(keyHashes[2].KeyHash, spkiHash[:]) == 0, "SPKI hash mismatch")
105+
test.Assert(t, bytes.Equal(keyHashes[0].KeyHash, spkiHash[:]), "SPKI hash mismatch")
106+
test.Assert(t, bytes.Equal(keyHashes[1].KeyHash, spkiHash[:]), "SPKI hash mismatch")
107+
test.Assert(t, bytes.Equal(keyHashes[2].KeyHash, spkiHash[:]), "SPKI hash mismatch")
108108
}

cmd/ocsp-responder/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type dbResponse struct {
8686
// Response is called by the HTTP server to handle a new OCSP request.
8787
func (src *DBSource) Response(req *ocsp.Request) ([]byte, http.Header, error) {
8888
// Check that this request is for the proper CA
89-
if bytes.Compare(req.IssuerKeyHash, src.caKeyHash) != 0 {
89+
if !bytes.Equal(req.IssuerKeyHash, src.caKeyHash) {
9090
src.log.Debugf("Request intended for CA Cert ID: %s", hex.EncodeToString(req.IssuerKeyHash))
9191
return nil, nil, bocsp.ErrNotFound
9292
}

0 commit comments

Comments
 (0)
X Tutup