PASETO
Platform-Agnostic Security Tokens, versions 3 and 4.
oxcrypto.paseto encodes and decodes PASETO v3 and v4 tokens in the local
(symmetric encryption) and public (signature) purposes, following the
PASETO specification. It is
built directly on oxcrypto primitives; no PASETO crate is used.
from secrets import token_bytes
from oxcrypto.paseto import PASETO, unverified_footer
key = token_bytes(32)
token = PASETO.V4_LOCAL.encode(b'{"sub":"alice"}', key, footer=b'{"kid":"1"}')
assert unverified_footer(token) == b'{"kid":"1"}'
assert PASETO.V4_LOCAL.decode(token, key) == b'{"sub":"alice"}'The selector fixes the version and purpose. A token with another header
(v3.local. decoded as V4_LOCAL, a public token decoded as local)
raises InvalidTag, and a key of the wrong type raises TypeError, so a
public key cannot be used as a local key. A failed MAC, signature, footer or
implicit-assertion check raises InvalidTag; verify returns False
instead. A malformed token raises ValueError.
footer is authenticated and sent in the clear. When decode gets a
footer, the token's footer must equal it (compared in constant time).
implicit_assertion is authenticated but not sent, and must be passed again
when decoding. The message and footer are bytes; claims validation such as
exp is left to the caller.
Versions
Tests use every v3 and v4 vector from paseto-standard/test-vectors, including the failure cases.
Zeroization
The derived encryption key, nonce and authentication key and the decrypted plaintext buffer are held in wiped buffers and wiped when a call returns. Signing keys follow the zeroization notes of their signature family.
Zeroization does not cover:
- Local keys, messages and footers passed in or returned as Python
bytes. - Short-lived stack copies made by
aes,ctr,chacha20,hmac,hkdfandblake2, including the keystream and MAC state during a call.
Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.