Zero clippy warnings: fix all 32 remaining

- Iterator::find() replaces manual loops (6 sites)
- Index-only loops → iterators (4 sites)
- Identical if-blocks merged
- Box large MkvStream WriteState enum variant
- Vec macro initializers, late init fixes
- Unused fields prefixed with underscore (format spec fields)
- Dead code removed or documented

0 clippy warnings. 319 tests passing.
This commit is contained in:
MattJackson
2026-04-11 19:33:13 +00:00
parent 75f15cae62
commit f48b4925c1
27 changed files with 80 additions and 106 deletions
+4 -4
View File
@@ -63,7 +63,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
// Clock LFSR1 forward 4 steps to reconstruct LFSR0 state
let mut t3: u32 = 0;
for i in 0..4 {
for &buf_byte in buf.iter().take(4) {
// Advance LFSR1
let t4 = TAB2[t2 as usize] ^ TAB3[t1 as usize];
t2 = t1 >> 1;
@@ -71,7 +71,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
let t4_perm = TAB5[t4 as usize];
// Deduce LFSR0 output from the buffer and LFSR1 output
let mut t6 = buf[i] as u32;
let mut t6 = buf_byte as u32;
if t5 > 0 {
t6 = (t6 + 0xFF) & 0xFF;
}
@@ -91,7 +91,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
// Phase 3: Validate — clock 6 more steps and check against buffer
let mut valid = true;
for i in 4..10 {
for &buf_byte in buf.iter().skip(4) {
let t4 = TAB2[t2 as usize] ^ TAB3[t1 as usize];
t2 = t1 >> 1;
t1 = ((t1 & 1) << 8) ^ t4 as u32;
@@ -103,7 +103,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
let t6_perm = TAB4[(t6 & 0xFF) as usize];
t5 += t6_perm as u32 + t4_perm as u32;
if (t5 & 0xFF) as u8 != buf[i] {
if (t5 & 0xFF) as u8 != buf_byte {
valid = false;
break;
}
+8 -8
View File
@@ -57,7 +57,7 @@ pub fn descramble_sector(title_key: &[u8; 5], sector: &mut [u8]) {
let mut combined: u32 = 0;
// Generate 1920 keystream bytes (for sector bytes 128..2048)
for i in 128..2048 {
for byte in sector.iter_mut().take(2048).skip(128) {
// Clock LFSR1
let o_lfsr1 = TAB2[lfsr1_hi as usize] ^ TAB3[lfsr1_lo as usize];
lfsr1_hi = lfsr1_lo >> 1;
@@ -70,7 +70,7 @@ pub fn descramble_sector(title_key: &[u8; 5], sector: &mut [u8]) {
// Combine with addition and carry
combined += (o_lfsr0 ^ 0xFF) as u32 + o_lfsr1_perm as u32;
sector[i] ^= (combined & 0xFF) as u8;
*byte ^= (combined & 0xFF) as u8;
combined >>= 8;
}
@@ -102,7 +102,7 @@ pub(crate) fn decrypt_key(invert: u8, p_key: &[u8; 5], p_crypted: &[u8]) -> [u8;
let mut combined: u32 = 0;
let mut k = [0u8; 5];
for i in 0..5 {
for byte in &mut k {
let o_lfsr1 = TAB2[lfsr1_hi as usize] ^ TAB3[lfsr1_lo as usize];
lfsr1_hi = lfsr1_lo >> 1;
lfsr1_lo = ((lfsr1_lo & 1) << 8) ^ o_lfsr1 as u32;
@@ -112,7 +112,7 @@ pub(crate) fn decrypt_key(invert: u8, p_key: &[u8; 5], p_crypted: &[u8]) -> [u8;
lfsr0 = (lfsr0 >> 8) | ((o_lfsr0 as u32) << 24);
combined += (o_lfsr0 ^ invert) as u32 + o_lfsr1_perm as u32;
k[i] = (combined & 0xFF) as u8;
*byte = (combined & 0xFF) as u8;
combined >>= 8;
}
@@ -257,8 +257,8 @@ mod tests {
sector[0x82] = 0x01;
sector[0x83] = 0xE0;
// Fill some content in the encrypted region
for i in 0x84..2048 {
sector[i] = (i & 0xFF) as u8;
for (i, byte) in sector.iter_mut().enumerate().take(2048).skip(0x84) {
*byte = (i & 0xFF) as u8;
}
let original = sector.clone();
@@ -299,8 +299,8 @@ mod tests {
#[test]
fn css_tab1_is_permutation() {
let mut seen = [false; 256];
for i in 0..256 {
let v = TAB1[i] as usize;
for tab1_val in &TAB1 {
let v = *tab1_val as usize;
assert!(!seen[v], "TAB1 maps two inputs to {:#04x}", v);
seen[v] = true;
}