From c9f55a4c5d3c9a340efc759921d27f2cad3a3916 Mon Sep 17 00:00:00 2001 From: Marek Date: Tue, 4 Apr 2023 18:38:28 +0200 Subject: [PATCH] Use `u64` instead of `usize` for `byte_count` --- zcash_proofs/src/hashreader.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/zcash_proofs/src/hashreader.rs b/zcash_proofs/src/hashreader.rs index 47fbc648e..553cdd965 100644 --- a/zcash_proofs/src/hashreader.rs +++ b/zcash_proofs/src/hashreader.rs @@ -11,7 +11,7 @@ use blake2b_simd::State; pub struct HashReader { reader: R, hasher: State, - byte_count: usize, + byte_count: u64, } impl HashReader { @@ -37,7 +37,7 @@ impl HashReader { } /// Return the number of bytes read so far. - pub fn byte_count(&self) -> usize { + pub fn byte_count(&self) -> u64 { self.byte_count } } @@ -48,7 +48,13 @@ impl Read for HashReader { if bytes > 0 { self.hasher.update(&buf[0..bytes]); - self.byte_count += bytes; + let byte_count = u64::try_from(bytes).map_err(|_| { + io::Error::new( + io::ErrorKind::InvalidData, + "Could not fit the number of read bytes into u64.", + ) + })?; + self.byte_count += byte_count; } Ok(bytes)