Consolidates three identical near-duplicate encoders: the
standard-alphabet base64 implementation lived in three places
before -- _b64_encode in flare.http.auth,
_base64_encode in flare.ws.client, _b64_encode_srv in
flare.ws.server -- each with the same RFC 4648 §4 table and
the same chunk-of-3 / pad-tail loop. This module is the single
canonical home; the three call sites now import from here.
The URL-safe (RFC 4648 §5, no padding) variant for cookies and
JWT lives at :mod:flare.crypto.hmac
(:func:base64url_encode / :func:base64url_decode); the two
alphabets diverge on + / / vs - / _ and on
padding behaviour. The HTTP-side Basic auth header
(RFC 7617) and the WebSocket Sec-WebSocket-Accept derivation
(RFC 6455 §4.2.2) require the standard alphabet with =
padding, which is what this module provides.
Public API
from flare.crypto.base64 import base64_encode, base64_decode
- :func:
base64_encode(data: Span[UInt8, _]) -> String --
alphabet A-Za-z0-9+/ with = padding to a multiple of 4.
- :func:
base64_decode(s: String) raises -> List[UInt8] --
inverse; tolerates missing padding, raises on invalid bytes.