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 7bff7ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "package-family-name"
version = "1.1.0"
version = "1.2.0"
edition = "2021"
license = "MIT OR Apache-2.0"
categories = ["no-std"]
Expand Down
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 7bff7ba

Please sign in to comment.