From 9b942eacca49d0468b4d7512667102363a6c9aa3 Mon Sep 17 00:00:00 2001 From: Ivan Boldyrev Date: Wed, 3 May 2023 02:48:42 +0700 Subject: [PATCH] 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. --- keypair/src/key_pair.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/keypair/src/key_pair.rs b/keypair/src/key_pair.rs index 5b14d8c..2238e54 100644 --- a/keypair/src/key_pair.rs +++ b/keypair/src/key_pair.rs @@ -48,6 +48,7 @@ use std::str::FromStr; /// ``` /// +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum KeyFormat { Ed25519, #[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. pub fn public(&self) -> PublicKey { use KeyPair::*;