feat(keypair): Make KeyFormat more convenient (#91)

* feat(keypair): Make `KeyFormat` more convenient

1. Make `KeyFormat` implement `Debug`, `Clone` and `Eq`.
2. Add `KeyPair::key_format(&self) -> KeyFormat` method.
This commit is contained in:
Ivan Boldyrev 2023-05-03 02:48:42 +07:00 committed by GitHub
parent c85fb16de3
commit 9b942eacca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,6 +48,7 @@ use std::str::FromStr;
/// ``` /// ```
/// ///
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyFormat { pub enum KeyFormat {
Ed25519, Ed25519,
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
@ -168,6 +169,18 @@ impl KeyPair {
} }
} }
/// Get the key format of this keypair.
pub fn key_format(&self) -> KeyFormat {
use KeyPair::*;
match self {
Ed25519(_) => KeyFormat::Ed25519,
#[cfg(not(target_arch = "wasm32"))]
Rsa(_) => KeyFormat::Rsa,
Secp256k1(_) => KeyFormat::Secp256k1,
}
}
/// Get the public key of this keypair. /// Get the public key of this keypair.
pub fn public(&self) -> PublicKey { pub fn public(&self) -> PublicKey {
use KeyPair::*; use KeyPair::*;