Skip to content

Commit 06ce69e

Browse files
committed
sum_bytes
1 parent b0cc303 commit 06ce69e

File tree

1 file changed

+7
-5
lines changed
  • lib/bencher_context/src/client/platform/target_os

1 file changed

+7
-5
lines changed

lib/bencher_context/src/client/platform/target_os/windows.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use core::ffi::c_void;
2-
use std::cmp;
32

43
use uuid::Uuid;
54
use windows::{
@@ -32,7 +31,7 @@ fn digital_product_id() -> Option<Uuid> {
3231
let value_bytes = "DigitalProductId\0".encode_utf16().collect::<Vec<u16>>();
3332
let value = PCWSTR::from_raw(value_bytes.as_ptr());
3433

35-
let mut data = vec![0u8; 256];
34+
let mut data = [0u8; 256];
3635
let mut data_size = data.len() as u32;
3736
// Safety: The accuracy of the data returned by `RegGetValueW` is not of any importance,
3837
// rather the consistency of the data is what is important.
@@ -52,11 +51,14 @@ fn digital_product_id() -> Option<Uuid> {
5251
.ok()?;
5352
}
5453

54+
// There appear to be quite a few zeroed out bytes at the beginning of the digital product ID.
55+
// In order to ensure as much entropy as possible,
56+
// we'll just sum all of the bytes together in a wrapping fashion.
5557
let digital_product_id = data
5658
.into_iter()
57-
.take(cmp::min(data_size as usize, size_of::<uuid::Bytes>()))
58-
.collect::<Vec<u8>>();
59-
digital_product_id.try_into().ok().map(Uuid::from_bytes)
59+
.take(data_size as usize)
60+
.fold(0u128, |acc, byte| acc.overflowing_add(byte.into()).0);
61+
Some(Uuid::from_u128(digital_product_id))
6062
}
6163

6264
impl OperatingSystem {

0 commit comments

Comments
 (0)