File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -54,8 +54,9 @@ impl HashSecret {
5454 pub fn new ( seed : u32 ) -> Self {
5555 let mut buf = [ 0u8 ; 16 ] ;
5656 lcg_urandom ( seed, & mut buf) ;
57- let k0 = u64:: from_le_bytes ( buf[ ..8 ] . try_into ( ) . unwrap ( ) ) ;
58- let k1 = u64:: from_le_bytes ( buf[ 8 ..] . try_into ( ) . unwrap ( ) ) ;
57+ let ( left, right) = buf. split_at ( 8 ) ;
58+ let k0 = u64:: from_le_bytes ( left. try_into ( ) . unwrap ( ) ) ;
59+ let k1 = u64:: from_le_bytes ( right. try_into ( ) . unwrap ( ) ) ;
5960 Self { k0, k1 }
6061 }
6162}
Original file line number Diff line number Diff line change @@ -88,6 +88,12 @@ pub struct PyGlobalState {
8888 pub codec_registry : CodecsRegistry ,
8989}
9090
91+ pub fn process_hash_secret_seed ( ) -> u32 {
92+ use once_cell:: sync:: OnceCell ;
93+ static SEED : OnceCell < u32 > = OnceCell :: new ( ) ;
94+ * SEED . get_or_init ( rand:: random)
95+ }
96+
9197impl VirtualMachine {
9298 /// Create a new `VirtualMachine` structure.
9399 fn new ( settings : Settings , ctx : PyRc < Context > ) -> VirtualMachine {
@@ -120,10 +126,11 @@ impl VirtualMachine {
120126
121127 let module_inits = stdlib:: get_module_inits ( ) ;
122128
123- let hash_secret = match settings. hash_seed {
124- Some ( seed) => HashSecret :: new ( seed) ,
125- None => rand :: random ( ) ,
129+ let seed = match settings. hash_seed {
130+ Some ( seed) => seed,
131+ None => process_hash_secret_seed ( ) ,
126132 } ;
133+ let hash_secret = HashSecret :: new ( seed) ;
127134
128135 let codec_registry = CodecsRegistry :: new ( & ctx) ;
129136
You can’t perform that action at this time.
0 commit comments