use core::fmt;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Algorithm {
Sha1,
Sha256,
Sha512,
Blake3,
Md5,
XxHash64,
FastCdc,
Perceptual,
Unknown,
}
impl Algorithm {
pub fn as_str(&self) -> &'static str {
match self {
Algorithm::Sha1 => "sha1",
Algorithm::Sha256 => "sha256",
Algorithm::Sha512 => "sha512",
Algorithm::Blake3 => "blake3",
Algorithm::Md5 => "md5",
Algorithm::XxHash64 => "xxhash64",
Algorithm::FastCdc => "fastcdc",
Algorithm::Perceptual => "perceptual",
Algorithm::Unknown => "unknown",
}
}
#[expect(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Self {
match s {
"sha1" => Algorithm::Sha1,
"sha256" => Algorithm::Sha256,
"sha512" => Algorithm::Sha512,
"blake3" => Algorithm::Blake3,
"md5" => Algorithm::Md5,
"xxhash64" => Algorithm::XxHash64,
"fastcdc" => Algorithm::FastCdc,
"perceptual" => Algorithm::Perceptual,
_ => Algorithm::Unknown,
}
}
pub fn output_len(&self) -> Option<usize> {
match self {
Algorithm::Sha1 => Some(20),
Algorithm::Sha256 => Some(32),
Algorithm::Sha512 => Some(64),
Algorithm::Blake3 => Some(32),
Algorithm::Md5 => Some(16),
Algorithm::XxHash64 => Some(8),
Algorithm::FastCdc => Some(4),
Algorithm::Perceptual | Algorithm::Unknown => None,
}
}
}
impl fmt::Display for Algorithm {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Format {
Png,
Jpeg,
Bmp,
Zip,
Mp4,
Mp3,
Wav,
Flac,
Pdf,
Gif,
Unknown,
}
impl Format {
pub fn as_str(&self) -> &'static str {
match self {
Format::Png => "png",
Format::Jpeg => "jpeg",
Format::Bmp => "bmp",
Format::Zip => "zip",
Format::Mp4 => "mp4",
Format::Mp3 => "mp3",
Format::Wav => "wav",
Format::Flac => "flac",
Format::Pdf => "pdf",
Format::Gif => "gif",
Format::Unknown => "unknown",
}
}
#[expect(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Self {
match s {
"png" => Format::Png,
"jpeg" => Format::Jpeg,
"bmp" => Format::Bmp,
"zip" => Format::Zip,
"mp4" => Format::Mp4,
"mp3" => Format::Mp3,
"wav" => Format::Wav,
"flac" => Format::Flac,
"pdf" => Format::Pdf,
"gif" => Format::Gif,
_ => Format::Unknown,
}
}
}
impl fmt::Display for Format {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}