Files
DeDRM_tools/tests/test_kgenpids.py
T
JMR-devandClaude Opus 4.8 d407298be4 Update tests for shared helpers and fix test nits
- Cover the new utilities helpers (unpad, crc32, checksumPid type
  preservation, pidFromSerial, safe_join) and drop the now-redundant
  per-module crc32 tests.
- Rename test_unpad_removes_pkcs7_padding to reflect that unpad only
  trusts the trailing pad-length byte rather than validating PKCS#7.
- Replace the KOBO_HASH_KEYS change-detector with a test that documents
  the intentional value pin and checks the ASCII-salt contract.
- Note kgenpids' hybrid import in the test-loader docstring.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 09:18:01 -05:00

36 lines
984 B
Python

"""Tests for Kindle PID generation helpers (kgenpids)."""
import dedrm_test_utils as U
kg = U.load("kgenpids")
def test_encode_known_vector():
assert kg.encode(b"\x00\x01\x42\xff\x80", kg.charMap1) == b"6n65tPrMnn"
def test_encode_doubles_length():
data = b"\x10\x20\x30"
assert len(kg.encode(data, kg.charMap1)) == 2 * len(data)
def test_two_bits_from_bit_field():
assert [kg.getTwoBitsFromBitField(b"\x1b\x2c\x3d\x4e", i) for i in range(4)] == [0, 1, 2, 3]
def test_six_bits_from_bit_field():
assert kg.getSixBitsFromBitField(b"\xff\xff\xff\xff", 0) == 63
def test_pid_encryption_table_is_crc32_table():
table = kg.generatePidEncryptionTable()
assert len(table) == 256
assert table[0] == 0
# Standard reflected CRC-32 table entry.
assert table[1] == 0x77073096
def test_generate_device_pid_known_vector():
table = kg.generatePidEncryptionTable()
assert kg.generateDevicePID(table, b"\x12\x34\x56\x78", 4) == b"22I8IQVF"