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
- class nacl_middleware.nacl_utils.Nacl(private_key: ~nacl.public.PrivateKey = <nacl.public.PrivateKey object>, encoder=<class 'nacl.encoding.HexEncoder'>)[source]#
Bases:
objectA 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.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.