From bbc4cc0c33d0a4a887013ac917f419f467977ab8 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 19 Jul 2025 13:41:07 +0800 Subject: [PATCH] feat: v1.2.2, digest type --- Cargo.toml | 2 +- src/lib.rs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5017746..26bf74e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 356fe40..2dbf7d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + 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 { + 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)]