Skip to content

Commit

Permalink
fixup! into/to correctness for PublicKey -> PeerId
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Jul 17, 2021
1 parent 99d0834 commit 7cbf674
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- Change `PublicKey::into_protobuf_encoding` to `PublicKey::to_protobuf_encoding`.
Change `PublicKey::into_peer_id` to `PublicKey::to_peer_id`.
Change `PeerId::from_public_key(PublicKey)` to `PeerId::from_public_key(PublicKey)`.
Change `PeerId::from_public_key(PublicKey)` to `PeerId::from_public_key(&PublicKey)`.
Add `From<&PublicKey> for PeerId`.
See [PR 2145]

Expand Down
6 changes: 3 additions & 3 deletions core/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl PeerId {
pub fn is_public_key(&self, public_key: &PublicKey) -> Option<bool> {
let alg = Code::try_from(self.multihash.code())
.expect("Internal multihash is always a valid `Code`");
let enc = public_key.clone().to_protobuf_encoding();
let enc = public_key.to_protobuf_encoding();
Some(alg.digest(&enc) == self.multihash)
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ mod tests {
#[test]
fn peer_id_is_public_key() {
let key = identity::Keypair::generate_ed25519().public();
let peer_id = key.clone().to_peer_id();
let peer_id = key.to_peer_id();
assert_eq!(peer_id.is_public_key(&key), Some(true));
}

Expand All @@ -213,7 +213,7 @@ mod tests {

#[test]
fn random_peer_id_is_valid() {
for _ in 0..5000 {
for _ in 0 .. 5000 {
let peer_id = PeerId::random();
assert_eq!(peer_id, PeerId::from_bytes(&peer_id.to_bytes()).unwrap());
}
Expand Down

0 comments on commit 7cbf674

Please sign in to comment.