diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-12 03:27:04 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-12 03:27:04 +0900 |
| commit | 7266045d40e4126767244510541f5f4764ee8afe (patch) | |
| tree | 60647571aef063023908657614b9b8c94eca4922 /crates | |
| parent | ac242b9ec64e7487a048954a22078db90ce6a155 (diff) | |
| download | php-shirabe-7266045d40e4126767244510541f5f4764ee8afe.tar.gz php-shirabe-7266045d40e4126767244510541f5f4764ee8afe.tar.zst php-shirabe-7266045d40e4126767244510541f5f4764ee8afe.zip | |
feat(port): port Keys.php
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/self_update/keys.rs | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 0533c0a..03db936 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -35,6 +35,10 @@ pub struct InvalidArgumentException { pub code: i64, } +pub fn hash(algo: &str, data: &str) -> String { + todo!() +} + #[derive(Debug)] pub struct PharData { path: String, 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<String> { + 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(" ")) + } +} |
