coffio/src/scheme.rs

36 lines
786 B
Rust
Raw Normal View History

2024-02-17 20:26:45 +01:00
use crate::encryption::EncryptionFunction;
2024-02-17 16:29:54 +01:00
use crate::kdf::KdfFunction;
2024-02-15 10:56:21 +01:00
use crate::Error;
2024-02-15 10:00:06 +01:00
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Scheme {
XChaCha20Poly1305WithBlake3 = 1,
}
2024-02-15 23:45:21 +01:00
impl Scheme {
2024-02-17 16:29:54 +01:00
pub(crate) fn get_kdf(&self) -> Box<KdfFunction> {
2024-02-15 23:45:21 +01:00
match self {
2024-02-17 16:29:54 +01:00
Scheme::XChaCha20Poly1305WithBlake3 => Box::new(crate::kdf::blake3_derive),
2024-02-15 23:45:21 +01:00
}
}
2024-02-17 20:26:45 +01:00
pub(crate) fn get_encryption(&self) -> Box<EncryptionFunction> {
match self {
Scheme::XChaCha20Poly1305WithBlake3 => {
Box::new(crate::encryption::xchacha20poly1305_encrypt)
}
}
}
2024-02-15 23:45:21 +01:00
}
2024-02-15 10:00:06 +01:00
impl TryFrom<u32> for Scheme {
2024-02-15 10:56:21 +01:00
type Error = Error;
2024-02-15 10:00:06 +01:00
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
1 => Ok(Scheme::XChaCha20Poly1305WithBlake3),
2024-02-15 10:56:21 +01:00
_ => Err(Error::ParsingUnknownScheme(value)),
2024-02-15 10:00:06 +01:00
}
}
}