Skip to content

Commit

Permalink
Add get_publisher_id function
Browse files Browse the repository at this point in the history
  • Loading branch information
russellbanks committed Jul 29, 2024
1 parent a85dce4 commit 1e4b349
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -31,4 +32,9 @@ mod tests {
"AppName_zj75k085cmj1a"
);
}

#[test]
fn test_package_family_hash() {
assert_eq!(get_publisher_id("Publisher Software"), "zj75k085cmj1a");
}
}

0 comments on commit 1e4b349

Please sign in to comment.