feat: v1.2.2, digest type

This commit is contained in:
2025-07-19 13:41:07 +08:00
parent c7fdb01022
commit bbc4cc0c33
2 changed files with 21 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "swift-secure-enclave-tool-rs"
version = "1.2.1"
version = "1.2.2"
edition = "2024"
authors = ["Hatter Jiang"]
repository = "https://git.hatter.ink/hatter/swift-secure-enclave-tool-rs"

View File

@@ -40,7 +40,7 @@ pub enum DigestType {
}
impl DigestType {
fn to_str(&self) -> &'static str {
pub fn to_str(&self) -> &'static str {
match self {
DigestType::Raw => "raw",
DigestType::Sha256 => "sha256",
@@ -48,6 +48,25 @@ impl DigestType {
DigestType::Sha512 => "sha512",
}
}
pub fn bytes(&self) -> Option<u32> {
match self {
DigestType::Raw => None,
DigestType::Sha256 => Some(256 / 8),
DigestType::Sha384 => Some(384 / 8),
DigestType::Sha512 => Some(512 / 8),
}
}
pub fn parse(t: Option<&str>) -> XResult<DigestType> {
Ok(match t {
None | Some("") | Some("raw") => DigestType::Raw,
Some("sha256") => DigestType::Sha256,
Some("sha384") => DigestType::Sha384,
Some("sha512") => DigestType::Sha512,
Some(other_digest_type) => return simple_error!("Invalid digest type: {}", other_digest_type),
})
}
}
#[derive(Debug)]