API Reference

A Python implementation of PASETO <https://pyseto.readthedocs.io>

pyseto.encode(key: pyseto.key_interface.KeyInterface, payload: Union[bytes, str], footer: Union[bytes, str] = b'', implicit_assertion: Union[bytes, str] = b'', nonce: bytes = b'') bytes[source]

Encodes a message to a PASETO token with a key.

Parameters
  • key (KeyInterface) – A key for encryption or signing.

  • payload (Union[bytes, str]) – A message to be encrypted or signed.

  • footer (Union[bytes, str]) – A footer.

  • implicit_assertion (Union[bytes, str]) – An implicit assertion.

  • nonce (bytes) – A nonce.

Returns

A PASETO token.

Return type

str

Raises
  • ValueError – Invalid arguments.

  • EncryptError – Failed to encrypt the message.

  • SignError – Failed to sign the message.

pyseto.decode(keys: Union[pyseto.key_interface.KeyInterface, List[pyseto.key_interface.KeyInterface]], token: Union[bytes, str], implicit_assertion: Union[bytes, str] = b'') pyseto.token.Token[source]

Decodes a PASETO token with a key.

Parameters
  • key (KeyInterface) – A key for decryption or verifying the signature in the token.

  • token (Union[bytes, str]) – A PASETO token to be decrypted or verified.

  • implicit_assertion (Optional[Union[bytes, str]]) – An implicit assertion.

Returns

A parsed PASETO token object.

Return type

Token

Raises
  • ValueError – Invalid arguments.

  • DecryptError – Failed to decrypt the message.

  • VerifyError – Failed to verify the message.

class pyseto.Key[source]

Bases: object

static new(version: str, type: str, key: Union[bytes, str] = b'')[source]
static from_asymmetric_key_params(version: str, x: bytes = b'', y: bytes = b'', d: bytes = b'')[source]
exception pyseto.PysetoError[source]

Bases: Exception

Base class for all exceptions.

exception pyseto.DecryptError[source]

Bases: pyseto.exceptions.PysetoError

An Exception occurred when an decryption process failed.

exception pyseto.EncryptError[source]

Bases: pyseto.exceptions.PysetoError

An Exception occurred when an encryption process failed.

exception pyseto.NotSupportedError[source]

Bases: pyseto.exceptions.PysetoError

An Exception occurred when the function is not supported for the key object.

exception pyseto.SignError[source]

Bases: pyseto.exceptions.PysetoError

An Exception occurred when a signing process failed.

exception pyseto.VerifyError[source]

Bases: pyseto.exceptions.PysetoError

An Exception occurred when a verification process failed.

class pyseto.key_interface.KeyInterface(version: str, type: str, key: Any)[source]

Bases: object

The key interface class for PASETO.

property version: str
property type: str
property header: bytes
encrypt(payload: bytes, footer: bytes = b'', implicit_assertion: bytes = b'', nonce: bytes = b'') bytes[source]
decrypt(payload: bytes, footer: bytes = b'', implicit_assertion: bytes = b'') bytes[source]
sign(payload: bytes, footer: bytes = b'', implicit_assertion: bytes = b'') bytes[source]
verify(payload: bytes, footer: bytes = b'', implicit_assertion: bytes = b'') bytes[source]
class pyseto.token.Token(version: str, purpose: str, payload: bytes, footer: bytes = b'')[source]

Bases: object

The parsed PASETO token class.

classmethod new(token: Union[bytes, str])[source]
property version: str
property purpose: str
property header: bytes
property payload: bytes
property footer: bytes