Skip to content

Commit f15cd63

Browse files
rusty1968FerralCoder
authored andcommitted
fix: resolve clippy warnings in cipher HAL
Address clippy warnings for safer and more idiomatic code: **get_first warnings:** - Replace `.get(0)` with `.first()` for accessing first array elements - More expressive and idiomatic Rust code **arithmetic_side_effects warnings:** - Replace `+=` with `.saturating_add()` for safe increment - Replace `*` with `.saturating_mul()` for safe multiplication - Prevents potential overflow in arithmetic operations **Security improvements:** - Arithmetic operations now cannot overflow/panic - Follows security guidelines for overflow-safe operations - All tests continue to pass with improved safety These changes align with the project's strict safety requirements while maintaining full functionality and performance.
1 parent ebd48c6 commit f15cd63

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

hal/blocking/src/cipher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<const BLOCK_SIZE: usize, const MAX_BLOCKS: usize> BlockAligned<BLOCK_SIZE,
346346
.get_mut(self.block_count)
347347
.ok_or(BlockAlignedError::CapacityExceeded)?;
348348
*block_slot = block;
349-
self.block_count += 1;
349+
self.block_count = self.block_count.saturating_add(1);
350350
Ok(())
351351
}
352352

@@ -357,7 +357,7 @@ impl<const BLOCK_SIZE: usize, const MAX_BLOCKS: usize> BlockAligned<BLOCK_SIZE,
357357

358358
/// Get the total number of bytes in valid blocks.
359359
pub const fn len(&self) -> usize {
360-
self.block_count * BLOCK_SIZE
360+
self.block_count.saturating_mul(BLOCK_SIZE)
361361
}
362362

363363
/// Check if the container is empty.
@@ -740,7 +740,7 @@ mod tests {
740740

741741
let blocks = container.blocks();
742742
assert_eq!(blocks.len(), 2);
743-
assert_eq!(blocks.get(0).unwrap(), &block1);
743+
assert_eq!(blocks.first().unwrap(), &block1);
744744
assert_eq!(blocks.get(1).unwrap(), &block2);
745745
}
746746

@@ -808,7 +808,7 @@ mod tests {
808808

809809
// Third block should have one byte of data and 15 bytes of padding
810810
let third_block = container.get_block(2).unwrap();
811-
assert_eq!(third_block.get(0).unwrap(), &0x42);
811+
assert_eq!(third_block.first().unwrap(), &0x42);
812812
assert_eq!(&third_block[1..], &[0xFF; 15]);
813813
}
814814

0 commit comments

Comments
 (0)