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-dms3ns
Commits
3b408d34
Commit
3b408d34
authored
6 years ago
by
potsables
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates tests and examples as per Stebalien's comment
parent
7651b3ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
30 deletions
+18
-30
examples/examples_test.go
examples/examples_test.go
+11
-12
examples/key.go
examples/key.go
+7
-18
No files found.
examples/examples_test.go
View file @
3b408d34
...
...
@@ -3,7 +3,8 @@ package examples_test
import
(
"testing"
"github.com/ipfs/go-ipns/examples"
"github.com/RTradeLtd/go-ipns/examples"
crypto
"github.com/libp2p/go-libp2p-crypto"
)
var
testPath
=
"/ipfs/Qme1knMqwt1hKZbc1BmQFmnm9f36nyQGwXxPGVpVJ9rMK5"
...
...
@@ -30,34 +31,32 @@ func TestEmbeddedEntryCreation(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
examples
.
CreateEntryWithEmbed
(
testPath
,
rk
.
Public
,
rk
.
Private
)
_
,
err
=
examples
.
CreateEntryWithEmbed
(
testPath
,
rk
.
GetPublic
(),
rk
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
_
,
err
=
examples
.
CreateEntryWithEmbed
(
testPath
,
ek
.
Public
,
ek
.
Private
)
_
,
err
=
examples
.
CreateEntryWithEmbed
(
testPath
,
ek
.
Get
Public
()
,
ek
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
generateRSAKey
()
(
*
examples
.
KeyPair
,
error
)
{
func
generateRSAKey
()
(
crypto
.
PrivKey
,
error
)
{
// DO NOT USE 1024 BITS IN PRODUCTION
// THIS IS ONLY FOR TESTING PURPOSES
k
p
,
err
:=
examples
.
GenerateRSAKeyPair
(
1024
)
k
,
err
:=
examples
.
GenerateRSAKeyPair
(
1024
)
if
err
!=
nil
{
return
nil
,
err
}
return
k
p
,
nil
return
k
,
nil
}
func
generateEDKey
()
(
*
examples
.
KeyPair
,
error
)
{
// DO NOT USE 1024 BITS IN PRODUCTION
// THIS IS ONLY FOR TESTING PURPOSES
kp
,
err
:=
examples
.
GenerateEDKeyPair
(
1024
)
func
generateEDKey
()
(
crypto
.
PrivKey
,
error
)
{
// ED25519 uses 256bit keys, and ignore the bit param
k
,
err
:=
examples
.
GenerateEDKeyPair
()
if
err
!=
nil
{
return
nil
,
err
}
return
k
p
,
nil
return
k
,
nil
}
This diff is collapsed.
Click to expand it.
examples/key.go
View file @
3b408d34
...
...
@@ -4,32 +4,21 @@ import (
crypto
"github.com/libp2p/go-libp2p-crypto"
)
// KeyPair is a helper struct used to contain the parts of a key
type
KeyPair
struct
{
Private
crypto
.
PrivKey
Public
crypto
.
PubKey
}
// GenerateRSAKeyPair is used to generate an RSA key pair
func
GenerateRSAKeyPair
(
bits
int
)
(
*
KeyPair
,
error
)
{
var
kp
KeyPair
priv
,
pub
,
err
:=
crypto
.
GenerateKeyPair
(
crypto
.
RSA
,
bits
)
func
GenerateRSAKeyPair
(
bits
int
)
(
crypto
.
PrivKey
,
error
)
{
priv
,
_
,
err
:=
crypto
.
GenerateKeyPair
(
crypto
.
RSA
,
bits
)
if
err
!=
nil
{
return
nil
,
err
}
kp
.
Private
=
priv
kp
.
Public
=
pub
return
&
kp
,
nil
return
priv
,
nil
}
// GenerateEDKeyPair is used to generate an ED25519 keypair
func
GenerateEDKeyPair
(
bits
int
)
(
*
KeyPair
,
error
)
{
var
kp
KeyPair
priv
,
pub
,
err
:=
crypto
.
GenerateKeyPair
(
crypto
.
Ed25519
,
bits
)
func
GenerateEDKeyPair
(
)
(
crypto
.
PrivKey
,
error
)
{
// ED25519 ignores the bit param and uses 256bit keys
priv
,
_
,
err
:=
crypto
.
GenerateKeyPair
(
crypto
.
Ed25519
,
256
)
if
err
!=
nil
{
return
nil
,
err
}
kp
.
Private
=
priv
kp
.
Public
=
pub
return
&
kp
,
nil
return
priv
,
nil
}
This diff is collapsed.
Click to expand it.
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