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
dms3
go-unixfs
Commits
d5239945
Commit
d5239945
authored
Sep 14, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for crypto package (issue #59, improve code coverage)
parent
0ec9dce1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
crypto/key_test.go
crypto/key_test.go
+54
-0
No files found.
crypto/key_test.go
0 → 100644
View file @
d5239945
package
crypto
import
"testing"
func
TestRsaKeys
(
t
*
testing
.
T
)
{
sk
,
_
,
err
:=
GenerateKeyPair
(
RSA
,
512
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
testKeySignature
(
t
,
sk
)
testKeyEncoding
(
t
,
sk
)
}
func
testKeySignature
(
t
*
testing
.
T
,
sk
PrivKey
)
{
pk
:=
sk
.
GetPublic
()
text
:=
sk
.
GenSecret
()
sig
,
err
:=
sk
.
Sign
(
text
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
valid
,
err
:=
pk
.
Verify
(
text
,
sig
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
valid
{
t
.
Fatal
(
"Invalid signature."
)
}
}
func
testKeyEncoding
(
t
*
testing
.
T
,
sk
PrivKey
)
{
skb
,
err
:=
sk
.
Bytes
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
UnmarshalPrivateKey
(
skb
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pk
:=
sk
.
GetPublic
()
pkb
,
err
:=
pk
.
Bytes
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
UnmarshalPublicKey
(
pkb
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
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