diff --git a/pubkey.go b/pubkey.go index 070bbc295..72772809c 100644 --- a/pubkey.go +++ b/pubkey.go @@ -6,6 +6,7 @@ package btcec import ( "crypto/ecdsa" + "errors" "fmt" "math/big" ) @@ -53,6 +54,10 @@ func ParsePubKey(pubKeyStr []byte, curve *KoblitzCurve) (key *ecdsa.PublicKey, e pubkey := ecdsa.PublicKey{} pubkey.Curve = curve + if len(pubKeyStr) == 0 { + return nil, errors.New("pubkey string is empty") + } + format := pubKeyStr[0] ybit := (format & 0x1) == 0x1 format &= ^byte(0x1)