File tree 1 file changed +7
-5
lines changed
lib/bencher_context/src/client/platform/target_os
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 1
1
use core:: ffi:: c_void;
2
- use std:: cmp;
3
2
4
3
use uuid:: Uuid ;
5
4
use windows:: {
@@ -32,7 +31,7 @@ fn digital_product_id() -> Option<Uuid> {
32
31
let value_bytes = "DigitalProductId\0 " . encode_utf16 ( ) . collect :: < Vec < u16 > > ( ) ;
33
32
let value = PCWSTR :: from_raw ( value_bytes. as_ptr ( ) ) ;
34
33
35
- let mut data = vec ! [ 0u8 ; 256 ] ;
34
+ let mut data = [ 0u8 ; 256 ] ;
36
35
let mut data_size = data. len ( ) as u32 ;
37
36
// Safety: The accuracy of the data returned by `RegGetValueW` is not of any importance,
38
37
// rather the consistency of the data is what is important.
@@ -52,11 +51,14 @@ fn digital_product_id() -> Option<Uuid> {
52
51
. ok ( ) ?;
53
52
}
54
53
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.
55
57
let digital_product_id = data
56
58
. 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 ) )
60
62
}
61
63
62
64
impl OperatingSystem {
You can’t perform that action at this time.
0 commit comments