Skip to content

Commit 1395de8

Browse files
ref(utils): Use usize in get_sha1_checksums signature
Since we convert the argument to usize in the function anyways, it likely makes more sense for this function to explicitly take a usize. In future refactors, we can change the signatures of the functions that take the values to also take `usize`.
1 parent 8fb9f1e commit 1395de8

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/utils/dif_upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'data> ChunkedDifMatch<'data> {
332332
/// Slices the DIF into chunks of `chunk_size` bytes each, and computes SHA1
333333
/// checksums for every chunk as well as the entire DIF.
334334
pub fn from(inner: DifMatch<'data>, chunk_size: u64) -> Result<Self> {
335-
let (checksum, chunks) = get_sha1_checksums(inner.data(), chunk_size)?;
335+
let (checksum, chunks) = get_sha1_checksums(inner.data(), chunk_size as usize)?;
336336
Ok(ChunkedDifMatch {
337337
inner: HashedDifMatch { inner, checksum },
338338
chunks,

src/utils/file_upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fn upload_files_chunked(
412412
pb.set_style(progress_style);
413413

414414
let view = ByteView::open(archive.path())?;
415-
let (checksum, checksums) = get_sha1_checksums(&view, options.chunk_size)?;
415+
let (checksum, checksums) = get_sha1_checksums(&view, options.chunk_size as usize)?;
416416
let mut chunks = view
417417
.chunks(options.chunk_size as usize)
418418
.zip(checksums.iter())

src/utils/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ pub fn get_sha1_checksum<R: Read>(rdr: R) -> Result<Digest> {
171171

172172
/// Returns the SHA1 hash for the entire input, as well as each chunk of it. The
173173
/// `chunk_size` must be a power of two.
174-
pub fn get_sha1_checksums(data: &[u8], chunk_size: u64) -> Result<(Digest, Vec<Digest>)> {
174+
pub fn get_sha1_checksums(data: &[u8], chunk_size: usize) -> Result<(Digest, Vec<Digest>)> {
175175
if !chunk_size.is_power_of_two() {
176176
bail!("Chunk size must be a power of two");
177177
}
178178

179179
let mut total_sha = Sha1::new();
180180
let mut chunks = Vec::new();
181181

182-
for chunk in data.chunks(chunk_size as usize) {
182+
for chunk in data.chunks(chunk_size) {
183183
let mut chunk_sha = Sha1::new();
184184
chunk_sha.update(chunk);
185185
total_sha.update(chunk);

src/utils/proguard_upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ChunkedMapping {
3838
let raw_data = fs::read(mapping)?;
3939
let file_name = format!("/proguard/{}.txt", mapping.uuid);
4040

41-
let (hash, chunk_hashes) = get_sha1_checksums(&raw_data, chunk_size)?;
41+
let (hash, chunk_hashes) = get_sha1_checksums(&raw_data, chunk_size as usize)?;
4242
Ok(Self {
4343
raw_data,
4444
hash,

0 commit comments

Comments
 (0)