mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-04-28 17:10:14 +08:00
Merge pull request #33 from libp2p/bug/curve-name
Return error rather than panic in GenerateEKeyPair
This commit is contained in:
commit
1d45af25d9
crypto
@ -143,6 +143,8 @@ func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error) {
|
||||
curve = elliptic.P384()
|
||||
case "P-521":
|
||||
curve = elliptic.P521()
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("unknown curve name")
|
||||
}
|
||||
|
||||
priv, x, y, err := elliptic.GenerateKey(curve, rand.Reader)
|
||||
|
@ -145,3 +145,15 @@ func (pk testkey) Raw() ([]byte, error) {
|
||||
func (pk testkey) Equals(k Key) bool {
|
||||
return KeyEqual(pk, k)
|
||||
}
|
||||
|
||||
func TestUnknownCurveErrors(t *testing.T) {
|
||||
_, _, err := GenerateEKeyPair("P-256")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, _, err = GenerateEKeyPair("error-please")
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid key type to error")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user