"""Strict base64 codec for persisted byte fields.The one home for the ASCII base64 round-trip this project persists bytematerial through. Decoding is strict: ``validate=True`` refuses any characteroutside the base64 alphabet rather than silently discarding it, so a corruptedor hand-edited record fails at the boundary instead of yielding shorter bytesthat still parse.Lives in :mod:`core` because its callers sit in two packages that must notimport each other — the shared-master key surface and the per-profile custodysurface — and a primitive shared by both belongs beneath both rather than ineither. Duplicating a two-line wrapper to avoid that dependency would put thesame encoding decision in two places, where only one of them would be fixed."""from__future__importannotationsimportbase64__all__=["b64_decode","b64_encode"]
[docs]defb64_encode(data:bytes)->str:"""Return ``data`` as an ASCII base64 string."""returnbase64.b64encode(data).decode("ascii")
[docs]defb64_decode(text:str)->bytes:"""Return the bytes of a strict ASCII base64 string. Raises: binascii.Error: When ``text`` carries any character outside the base64 alphabet, or is not correctly padded. """returnbase64.b64decode(text.encode("ascii"),validate=True)