Skip to content

Commit

Permalink
feat(identity): add From impls for specific keypair types
Browse files Browse the repository at this point in the history
Closes #3618.

Pull-Request: #3626.
  • Loading branch information
creativcoder authored Mar 16, 2023
1 parent 873a90e commit 14292c4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [`libp2p-floodsub` CHANGELOG](protocols/floodsub/CHANGELOG.md)
- [`libp2p-gossipsub` CHANGELOG](protocols/gossipsub/CHANGELOG.md)
- [`libp2p-identify` CHANGELOG](protocols/identify/CHANGELOG.md)
- [`libp2p-identity` CHANGELOG](protocols/identity/CHANGELOG.md)
- [`libp2p-kad` CHANGELOG](protocols/kad/CHANGELOG.md)
- [`libp2p-mdns` CHANGELOG](protocols/mdns/CHANGELOG.md)
- [`libp2p-ping` CHANGELOG](protocols/ping/CHANGELOG.md)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions identity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 0.1.1 [unreleased]

- Add `From` impl for specific keypairs.
See [PR 3626].

[PR 3626]: https://github.com/libp2p/rust-libp2p/pull/3626
2 changes: 1 addition & 1 deletion identity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libp2p-identity"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "Data structures and algorithms for identifying peers in libp2p."
rust-version = "1.60.0"
Expand Down
32 changes: 32 additions & 0 deletions identity/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,38 @@ impl Keypair {
}
}

#[cfg(feature = "ecdsa")]
impl From<ecdsa::Keypair> for Keypair {
fn from(kp: ecdsa::Keypair) -> Self {
#[allow(deprecated)]
Keypair::Ecdsa(kp)
}
}

#[cfg(feature = "ed25519")]
impl From<ed25519::Keypair> for Keypair {
fn from(kp: ed25519::Keypair) -> Self {
#[allow(deprecated)]
Keypair::Ed25519(kp)
}
}

#[cfg(feature = "secp256k1")]
impl From<secp256k1::Keypair> for Keypair {
fn from(kp: secp256k1::Keypair) -> Self {
#[allow(deprecated)]
Keypair::Secp256k1(kp)
}
}

#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
impl From<rsa::Keypair> for Keypair {
fn from(kp: rsa::Keypair) -> Self {
#[allow(deprecated)]
Keypair::Rsa(kp)
}
}

/// The public key of a node's identity keypair.
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum PublicKey {
Expand Down

0 comments on commit 14292c4

Please sign in to comment.