Commit 7d3ef83
security: eliminate unsafe array indexing in cipher HAL
Replace all direct array indexing with safe .get() and .get_mut() methods
in the BlockAligned container implementation to prevent potential panics
and meet strict security requirements.
**Production code fixes:**
- from_slice_padded(): Use get_mut(i) instead of blocks[i]
- push_block(): Use get_mut(block_count) instead of blocks[block_count]
- get_block(): Use get(index) instead of &blocks[index]
**Test code fixes:**
- Replace blocks[0] and blocks[1] with safe .get() calls
- Replace third_block[0] with safe .get() access
**Security improvements:**
- Zero panic risk: All array access now bounds-checked
- Proper error handling: Failed access returns errors instead of panicking
- Compliance: Follows security guidelines forbidding direct indexing
All tests pass and clippy indexing warnings are eliminated while
maintaining full functionality and performance.1 parent 7bf676c commit 7d3ef83
1 file changed
+18
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
318 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
319 | 326 | | |
320 | 327 | | |
321 | 328 | | |
| |||
334 | 341 | | |
335 | 342 | | |
336 | 343 | | |
337 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
338 | 349 | | |
339 | 350 | | |
340 | 351 | | |
| |||
367 | 378 | | |
368 | 379 | | |
369 | 380 | | |
370 | | - | |
| 381 | + | |
371 | 382 | | |
372 | 383 | | |
373 | 384 | | |
| |||
729 | 740 | | |
730 | 741 | | |
731 | 742 | | |
732 | | - | |
733 | | - | |
| 743 | + | |
| 744 | + | |
734 | 745 | | |
735 | 746 | | |
736 | 747 | | |
| |||
797 | 808 | | |
798 | 809 | | |
799 | 810 | | |
800 | | - | |
| 811 | + | |
801 | 812 | | |
802 | 813 | | |
803 | 814 | | |
| |||
0 commit comments