Skip to content

Commit

Permalink
Change PublicKey::into_protobuf_encoding(self) to `PublicKey::to_pr…
Browse files Browse the repository at this point in the history
…otobuf_encoding(&self)`
  • Loading branch information
rubdos committed Jul 16, 2021
1 parent 20183c1 commit 10f168d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl PublicKey {

/// Encode the public key into a protobuf structure for storage or
/// exchange with other nodes.
pub fn into_protobuf_encoding(self) -> Vec<u8> {
pub fn to_protobuf_encoding(&self) -> Vec<u8> {
use prost::Message;

let public_key = match self {
Expand Down
4 changes: 2 additions & 2 deletions core/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl fmt::Display for PeerId {
impl PeerId {
/// Builds a `PeerId` from a public key.
pub fn from_public_key(key: PublicKey) -> PeerId {
let key_enc = key.into_protobuf_encoding();
let key_enc = key.to_protobuf_encoding();

let hash_algorithm = if key_enc.len() <= MAX_INLINE_KEY_LENGTH {
Code::Identity
Expand Down Expand Up @@ -114,7 +114,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().into_protobuf_encoding();
let enc = public_key.clone().to_protobuf_encoding();
Some(alg.digest(&enc) == self.multihash)
}
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl From<MessageAuthenticity> for PublishConfig {
match authenticity {
MessageAuthenticity::Signed(keypair) => {
let public_key = keypair.public();
let key_enc = public_key.clone().into_protobuf_encoding();
let key_enc = public_key.clone().to_protobuf_encoding();
let key = if key_enc.len() <= 42 {
// The public key can be inlined in [`rpc_proto::Message::from`], so we don't include it
// specifically in the [`rpc_proto::Message::key`] field.
Expand Down
2 changes: 1 addition & 1 deletion protocols/identify/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ where
.map(|addr| addr.to_vec())
.collect();

let pubkey_bytes = info.public_key.into_protobuf_encoding();
let pubkey_bytes = info.public_key.to_protobuf_encoding();

let message = structs_proto::Identify {
agent_version: Some(info.agent_version),
Expand Down
2 changes: 1 addition & 1 deletion transports/noise/src/io/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ where
let mut pb = payload_proto::NoiseHandshakePayload::default();

if state.send_identity {
pb.identity_key = state.identity.public.clone().into_protobuf_encoding()
pb.identity_key = state.identity.public.clone().to_protobuf_encoding()
}

if let Some(ref sig) = state.identity.signature {
Expand Down
2 changes: 1 addition & 1 deletion transports/plaintext/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl HandshakeContext<Local> {
fn new(config: PlainText2Config) -> Self {
let exchange = Exchange {
id: Some(config.local_public_key.clone().into_peer_id().to_bytes()),
pubkey: Some(config.local_public_key.clone().into_protobuf_encoding())
pubkey: Some(config.local_public_key.to_protobuf_encoding())
};
let mut buf = Vec::with_capacity(exchange.encoded_len());
exchange.encode(&mut buf).expect("Vec<u8> provides capacity as needed");
Expand Down

0 comments on commit 10f168d

Please sign in to comment.