~nicohman/signal-rs

ref: 5084c926fb753fdc6dda5f3cc2c8af2df5f1190b signal-rs/src/util.rs -rw-r--r-- 980 bytes
5084c926 — nicohman Make SignalUI a singleton and add application icon 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use presage::prelude::*;
// When given a group master key, derive secret params and return the identifier
pub fn get_gid_v2(master_key: Vec<u8>) -> String {
    let secret_params = GroupSecretParams::derive_from_master_key(make_gkey(master_key));
    let gid = secret_params.get_group_identifier();
    let dec = base64::encode(gid);
    return dec.to_uppercase();
}

// Returns the string form of a group id v1 in bytes
pub fn get_gid(id: Vec<u8>) -> String {
    return base64::encode(id).to_uppercase();
}

// Takes a vec of bytes and returns a constructed GroupMasterKey struct
pub fn make_gkey(bytes: Vec<u8>) -> GroupMasterKey {
    let mut slice: [u8; 32] = Default::default();
    slice.copy_from_slice(bytes.as_slice());
    GroupMasterKey::new(slice)
}

// Takes a vec of bytes and returns a profilekey slice
pub fn make_profile_key(bytes: Vec<u8>) -> [u8; 32] {
    let mut slice: [u8; 32] = Default::default();
    slice.copy_from_slice(bytes.as_slice());
    slice
}