use safe_nd::{AppFullId, ClientFullId, PublicId, PublicKey, Signature};
use std::sync::Arc;
#[derive(Clone)]
pub enum SafeKey {
App(Arc<AppFullId>),
Client(Arc<ClientFullId>),
}
impl SafeKey {
pub fn client(full_id: ClientFullId) -> Self {
Self::Client(Arc::new(full_id))
}
pub fn app(full_id: AppFullId) -> Self {
Self::App(Arc::new(full_id))
}
pub fn sign(&self, msg: &[u8]) -> Signature {
match self {
Self::App(app_full_id) => app_full_id.sign(msg),
Self::Client(client_full_id) => client_full_id.sign(msg),
}
}
pub fn public_id(&self) -> PublicId {
match self {
Self::App(app_full_id) => PublicId::App(app_full_id.public_id().clone()),
Self::Client(client_full_id) => PublicId::Client(client_full_id.public_id().clone()),
}
}
pub fn public_key(&self) -> PublicKey {
match self {
Self::App(app_full_id) => *app_full_id.public_id().public_key(),
Self::Client(client_full_id) => *client_full_id.public_id().public_key(),
}
}
}