nacl_middleware package#

Submodules#

nacl_middleware.nacl_middleware module#

nacl_middleware.nacl_middleware.nacl_middleware(private_key: ~nacl.public.PrivateKey, exclude_routes: ~typing.Tuple = (), exclude_methods: ~typing.Tuple = (), log=<RootLogger root (DEBUG)>) Callable[[Request, Callable[[Request], Awaitable[StreamResponse]]], Awaitable[StreamResponse]][source]#

Middleware function that handles NaCl encryption and decryption.

Args:

private_key (PrivateKey): The private key used for decryption. exclude_routes (Tuple, optional): Tuple of routes to exclude from encryption/decryption. Defaults to an empty tuple. exclude_methods (Tuple, optional): Tuple of HTTP methods to exclude from encryption/decryption. Defaults to an empty tuple. log (Logger, optional): Logger object for logging debug messages. Defaults to getLogger().

Returns:

Middleware: The middleware function.

nacl_middleware.nacl_utils module#

class nacl_middleware.nacl_utils.MailBox(private_key: PrivateKey, hex_public_key: str)[source]#

Bases: object

box(message: any) str[source]#

Encrypts the given message using the NaCl encryption algorithm.

Parameters: message (any): The message to be encrypted.

Returns: str: The encrypted message as a string.

unbox(encrypted_message: str) any[source]#

Decrypts the encrypted message using the private key and returns the decrypted message.

Parameters: encrypted_message (str): The encrypted message to be decrypted.

Returns: any: The decrypted message.

class nacl_middleware.nacl_utils.Nacl(private_key: ~nacl.public.PrivateKey = <nacl.public.PrivateKey object>, encoder=<class 'nacl.encoding.HexEncoder'>)[source]#

Bases: object

A class that provides utility functions for encoding and decoding Nacl keys.

decoded_private_key() str[source]#

Decode the private key using the specified encoder.

Returns:

str: The decoded private key as a string.

decoded_public_key() str[source]#

Decode the public key of the private key using the specified encoder.

Returns:

str: The decoded public key as a string.

private_key: PrivateKey#
nacl_middleware.nacl_utils.custom_loads(obj) any[source]#

Custom loads function that deserializes a JSON string into a Python object.

Args:

obj (str): The JSON string to be deserialized.

Returns:

any: The deserialized Python object.

nacl_middleware.utils module#

nacl_middleware.utils.is_exclude(request: Request, exclude: Tuple) bool[source]#

Check if the request path matches any pattern in the exclude list.

Args:

request (Request): The request object. exclude (Tuple): A tuple of patterns to exclude.

Returns:

bool: True if the request path matches any pattern in the exclude list, False otherwise.

Module contents#