mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 13:41:47 +00:00
keys: don't panic if signature has invalid size
This commit is contained in:
parent
9733a6f394
commit
0a596e1df2
2 changed files with 4 additions and 1 deletions
|
@ -333,7 +333,7 @@ func (p *PublicKey) Address() string {
|
|||
// Verify returns true if the signature is valid and corresponds
|
||||
// to the hash and public key.
|
||||
func (p *PublicKey) Verify(signature []byte, hash []byte) bool {
|
||||
if p.X == nil || p.Y == nil {
|
||||
if p.X == nil || p.Y == nil || len(signature) != 64 {
|
||||
return false
|
||||
}
|
||||
rBytes := new(big.Int).SetBytes(signature[0:32])
|
||||
|
|
|
@ -52,6 +52,9 @@ func TestPubKeyVerify(t *testing.T) {
|
|||
expected := true
|
||||
assert.Equal(t, expected, result)
|
||||
|
||||
// Small signature, no panic.
|
||||
assert.False(t, pubKey.Verify([]byte{1, 2, 3}, hashedData.BytesBE()))
|
||||
|
||||
pubKey = &PublicKey{}
|
||||
assert.False(t, pubKey.Verify(signedData, hashedData.BytesBE()))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue