File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
hermes/bin/src/runtime_extensions/hermes/doc_sync Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,9 @@ impl HostSyncChannel for HermesRuntimeContext {
9494 & mut self ,
9595 name : ChannelName ,
9696 ) -> wasmtime:: Result < Resource < SyncChannel > > {
97- let hash = blake2b_simd:: blake2b ( name. as_bytes ( ) ) ;
97+ let hash = blake2b_simd:: Params :: new ( )
98+ . hash_length ( 4 )
99+ . hash ( name. as_bytes ( ) ) ;
98100
99101 // The digest is a 64-byte array ([u8; 64]) for 512-bit output.
100102 // Take the first 4 bytes to use them as resource id.
@@ -104,12 +106,11 @@ impl HostSyncChannel for HermesRuntimeContext {
104106 // acceptable but unlikely in practice. We use the first 4 bytes of
105107 // the cryptographically secure Blake2b hash as a fast, 32-bit ID
106108 // to minimize lock contention when accessing state via DOC_SYNC_STATE.
107- #[ allow( clippy:: indexing_slicing) ]
108- let prefix_bytes: [ u8 ; 4 ] = hash. as_bytes ( ) [ ..4 ] . try_into ( ) . map_err ( |err| {
109- wasmtime:: Error :: msg ( format ! ( "error trimming channel name hash: {err}" ) )
109+ let prefix_bytes: & [ u8 ; 4 ] = hash. as_bytes ( ) . try_into ( ) . map_err ( |err| {
110+ wasmtime:: Error :: msg ( format ! ( "BLAKE2b hash output length must be 4 bytes: {err}" ) )
110111 } ) ?;
111112
112- let resource: u32 = u32:: from_be_bytes ( prefix_bytes) ;
113+ let resource: u32 = u32:: from_be_bytes ( * prefix_bytes) ;
113114
114115 // Code block is used to minimize locking scope.
115116 {
You can’t perform that action at this time.
0 commit comments