Rename is_scrambled to has_scramble_flag_bits
The 1.6.1 DVD fix removed the USE of the loose predicate but left the predicate sitting there with the better name. Anyone asking "is this sector scrambled?" finds is_scrambled before is_scrambled_pack, and reintroduces the defect that destroyed 1912 bytes of a real VIDEO_TS.IFO — the sector carrying TT_SRPT — so the disc enumerated 38 titles and an image decrypted from it enumerated 10, silently, at exit 0. Byte 0x14 only means "scrambling control" inside an MPEG-2 pack. In an IFO, UDF or ISO 9660 sector it is whatever that format stores there. The new name says what the function actually tests and nothing more, so the honest question has the obvious name and the dangerous one has to be asked for deliberately. Its doc comment also claimed a caller, decrypt::decrypt_sectors, that does not exist — so the name was an invitation and the documentation was an argument for accepting it. It has no production callers at all; it stays public because an integration test asserts the flag extraction directly.
This commit is contained in:
+12
-6
@@ -37,30 +37,36 @@ fn css_descramble_sector_roundtrip_via_public_api() {
|
||||
assert_ne!(§or[128..256], &original[128..256]);
|
||||
}
|
||||
|
||||
/// Test: css_is_scrambled detects scramble flags correctly.
|
||||
/// Test: has_scramble_flag_bits detects the raw flag bits correctly.
|
||||
#[test]
|
||||
fn css_is_scrambled_detection() {
|
||||
let mut sector = vec![0u8; 2048];
|
||||
assert!(
|
||||
!css::is_scrambled(§or),
|
||||
!css::has_scramble_flag_bits(§or),
|
||||
"empty sector should not be scrambled"
|
||||
);
|
||||
|
||||
sector[0x14] = 0x10; // bit 4 set
|
||||
assert!(css::is_scrambled(§or), "bit 4 set should be detected");
|
||||
assert!(
|
||||
css::has_scramble_flag_bits(§or),
|
||||
"bit 4 set should be detected"
|
||||
);
|
||||
|
||||
sector[0x14] = 0x20; // bit 5 set
|
||||
assert!(css::is_scrambled(§or), "bit 5 set should be detected");
|
||||
assert!(
|
||||
css::has_scramble_flag_bits(§or),
|
||||
"bit 5 set should be detected"
|
||||
);
|
||||
|
||||
sector[0x14] = 0x30; // both bits set
|
||||
assert!(
|
||||
css::is_scrambled(§or),
|
||||
css::has_scramble_flag_bits(§or),
|
||||
"both bits set should be detected"
|
||||
);
|
||||
|
||||
sector[0x14] = 0xCF; // bits 4-5 clear, other bits set
|
||||
assert!(
|
||||
!css::is_scrambled(§or),
|
||||
!css::has_scramble_flag_bits(§or),
|
||||
"bits 4-5 clear should not be scrambled"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user