pub const COSE_ED25519: i64 = -19;
pub const COSE_ESP256: i64 = -9;
pub const DEPRECATED: &[i64] = &[-8, -7, -35, -36];
#[derive(Debug, Clone, Copy)]
pub struct AllowedAlgs {
pub ed25519: bool,
pub esp256: bool,
}
impl Default for AllowedAlgs {
fn default() -> Self {
Self {
ed25519: true,
esp256: false,
}
}
}
impl AllowedAlgs {
pub fn strict() -> Self {
Self::default()
}
pub fn with_esp256(mut self) -> Self {
self.esp256 = true;
self
}
pub fn is_allowed(&self, alg: i64) -> bool {
match alg {
x if x == COSE_ED25519 => self.ed25519,
x if x == COSE_ESP256 => self.esp256,
_ => false,
}
}
pub fn is_deprecated(alg: i64) -> bool {
DEPRECATED.contains(&alg)
}
}