diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index ddb02807e632..6f2671e13caf 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -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] diff --git a/core/src/peer_id.rs b/core/src/peer_id.rs index b7e4b976e5bf..001db2985227 100644 --- a/core/src/peer_id.rs +++ b/core/src/peer_id.rs @@ -113,7 +113,7 @@ impl PeerId { pub fn is_public_key(&self, public_key: &PublicKey) -> Option { 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) } } @@ -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)); } @@ -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()); }