1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
//! Traits for public keys

use core::fmt::Debug;

use error::Error;

/// Signers which know their public keys (to be implemented by Signatory
/// providers)
pub trait PublicKeyed<K: PublicKey>: Send + Sync {
    /// Public key which can verify signatures created by this signer
    fn public_key(&self) -> Result<K, Error>;
}

/// Common trait for all public keys
pub trait PublicKey: AsRef<[u8]> + Debug + Sized {}

/// Get the public key for the given public keyed object (i.e. a `Signer`)
pub fn public_key<K: PublicKey>(keyed: &PublicKeyed<K>) -> Result<K, Error> {
    keyed.public_key()
}