From 1e4b34937ca72ecbbedd35446eb92c23519c686c Mon Sep 17 00:00:00 2001 From: Russell Banks <74878137+russellbanks@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:35:52 +0100 Subject: [PATCH] Add `get_publisher_id` function --- src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 53faece..6a533a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,21 +8,22 @@ use fast32::base32::CROCKFORD_LOWER; use sha2::{Digest, Sha256}; pub fn get_package_family_name(identity_name: &str, identity_publisher: &str) -> String { + format!("{identity_name}_{}", get_publisher_id(identity_publisher)) +} + +pub fn get_publisher_id(identity_publisher: &str) -> String { let publisher_sha_256 = identity_publisher .encode_utf16() .flat_map(u16::to_le_bytes) .fold(Sha256::new(), |buf, byte| buf.chain_update([byte])) .finalize(); - format!( - "{identity_name}_{}", - CROCKFORD_LOWER.encode(&publisher_sha_256[..8]) - ) + CROCKFORD_LOWER.encode(&publisher_sha_256[..8]) } #[cfg(test)] mod tests { - use crate::get_package_family_name; + use crate::{get_package_family_name, get_publisher_id}; #[test] fn test_package_family_name() { @@ -31,4 +32,9 @@ mod tests { "AppName_zj75k085cmj1a" ); } + + #[test] + fn test_package_family_hash() { + assert_eq!(get_publisher_id("Publisher Software"), "zj75k085cmj1a"); + } }