Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-core
Commits
1d45af25
Unverified
Commit
1d45af25
authored
Jul 12, 2019
by
bigs
Committed by
GitHub
Jul 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #33 from libp2p/bug/curve-name
Return error rather than panic in GenerateEKeyPair
parents
c3f7bb21
c7c0a1cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
crypto/key.go
crypto/key.go
+2
-0
crypto/key_test.go
crypto/key_test.go
+12
-0
No files found.
crypto/key.go
View file @
1d45af25
...
...
@@ -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
)
...
...
crypto/key_test.go
View file @
1d45af25
...
...
@@ -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"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment