def fernet_decrypt_psk(token, ttl=None, raw=False):
"""Decrypts the specified Fernet token using the MAAS secret.
Returns the decrypted token as a byte string; the user is responsible for
converting it to the correct format or encoding.
:param message: The token to decrypt.
:type token: Must be of type 'bytes', or an ASCII base64 string.
:param ttl: Optional amount of time (in seconds) allowed to have elapsed
before the message is rejected upon decryption. Note that the Fernet
library considers times up to 60 seconds into the future (beyond the
TTL) to be valid.
:param raw: if True, treats the string as the decoded base64 bytes of a
Fernet token, and attempts to encode them (as expected by the Fernet
APIs) before decrypting.
:return: bytes
"""
if raw is True:
token = urlsafe_b64encode(token)
f = _get_fernet_context()
if isinstance(token, str):
token = token.encode("ascii")
return f.decrypt(token, ttl=ttl)
评论列表
文章目录