From 7266045d40e4126767244510541f5f4764ee8afe Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 12 May 2026 03:27:04 +0900 Subject: feat(port): port Keys.php --- crates/shirabe/src/self_update/keys.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'crates/shirabe/src') diff --git a/crates/shirabe/src/self_update/keys.rs b/crates/shirabe/src/self_update/keys.rs index a1d30ff..b1da7b5 100644 --- a/crates/shirabe/src/self_update/keys.rs +++ b/crates/shirabe/src/self_update/keys.rs @@ -1 +1,29 @@ //! ref: composer/src/Composer/SelfUpdate/Keys.php + +use anyhow::Result; +use regex::Regex; +use shirabe_php_shim::hash; + +pub struct Keys; + +impl Keys { + pub fn fingerprint(path: &str) -> Result { + let content = std::fs::read_to_string(path)?; + let re = Regex::new(r"\s").unwrap(); + let cleaned = re.replace_all(&content, ""); + let hash = hash("sha256", &cleaned).to_uppercase(); + + Ok([ + &hash[0..8], + &hash[8..16], + &hash[16..24], + &hash[24..32], + "", + &hash[32..40], + &hash[40..48], + &hash[48..56], + &hash[56..64], + ] + .join(" ")) + } +} -- cgit v1.3.1