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
d7779be9
Commit
d7779be9
authored
6 years ago
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add an explicit test case for the EmbedPublicKey function
parent
130e692f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
ipns.go
ipns.go
+5
-0
ipns_test.go
ipns_test.go
+43
-0
No files found.
ipns.go
View file @
d7779be9
...
...
@@ -68,6 +68,8 @@ func GetEOL(entry *pb.IpnsEntry) (time.Time, error) {
// that don't embed their public keys as they may not be able to validate them
// efficiently.
func
EmbedPublicKey
(
pk
ic
.
PubKey
,
entry
*
pb
.
IpnsEntry
)
error
{
// Try extracting the public key from the ID. If we can, *don't* embed
// it.
id
,
err
:=
peer
.
IDFromPublicKey
(
pk
)
if
err
!=
nil
{
return
err
...
...
@@ -79,6 +81,9 @@ func EmbedPublicKey(pk ic.PubKey, entry *pb.IpnsEntry) error {
if
extraced
!=
nil
{
return
nil
}
// We failed to extract the public key from the peer ID, embed it in the
// record.
pkBytes
,
err
:=
pk
.
Bytes
()
if
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
ipns_test.go
0 → 100644
View file @
d7779be9
package
ipns
import
(
"testing"
"time"
u
"github.com/ipfs/go-ipfs-util"
ci
"github.com/libp2p/go-libp2p-crypto"
peer
"github.com/libp2p/go-libp2p-peer"
)
func
TestEmbedPublicKey
(
t
*
testing
.
T
)
{
sr
:=
u
.
NewTimeSeededRand
()
priv
,
pub
,
err
:=
ci
.
GenerateKeyPairWithReader
(
ci
.
RSA
,
1024
,
sr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pid
,
err
:=
peer
.
IDFromPublicKey
(
pub
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
e
,
err
:=
Create
(
priv
,
[]
byte
(
"/a/b"
),
0
,
time
.
Now
()
.
Add
(
1
*
time
.
Hour
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
EmbedPublicKey
(
pub
,
e
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
embeddedPk
,
err
:=
ci
.
UnmarshalPublicKey
(
e
.
PubKey
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
embeddedPid
,
err
:=
peer
.
IDFromPublicKey
(
embeddedPk
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
embeddedPid
!=
pid
{
t
.
Fatalf
(
"pid mismatch: %s != %s"
,
pid
,
embeddedPid
)
}
}
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