Fix cargo fmt formatting

This commit is contained in:
MattJackson
2026-04-16 17:51:45 +00:00
parent 8de99bb8e8
commit 8820f7a460
8 changed files with 60 additions and 36 deletions
+1
View File
@@ -0,0 +1 @@
max_width = 100
-3
View File
@@ -326,13 +326,11 @@ fn read_disc_key(drive: &mut Drive, agid: u8, bus_key: &[u8; 5]) -> Result<[u8;
// Disc key block starts at offset 4 (skip 4-byte header)
let disc_key_block = &mut buf[4..4 + 2048];
// XOR with reversed bus key (per libdvdcss)
for (i, byte) in disc_key_block.iter_mut().enumerate() {
*byte ^= bus_key[4 - (i % 5)];
}
// Try each player key against each of 408 disc key entries.
// Each entry in the block is the disc key encrypted with a specific player key.
// We try all known player keys and verify by checking that two different
@@ -421,7 +419,6 @@ fn read_title_key(
);
tk_result.map_err(|_| Error::CssAuthFailed)?;
// Title key at bytes 5..10, byte-reversed
let mut title_key = [0u8; 5];
for i in 0..5 {
+6 -2
View File
@@ -204,7 +204,9 @@ pub fn crack_title_key(sector: &[u8]) -> Option<[u8; 5]> {
// Padding stream (0xBE): payload is 0xFF bytes, various lengths
for len_hi in 0u8..8 {
for len_lo_top in [0x00u8, 0x80, 0xFF] {
patterns.push([0x00, 0x00, 0x01, 0xBE, len_hi, len_lo_top, 0xFF, 0xFF, 0xFF, 0xFF]);
patterns.push([
0x00, 0x00, 0x01, 0xBE, len_hi, len_lo_top, 0xFF, 0xFF, 0xFF, 0xFF,
]);
}
}
@@ -216,7 +218,9 @@ pub fn crack_title_key(sector: &[u8]) -> Option<[u8; 5]> {
let pts0 = if flags2 & 0x80 != 0 { 0x21u8 } else { 0x00 };
// Try with several PES lengths
for &len_hi in &[0x00u8, 0x07] {
patterns.push([0x00, 0x00, 0x01, sid, len_hi, 0x00, flags1, flags2, hdr_len, pts0]);
patterns.push([
0x00, 0x00, 0x01, sid, len_hi, 0x00, flags1, flags2, hdr_len, pts0,
]);
}
}
}
+1 -4
View File
@@ -958,10 +958,7 @@ impl Disc {
&& disc.content_format == ContentFormat::MpegPs
&& !disc.titles.is_empty()
{
let lba = disc.titles[0]
.extents
.iter()
.find_map(|ext| {
let lba = disc.titles[0].extents.iter().find_map(|ext| {
let mut buf = vec![0u8; 2048];
if session.read_sectors(ext.start_lba, 1, &mut buf).is_ok() {
if crate::css::is_scrambled(&buf) {
+10 -3
View File
@@ -62,7 +62,10 @@ impl Default for Mpeg2Parser {
impl Mpeg2Parser {
pub fn new() -> Self {
Self { seq_header: None, has_extension: false }
Self {
seq_header: None,
has_extension: false,
}
}
/// Extract resolution from a captured sequence header.
@@ -137,14 +140,18 @@ impl CodecParser for Mpeg2Parser {
} else {
let mut bits = 63u32; // bits consumed so far
let intra = (data[sc + 11] & 0x02) != 0;
if intra { bits += 64 * 8; }
if intra {
bits += 64 * 8;
}
// Non-intra flag is at current bit position
let byte_pos = (bits / 8) as usize;
let bit_pos = 7 - (bits % 8) as u8;
if sc + 4 + byte_pos < data.len() {
let non_intra = (data[sc + 4 + byte_pos] >> bit_pos) & 1 != 0;
bits += 1;
if non_intra { bits += 64 * 8; }
if non_intra {
bits += 64 * 8;
}
}
let total_bytes = 4 + ((bits + 7) / 8) as usize;
(sc + total_bytes).min(data.len())
+4 -8
View File
@@ -285,8 +285,7 @@ impl crate::pes::Stream for DiscStream {
dts: ps.dts.map(|d| d as i64),
data: ps.data.clone(),
};
if let Some((_, parser)) =
self.parsers.iter_mut().find(|(p, _)| *p == pid)
if let Some((_, parser)) = self.parsers.iter_mut().find(|(p, _)| *p == pid)
{
for frame in parser.parse(&pes) {
self.pending_frames.push_back(
@@ -354,13 +353,10 @@ impl crate::pes::Stream for DiscStream {
data: ps.data.clone(),
};
if let Some((_, parser)) =
self.parsers.iter_mut().find(|(p, _)| *p == pid)
{
if let Some((_, parser)) = self.parsers.iter_mut().find(|(p, _)| *p == pid) {
for frame in parser.parse(&pes) {
self.pending_frames.push_back(
crate::pes::PesFrame::from_codec_frame(track, frame),
);
self.pending_frames
.push_back(crate::pes::PesFrame::from_codec_frame(track, frame));
}
}
}
+29 -7
View File
@@ -27,7 +27,9 @@ fn css_descramble_sector_roundtrip_via_public_api() {
assert_eq!(sector[0x14] & 0x30, 0x00, "flag not cleared");
// Header preserved (except flag byte)
for i in 0..128 {
if i == 0x14 { continue; }
if i == 0x14 {
continue;
}
assert_eq!(sector[i], original[i], "header byte {} changed", i);
}
// Encrypted region modified
@@ -504,17 +506,33 @@ fn css_roundtrip_with_snapshot() {
// Determinism: same input → same output
let mut sector2 = original.clone();
css::lfsr::descramble_sector(&title_key, &mut sector2);
assert_eq!(&sector[0x80..2048], &sector2[0x80..2048], "not deterministic");
assert_eq!(
&sector[0x80..2048],
&sector2[0x80..2048],
"not deterministic"
);
}
/// Multiple key/seed combinations produce different outputs.
#[test]
fn css_roundtrip_multiple_keys() {
let cases: &[([u8; 5], [u8; 5])] = &[
([0x00, 0x00, 0x00, 0x00, 0x00], [0x00, 0x00, 0x00, 0x00, 0x00]),
([0xFF, 0xFF, 0xFF, 0xFF, 0xFF], [0xFF, 0xFF, 0xFF, 0xFF, 0xFF]),
([0x01, 0x02, 0x03, 0x04, 0x05], [0xAA, 0xBB, 0xCC, 0xDD, 0xEE]),
([0xAB, 0xCD, 0xEF, 0x01, 0x23], [0x12, 0x34, 0x56, 0x78, 0x9A]),
(
[0x00, 0x00, 0x00, 0x00, 0x00],
[0x00, 0x00, 0x00, 0x00, 0x00],
),
(
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
),
(
[0x01, 0x02, 0x03, 0x04, 0x05],
[0xAA, 0xBB, 0xCC, 0xDD, 0xEE],
),
(
[0xAB, 0xCD, 0xEF, 0x01, 0x23],
[0x12, 0x34, 0x56, 0x78, 0x9A],
),
];
let mut results = Vec::new();
@@ -530,7 +548,11 @@ fn css_roundtrip_multiple_keys() {
// Different keys/seeds should produce different outputs
for i in 0..results.len() {
for j in (i + 1)..results.len() {
assert_ne!(results[i], results[j], "cases {} and {} produced same output", i, j);
assert_ne!(
results[i], results[j],
"cases {} and {} produced same output",
i, j
);
}
}
}