feat(core): add HDR Vivid hybrids and a MonaLisa command builder

This commit is contained in:
CodeName393
2026-12-01 15:29:03 -06:00
committed by GitHub
parent 71b8b63037
commit 90ab0ca4cb
27 changed files with 756 additions and 119 deletions
+68 -4
View File
@@ -24,8 +24,8 @@ def make_drm(monkeypatch: pytest.MonkeyPatch):
"""Build a MonaLisa with a known key; extract_keys needs a real device file, so it is skipped."""
monkeypatch.setattr(MonaLisa, "extract_keys", lambda self: None)
def build(tool: Path) -> MonaLisa:
drm = MonaLisa("ticket", Path("unused.mld"), tool)
def build(tool: Path, **kwargs) -> MonaLisa:
drm = MonaLisa("ticket", Path("unused.mld"), tool, **kwargs)
drm._kid = UUID(int=1)
drm._key = "00" * 16
return drm
@@ -79,8 +79,8 @@ def test_a_timeout_keeps_the_ciphertext_and_hides_the_key(
monkeypatch.setattr(tool_runner.subprocess, "run", hang)
drm = make_drm(tool)
with pytest.raises(RuntimeError, match="timed out") as raised:
drm.decrypt(track)
with pytest.raises(RuntimeError, match="timed out after 60s") as raised:
drm.decrypt_segment(track)
assert drm.key_pair not in str(raised.value)
assert raised.value.__suppress_context__
assert track.read_bytes() == b"cipher"
@@ -93,3 +93,67 @@ def test_a_good_run_replaces_the_file_and_drops_the_temp_output(
make_drm(tool).decrypt(track)
assert track.read_bytes() == b"plain"
assert not track.with_name("track_decrypted.mp4").exists()
@pytest.mark.parametrize("build", ["constructor", "from_ticket"])
def test_a_service_command_builder_replaces_the_default_command(
make_drm, track: Path, tool: Path, monkeypatch: pytest.MonkeyPatch, build: str
) -> None:
commands = []
def run(cmd, **kwargs):
commands.append((cmd, kwargs["timeout"]))
Path(cmd[-1]).write_bytes(b"plain")
return subprocess.CompletedProcess(cmd, 0, b"", b"")
def command(tool_path, src, dst, kid, key):
return [tool_path, f"{kid}/{key}", src, dst]
monkeypatch.setattr(tool_runner.subprocess, "run", run)
if build == "constructor":
drm = make_drm(tool, command_builder=command, segment_decrypt=False)
else:
drm = MonaLisa.from_ticket("ticket", Path("unused.mld"), tool, command, False)
drm._kid, drm._key = UUID(int=1), "00" * 16
assert not drm.supports_segment_decrypt
drm.decrypt(track)
output = track.with_name("track_decrypted.mp4")
assert commands == [([str(tool), f"{drm.kid.hex}/{drm.key}", str(track), str(output)], None)]
assert track.read_bytes() == b"plain"
@pytest.mark.parametrize("segment_decrypt", [True, False])
def test_every_in_place_file_is_decrypted(
make_drm, track: Path, tool: Path, monkeypatch: pytest.MonkeyPatch, segment_decrypt: bool
) -> None:
fake_tool(monkeypatch, b"plain")
drm = make_drm(tool, segment_decrypt=segment_decrypt)
other = track.with_name("other.mp4")
other.write_bytes(b"cipher")
drm.decrypt(track)
drm.decrypt(other)
assert (track.read_bytes(), other.read_bytes()) == (b"plain", b"plain")
assert not drm.track_decrypted
def test_a_track_that_the_service_decrypted_is_not_decrypted_again(
make_drm, track: Path, tool: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
fake_tool(monkeypatch, b"plain")
drm = make_drm(tool, segment_decrypt=False)
out = track.with_name("out.mp4")
drm.decrypt(track, out)
fake_tool(monkeypatch, b"twice")
drm.decrypt(out)
assert drm.track_decrypted and out.read_bytes() == b"plain"
def test_a_segment_tool_decrypts_every_file_it_gets_an_output_path_for(
make_drm, track: Path, tool: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
fake_tool(monkeypatch, b"plain")
drm = make_drm(tool)
outputs = [track.with_name(f"{i}.mp4") for i in range(2)]
for output in outputs:
drm.decrypt(track, output)
assert [output.read_bytes() for output in outputs] == [b"plain", b"plain"]