#![allow(clippy::should_implement_trait)]
#[derive(PartialEq)]
pub enum EncryptionAlg {
AesGcm,
ChaCha20Poly1305,
}
impl EncryptionAlg {
pub fn value(&self) -> u8 {
match *self {
EncryptionAlg::AesGcm => 1,
EncryptionAlg::ChaCha20Poly1305 => 2,
}
}
pub fn from_str(input: &str) -> EncryptionAlg {
match input {
"aes-gcm" => EncryptionAlg::AesGcm,
"chacha20-poly1305" => EncryptionAlg::ChaCha20Poly1305,
_ => EncryptionAlg::AesGcm,
}
}
pub fn from_u8(input: u8) -> EncryptionAlg {
match input {
1 => EncryptionAlg::AesGcm,
2 => EncryptionAlg::ChaCha20Poly1305,
_ => EncryptionAlg::AesGcm,
}
}
pub fn to_str(&self) -> &str {
match *self {
EncryptionAlg::AesGcm => "aes-gcm",
EncryptionAlg::ChaCha20Poly1305 => "chacha20-poly1305",
}
}
}
#[derive(PartialEq)]
pub enum HashAlg {
Sha256,
}
impl HashAlg {
pub fn value(&self) -> u8 {
match *self {
HashAlg::Sha256 => 1,
}
}
pub fn from_str(input: &str) -> HashAlg {
match input {
"sha-256" => HashAlg::Sha256,
_ => HashAlg::Sha256,
}
}
pub fn from_u8(input: u8) -> HashAlg {
match input {
1 => HashAlg::Sha256,
_ => HashAlg::Sha256,
}
}
pub fn to_str(&self) -> &str {
match *self {
HashAlg::Sha256 => "sha-256",
}
}
}
#[derive(PartialEq)]
pub enum KdfAlg {
Argon2d,
Argon2id,
}
impl KdfAlg {
pub fn value(&self) -> u8 {
match *self {
KdfAlg::Argon2d => 1,
KdfAlg::Argon2id => 2,
}
}
pub fn from_u8(input: u8) -> KdfAlg {
match input {
1 => KdfAlg::Argon2d,
2 => KdfAlg::Argon2id,
_ => KdfAlg::Argon2d,
}
}
pub fn from_str(input: &str) -> KdfAlg {
match input {
"argon2d" => KdfAlg::Argon2d,
"argon2id" => KdfAlg::Argon2id,
_ => KdfAlg::Argon2d,
}
}
pub fn to_str(&self) -> &str {
match *self {
KdfAlg::Argon2d => "argon2d",
KdfAlg::Argon2id => "argon2id",
}
}
}
#[derive(PartialEq)]
pub enum CompressionAlg {
None,
Gzip,
}
impl CompressionAlg {
pub fn value(&self) -> u8 {
match *self {
CompressionAlg::None => 0,
CompressionAlg::Gzip => 1,
}
}
pub fn from_bool(input: bool) -> CompressionAlg {
match input {
true => CompressionAlg::Gzip,
false => CompressionAlg::None,
}
}
pub fn from_u8(input: u8) -> CompressionAlg {
match input {
0 => CompressionAlg::None,
1 => CompressionAlg::Gzip,
_ => CompressionAlg::Gzip,
}
}
pub fn to_bool(&self) -> bool {
match *self {
CompressionAlg::Gzip => true,
CompressionAlg::None => false,
}
}
}