@@ -9,7 +9,7 @@ use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
9
9
10
10
// Size of our temporary Uint8Array buffer used with WebCrypto methods
11
11
// Maximum is 65536 bytes see https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
12
- const WEB_CRYPTO_BUFFER_SIZE : usize = 256 ;
12
+ const WEB_CRYPTO_BUFFER_SIZE : u16 = 256 ;
13
13
// Node.js's crypto.randomFillSync requires the size to be less than 2**31.
14
14
const NODE_MAX_BUFFER_SIZE : usize = ( 1 << 31 ) - 1 ;
15
15
@@ -50,9 +50,10 @@ pub(crate) fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error>
50
50
RngSource :: Web ( crypto, buf) => {
51
51
// getRandomValues does not work with all types of WASM memory,
52
52
// so we initially write to browser memory to avoid exceptions.
53
- for chunk in dest. chunks_mut ( WEB_CRYPTO_BUFFER_SIZE ) {
53
+ for chunk in dest. chunks_mut ( WEB_CRYPTO_BUFFER_SIZE . into ( ) ) {
54
54
// The chunk can be smaller than buf's length, so we call to
55
55
// JS to create a smaller view of buf without allocation.
56
+ #[ allow( clippy:: cast_possible_truncation) ]
56
57
let sub_buf = buf. subarray ( 0 , chunk. len ( ) as u32 ) ;
57
58
58
59
if crypto. get_random_values ( & sub_buf) . is_err ( ) {
@@ -95,7 +96,7 @@ fn getrandom_init() -> Result<RngSource, Error> {
95
96
} ,
96
97
} ;
97
98
98
- let buf = Uint8Array :: new_with_length ( WEB_CRYPTO_BUFFER_SIZE as u32 ) ;
99
+ let buf = Uint8Array :: new_with_length ( WEB_CRYPTO_BUFFER_SIZE . into ( ) ) ;
99
100
Ok ( RngSource :: Web ( crypto, buf) )
100
101
}
101
102
0 commit comments