1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
}
}