"""Tests for the Obok (Kobo) plugin core.""" import io import dedrm_test_utils as U obok = U.load("obok") def test_unpad_strips_trailing_pad_length(): # obok.unpad trusts the final byte as the pad length; it is not a validating # PKCS#7 implementation, so the name reflects what it actually does. assert obok.unpad(b"data\x04\x04\x04\x04") == b"data" def test_kobo_hash_keys_are_stable_ascii_salts(): # These four salts are baked into Kobo's userkey derivation # (sha256(hash + macaddr) -> deviceid). Pinning the exact values is # intentional: a silent typo here would break decryption for every user, so # we want a hard regression guard rather than only a shape check. keys = obok.KOBO_HASH_KEYS assert keys == ["88b3a2e13", "XzUhGYdFp", "NoCanLook", "QJhwzAtXL"] # The derivation feeds each salt to ``.encode('ascii')``; pin that contract. for k in keys: assert isinstance(k, str) and k k.encode("ascii") class _FakeStream: encoding = "utf-8" def __init__(self): self.buffer = io.BytesIO() def test_safeunbuffered_encodes_str(): fake = _FakeStream() obok.SafeUnbuffered(fake).write("héllo") assert fake.buffer.getvalue() == "héllo".encode("utf-8") def test_safeunbuffered_passes_bytes_through(): fake = _FakeStream() obok.SafeUnbuffered(fake).write(b"\x00\x01\x02") assert fake.buffer.getvalue() == b"\x00\x01\x02"