mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
crypto: replace noarg fmt.Errorf with errors.New (#27333)
This commit is contained in:
parent
ed03a99770
commit
bd93c59bae
2 changed files with 4 additions and 3 deletions
|
|
@ -22,6 +22,7 @@ package crypto
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common/math"
|
"github.com/XinFinOrg/XDPoSChain/common/math"
|
||||||
|
|
@ -72,7 +73,7 @@ func VerifySignature(pubkey, digestHash, signature []byte) bool {
|
||||||
func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error) {
|
func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error) {
|
||||||
x, y := secp256k1.DecompressPubkey(pubkey)
|
x, y := secp256k1.DecompressPubkey(pubkey)
|
||||||
if x == nil {
|
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
|
return &ecdsa.PublicKey{X: x, Y: y, Curve: S256()}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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))
|
return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash))
|
||||||
}
|
}
|
||||||
if prv.Curve != btcec.S256() {
|
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
|
// ecdsa.PrivateKey -> btcec.PrivateKey
|
||||||
var priv btcec.PrivateKey
|
var priv btcec.PrivateKey
|
||||||
if overflow := priv.Key.SetByteSlice(prv.D.Bytes()); overflow || priv.Key.IsZero() {
|
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()
|
defer priv.Zero()
|
||||||
sig, err := btc_ecdsa.SignCompact(&priv, hash, false) // ref uncompressed pubkey
|
sig, err := btc_ecdsa.SignCompact(&priv, hash, false) // ref uncompressed pubkey
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue