From bd93c59baed3a658f6ff29d1af60b8789a4bd9f5 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Fri, 29 Nov 2024 16:08:31 +0800 Subject: [PATCH] crypto: replace noarg fmt.Errorf with errors.New (#27333) --- crypto/signature_cgo.go | 3 ++- crypto/signature_nocgo.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crypto/signature_cgo.go b/crypto/signature_cgo.go index c33cd0094b..6811657503 100644 --- a/crypto/signature_cgo.go +++ b/crypto/signature_cgo.go @@ -22,6 +22,7 @@ package crypto import ( "crypto/ecdsa" "crypto/elliptic" + "errors" "fmt" "github.com/XinFinOrg/XDPoSChain/common/math" @@ -72,7 +73,7 @@ func VerifySignature(pubkey, digestHash, signature []byte) bool { func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error) { x, y := secp256k1.DecompressPubkey(pubkey) if x == nil { - return nil, fmt.Errorf("invalid public key") + return nil, errors.New("invalid public key") } return &ecdsa.PublicKey{X: x, Y: y, Curve: S256()}, nil } diff --git a/crypto/signature_nocgo.go b/crypto/signature_nocgo.go index 3e48e51e84..6d628d758d 100644 --- a/crypto/signature_nocgo.go +++ b/crypto/signature_nocgo.go @@ -74,12 +74,12 @@ func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error) { return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash)) } if prv.Curve != btcec.S256() { - return nil, fmt.Errorf("private key curve is not secp256k1") + return nil, errors.New("private key curve is not secp256k1") } // ecdsa.PrivateKey -> btcec.PrivateKey var priv btcec.PrivateKey if overflow := priv.Key.SetByteSlice(prv.D.Bytes()); overflow || priv.Key.IsZero() { - return nil, fmt.Errorf("invalid private key") + return nil, errors.New("invalid private key") } defer priv.Zero() sig, err := btc_ecdsa.SignCompact(&priv, hash, false) // ref uncompressed pubkey