iop_keyvault/multicipher/
sk.rs

1use super::*;
2
3/// Multicipher [`PrivateKey`]
4///
5/// [`PrivateKey`]: ../trait.AsymmetricCrypto.html#associatedtype.PrivateKey
6#[derive(Clone)]
7pub enum MPrivateKey {
8    /// The private key tagged with this variant belongs to the [`ed25519`] module
9    ///
10    /// [`ed25519`]: ../ed25519/index.html
11    Ed25519(EdPrivateKey),
12    /// The private key tagged with this variant belongs to the [`secp256k1`] module
13    ///
14    /// [`secp256k1`]: ../secp256k1/index.html
15    Secp256k1(SecpPrivateKey),
16}
17
18impl PrivateKey<MultiCipher> for MPrivateKey {
19    fn public_key(&self) -> MPublicKey {
20        match self {
21            Self::Ed25519(edsk) => MPublicKey::from(edsk.public_key()),
22            Self::Secp256k1(secpsk) => MPublicKey::from(secpsk.public_key()),
23        }
24    }
25    fn sign<D: AsRef<[u8]>>(&self, data: D) -> MSignature {
26        match self {
27            Self::Ed25519(edsk) => MSignature::from(edsk.sign(data)),
28            Self::Secp256k1(secpsk) => MSignature::from(secpsk.sign(data)),
29        }
30    }
31}
32
33impl From<EdPrivateKey> for MPrivateKey {
34    fn from(src: EdPrivateKey) -> Self {
35        Self::Ed25519(src)
36    }
37}
38
39impl From<SecpPrivateKey> for MPrivateKey {
40    fn from(src: SecpPrivateKey) -> Self {
41        Self::Secp256k1(src)
42    }
43}