use std::borrow::Cow;
use crate::keytype::*;
use crate::{Key, Keyring, KeyringSerial};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Asymmetric;
impl KeyType for Asymmetric {
type Description = str;
type Payload = [u8];
fn name() -> &'static str {
"asymmetric"
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AsymmetricRestriction {
BuiltinTrusted,
BuiltinAndSecondaryTrusted,
Key {
key: Key,
chained: bool,
},
Keyring {
keyring: Keyring,
chained: bool,
},
Chained,
}
impl AsymmetricRestriction {
fn restriction_str(id: KeyringSerial, chained: bool) -> String {
let chain_suffix = if chained { ":chain" } else { "" };
format!("key_or_keyring:{}{}", id, chain_suffix)
}
}
impl KeyRestriction for AsymmetricRestriction {
fn restriction(&self) -> Cow<str> {
match self {
AsymmetricRestriction::BuiltinTrusted => "builtin_trusted".into(),
AsymmetricRestriction::BuiltinAndSecondaryTrusted => {
"builtin_and_secondary_trusted".into()
},
AsymmetricRestriction::Key {
key,
chained,
} => Self::restriction_str(key.serial(), *chained).into(),
AsymmetricRestriction::Keyring {
keyring,
chained,
} => Self::restriction_str(keyring.serial(), *chained).into(),
AsymmetricRestriction::Chained => "key_or_keyring:0:chain".into(),
}
}
}
impl RestrictableKeyType for Asymmetric {
type Restriction = AsymmetricRestriction;
}