@@ -302,15 +302,16 @@ pub(crate) fn decrypt_file_impl(
302302
303303// -- Streaming hash (no encryption padding) -----------------------------------
304304
305- /// Hash a file in streaming 64KB chunks.
305+ /// Feed an entire file into the hasher in 64KB chunks. Does NOT finalize .
306306///
307307/// Resets the hasher first to ensure a clean state, then feeds raw file bytes
308- /// (no padding). The digest matches `blake3_hash(fs::read(path))`.
309- pub ( crate ) fn hash_file_impl (
308+ /// (no padding). Caller must call `finalize_raw()` / `hasherFinalize()` to
309+ /// obtain the digest.
310+ pub ( crate ) fn hash_file_feed (
310311 hasher : & HasherHandle ,
311312 file_path : & str ,
312313 on_progress : & dyn Fn ( f64 ) ,
313- ) -> Result < Vec < u8 > , CryptoError > {
314+ ) -> Result < ( ) , CryptoError > {
314315 hasher. reset_raw ( ) ?;
315316
316317 let file = File :: open ( file_path)
@@ -336,9 +337,22 @@ pub(crate) fn hash_file_impl(
336337 }
337338 }
338339
339- let digest = hasher. finalize_raw ( ) ?;
340340 on_progress ( 1.0 ) ;
341- Ok ( digest)
341+ Ok ( ( ) )
342+ }
343+
344+ /// Hash a file in streaming 64KB chunks (feed + finalize).
345+ ///
346+ /// Convenience wrapper: feeds the entire file then finalizes.
347+ /// The digest matches `blake3_hash(fs::read(path))`.
348+ #[ cfg( test) ]
349+ fn hash_file_impl (
350+ hasher : & HasherHandle ,
351+ file_path : & str ,
352+ on_progress : & dyn Fn ( f64 ) ,
353+ ) -> Result < Vec < u8 > , CryptoError > {
354+ hash_file_feed ( hasher, file_path, on_progress) ?;
355+ hasher. finalize_raw ( )
342356}
343357
344358// -- FRB entry points (thin wrappers) ----------------------------------------
@@ -373,17 +387,20 @@ pub fn stream_decrypt_file(
373387 } )
374388}
375389
376- /// Hash a file using streaming 64KB chunks.
390+ /// Hash a file using streaming 64KB chunks — feeds data only, does NOT finalize .
377391///
378- /// Reads raw file bytes (no encryption padding) so the digest matches
379- /// one-shot `blake3_hash()` / `sha3_hash()` output.
392+ /// Reads raw file bytes (no encryption padding) and feeds them to the hasher.
380393/// Progress (0.0..1.0) is pushed to `progress_sink`.
394+ ///
395+ /// After the stream completes, call `hasherFinalize()` from Dart to obtain
396+ /// the digest. This two-step design is required because FRB cannot return
397+ /// both a Stream and a value from the same function.
381398pub fn stream_hash_file (
382399 hasher : & HasherHandle ,
383400 file_path : String ,
384401 progress_sink : StreamSink < f64 > ,
385- ) -> Result < Vec < u8 > , CryptoError > {
386- hash_file_impl ( hasher, & file_path, & |p| {
402+ ) -> Result < ( ) , CryptoError > {
403+ hash_file_feed ( hasher, & file_path, & |p| {
387404 let _ = progress_sink. add ( p) ;
388405 } )
389406}
0 commit comments