Skip to content

Commit

Permalink
error when seed is too short
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Oct 17, 2023
1 parent f320981 commit 0c5c370
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/ed25519"
crand "crypto/rand"
"crypto/sha256"
"errors"
"io"

libp2p "github.com/libp2p/go-libp2p/core/crypto"
Expand All @@ -29,6 +30,9 @@ func deriveKey(b58secret string, info []byte) (libp2p.PrivKey, error) {
if err != nil {
return nil, err
}
if len(secret) < seedBytes {
return nil, errors.New("derivation seed is too short")
}

Check warning on line 35 in keys.go

View check run for this annotation

Codecov / codecov/patch

keys.go#L28-L35

Added lines #L28 - L35 were not covered by tests

hash := sha256.New
hkdf := hkdf.New(hash, secret, nil, info)
Expand Down

0 comments on commit 0c5c370

Please sign in to comment.