use crate::{CryptoError, error::SignatureError};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SigningNamespace {
SignedPublicKey = 1,
SecurityState = 2,
#[cfg(test)]
ExampleNamespace = -1,
#[cfg(test)]
ExampleNamespace2 = -2,
}
impl SigningNamespace {
pub fn as_i64(&self) -> i64 {
*self as i64
}
}
impl TryFrom<i64> for SigningNamespace {
type Error = CryptoError;
fn try_from(value: i64) -> Result<Self, Self::Error> {
match value {
1 => Ok(SigningNamespace::SignedPublicKey),
2 => Ok(SigningNamespace::SecurityState),
#[cfg(test)]
-1 => Ok(SigningNamespace::ExampleNamespace),
#[cfg(test)]
-2 => Ok(SigningNamespace::ExampleNamespace2),
_ => Err(SignatureError::InvalidNamespace.into()),
}
}
}
impl TryFrom<i128> for SigningNamespace {
type Error = CryptoError;
fn try_from(value: i128) -> Result<Self, Self::Error> {
let Ok(value) = i64::try_from(value) else {
return Err(SignatureError::InvalidNamespace.into());
};
Self::try_from(value)
}
}