Skip to content

jam.paseto.base

__base__

Classes:

Name Description
BasePASETO

Base PASETO instance.

BasePASETO

BasePASETO()

Bases: ABC

Base PASETO instance.

Methods:

Name Description
decode

Decode PASETO.

encode

Generate token from key instance.

key

Create a PASETO instance with the given key.

load_rsa_key

Load rsa key from string | bytes.

Attributes:

Name Type Description
purpose Literal['local', 'public'] | None

Return PASETO purpose.

purpose property

purpose: Literal['local', 'public'] | None

Return PASETO purpose.

decode abstractmethod

decode(
    token: str,
    serializer: type[BaseEncoder]
    | BaseEncoder = JsonEncoder,
) -> tuple[dict[str, Any], dict[str, Any] | None]

Decode PASETO.

Parameters:

Name Type Description Default
token str

Token

required
serializer BaseEncoder

JSON Encoder

JsonEncoder

Returns:

Type Description
tuple[dict[str, Any], dict[str, Any] | None]

tuple[dict[str, Any], Optional[dict[str, Any]]]: Payload, footer

encode abstractmethod

encode(
    payload: dict[str, Any],
    footer: dict[str, Any] | str | None = None,
    serializer: type[BaseEncoder]
    | BaseEncoder = JsonEncoder,
) -> str

Generate token from key instance.

Parameters:

Name Type Description Default
payload dict[str, Any]

Payload for token

required
footer dict[str, Any] | str | None

Token footer

None
serializer BaseEncoder

JSON Encoder

JsonEncoder

key abstractmethod classmethod

key(
    purpose: Literal["local", "public"],
    secret_key: str | bytes,
) -> PASETO

Create a PASETO instance with the given key.

Parameters:

Name Type Description Default
purpose Literal['local', 'public']

'local' (symmetric encryption) or 'public' (asymmetric signing)

required
secret_key str | bytes

raw bytes or PEM text depending on purpose

required

Returns:

Name Type Description
PASETO PASETO

configured PASETO instance for encoding/decoding tokens.

load_rsa_key staticmethod

load_rsa_key(
    key: RSAKeyLike | None, *, private: bool = True
) -> Any

Load rsa key from string | bytes.

Parameters:

Name Type Description Default
key RSAKeyLike | None

RSA Key

required
private bool

Private or public

True

Raises:

Type Description
JamPASETOInvalidRSAKey

Invalid RSA key format.