aws_sdk_manager/utils/
system_id.rs

1use ripemd::{Digest, Ripemd160};
2
3/// Creates an ID based on host information.
4pub fn string(n: usize) -> String {
5    let id = format!(
6        "{}-{}-{}-{}-{}",
7        whoami::username(),
8        whoami::realname(),
9        whoami::hostname(),
10        whoami::platform(),
11        whoami::devicename(),
12    );
13
14    let mut hasher = Ripemd160::new();
15    hasher.update(id.as_bytes());
16    let result = hasher.finalize();
17
18    let mut id = bs58::encode(&result[..]).into_string();
19    if n > 0 && id.len() > n {
20        id.truncate(n);
21    }
22    id.to_lowercase()
23}
24
25/// RUST_LOG=debug cargo test --all-features --package avalanche-utils --lib -- system_id::test_string --exact --show-output
26#[test]
27fn test_string() {
28    let _ = env_logger::builder().is_test(true).try_init();
29    use log::info;
30
31    let system1 = string(10);
32    let system2 = string(10);
33    assert_eq!(system1, system2);
34
35    info!("system1: {:?}", system1);
36    info!("system2: {:?}", system2);
37}