use crate::{
Error,
PublicKey,
SecretKey,
};
use borrown::Borrown;
pub trait Keystore {
type Error: From<Error>;
type KeyId;
fn secret(
&self,
id: &Self::KeyId,
) -> Result<Option<Borrown<'_, SecretKey>>, Self::Error>;
#[cfg(not(feature = "std"))]
fn public(
&self,
id: &Self::KeyId,
) -> Result<Option<Borrown<'_, PublicKey>>, Self::Error>;
#[cfg(feature = "std")]
fn public(
&self,
id: &Self::KeyId,
) -> Result<Option<Borrown<'_, PublicKey>>, Self::Error> {
let secret = self.secret(id)?;
let public = secret
.map(|s| PublicKey::from(s.as_ref()))
.map(Borrown::Owned);
Ok(public)
}
}