File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
lib/bencher_context/src/client/platform/target_os Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 11use core:: ffi:: c_void;
2- use std:: cmp;
32
43use uuid:: Uuid ;
54use 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
6264impl OperatingSystem {
You can’t perform that action at this time.
0 commit comments