Skip to content

Commit b6ede55

Browse files
jsvisadevopsbo3
authored andcommitted
crypto: replace noarg fmt.Errorf with errors.New (ethereum#27333)
Signed-off-by: jsvisa <[email protected]>
1 parent 5d27acd commit b6ede55

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

crypto/crypto.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
141141

142142
// The priv.D must < N
143143
if priv.D.Cmp(secp256k1N) >= 0 {
144-
return nil, fmt.Errorf("invalid private key, >=N")
144+
return nil, errors.New("invalid private key, >=N")
145145
}
146146
// The priv.D must not be zero or negative.
147147
if priv.D.Sign() <= 0 {
148-
return nil, fmt.Errorf("invalid private key, zero or negative")
148+
return nil, errors.New("invalid private key, zero or negative")
149149
}
150150

151151
priv.PublicKey.X, priv.PublicKey.Y = priv.PublicKey.Curve.ScalarBaseMult(d)
@@ -204,7 +204,7 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
204204
if err != nil {
205205
return nil, err
206206
} else if n != len(buf) {
207-
return nil, fmt.Errorf("key file too short, want 64 hex characters")
207+
return nil, errors.New("key file too short, want 64 hex characters")
208208
}
209209
if err := checkKeyFileEnd(r); err != nil {
210210
return nil, err

crypto/ecies/ecies.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ import (
3636
"crypto/hmac"
3737
"crypto/subtle"
3838
"encoding/binary"
39-
"fmt"
39+
"errors"
4040
"hash"
4141
"io"
4242
"math/big"
4343
)
4444

4545
var (
46-
ErrImport = fmt.Errorf("ecies: failed to import key")
47-
ErrInvalidCurve = fmt.Errorf("ecies: invalid elliptic curve")
48-
ErrInvalidPublicKey = fmt.Errorf("ecies: invalid public key")
49-
ErrSharedKeyIsPointAtInfinity = fmt.Errorf("ecies: shared key is point at infinity")
50-
ErrSharedKeyTooBig = fmt.Errorf("ecies: shared key params are too big")
46+
ErrImport = errors.New("ecies: failed to import key")
47+
ErrInvalidCurve = errors.New("ecies: invalid elliptic curve")
48+
ErrInvalidPublicKey = errors.New("ecies: invalid public key")
49+
ErrSharedKeyIsPointAtInfinity = errors.New("ecies: shared key is point at infinity")
50+
ErrSharedKeyTooBig = errors.New("ecies: shared key params are too big")
5151
)
5252

5353
// PublicKey is a representation of an elliptic curve public key.
@@ -138,8 +138,8 @@ func (prv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []b
138138
}
139139

140140
var (
141-
ErrSharedTooLong = fmt.Errorf("ecies: shared secret is too long")
142-
ErrInvalidMessage = fmt.Errorf("ecies: invalid message")
141+
ErrSharedTooLong = errors.New("ecies: shared secret is too long")
142+
ErrInvalidMessage = errors.New("ecies: invalid message")
143143
)
144144

145145
// NIST SP 800-56 Concatenation Key Derivation Function (see section 5.8.1).

crypto/ecies/ecies_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"crypto/rand"
3636
"crypto/sha256"
3737
"encoding/hex"
38-
"fmt"
38+
"errors"
3939
"math/big"
4040
"testing"
4141

@@ -62,7 +62,7 @@ func TestKDF(t *testing.T) {
6262
}
6363
}
6464

65-
var ErrBadSharedKeys = fmt.Errorf("ecies: shared keys don't match")
65+
var ErrBadSharedKeys = errors.New("ecies: shared keys don't match")
6666

6767
// cmpParams compares a set of ECIES parameters. We assume, as per the
6868
// docs, that AES is the only supported symmetric encryption algorithm.

crypto/ecies/params.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"crypto/elliptic"
4040
"crypto/sha256"
4141
"crypto/sha512"
42+
"errors"
4243
"fmt"
4344
"hash"
4445

@@ -47,8 +48,8 @@ import (
4748

4849
var (
4950
DefaultCurve = ethcrypto.S256()
50-
ErrUnsupportedECDHAlgorithm = fmt.Errorf("ecies: unsupported ECDH algorithm")
51-
ErrUnsupportedECIESParameters = fmt.Errorf("ecies: unsupported ECIES parameters")
51+
ErrUnsupportedECDHAlgorithm = errors.New("ecies: unsupported ECDH algorithm")
52+
ErrUnsupportedECIESParameters = errors.New("ecies: unsupported ECIES parameters")
5253
ErrInvalidKeyLen = fmt.Errorf("ecies: invalid key size (> %d) in ECIESParams", maxKeyLen)
5354
)
5455

crypto/signature_cgo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package crypto
2222
import (
2323
"crypto/ecdsa"
2424
"crypto/elliptic"
25+
"errors"
2526
"fmt"
2627

2728
"github.com/ethereum/go-ethereum/common/math"
@@ -72,7 +73,7 @@ func VerifySignature(pubkey, digestHash, signature []byte) bool {
7273
func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error) {
7374
x, y := secp256k1.DecompressPubkey(pubkey)
7475
if x == nil {
75-
return nil, fmt.Errorf("invalid public key")
76+
return nil, errors.New("invalid public key")
7677
}
7778
return &ecdsa.PublicKey{X: x, Y: y, Curve: S256()}, nil
7879
}

crypto/signature_nocgo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error) {
7474
return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash))
7575
}
7676
if prv.Curve != btcec.S256() {
77-
return nil, fmt.Errorf("private key curve is not secp256k1")
77+
return nil, errors.New("private key curve is not secp256k1")
7878
}
7979
// ecdsa.PrivateKey -> btcec.PrivateKey
8080
var priv btcec.PrivateKey
8181
if overflow := priv.Key.SetByteSlice(prv.D.Bytes()); overflow || priv.Key.IsZero() {
82-
return nil, fmt.Errorf("invalid private key")
82+
return nil, errors.New("invalid private key")
8383
}
8484
defer priv.Zero()
8585
sig, err := btc_ecdsa.SignCompact(&priv, hash, false) // ref uncompressed pubkey

0 commit comments

Comments
 (0)