diff options
Diffstat (limited to 'accounts/utils/sessions.py')
-rw-r--r-- | accounts/utils/sessions.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/accounts/utils/sessions.py b/accounts/utils/sessions.py index a452fe1..47580bd 100644 --- a/accounts/utils/sessions.py +++ b/accounts/utils/sessions.py @@ -18,7 +18,7 @@ def _pad(value: str, block_size: int) -> bytes: def _unpad(value: str) -> str: - pad_length = ord(value[len(value)-1:]) + pad_length = ord(value[len(value) - 1 :]) return value[:-pad_length] @@ -29,7 +29,7 @@ class EncryptedSerializer(TaggedJSONSerializer): self.block_size = AES.block_size def _cipher(self, iv: bytes): - key = accounts_app.config['SESSION_ENCRYPTION_KEY'] + key = accounts_app.config["SESSION_ENCRYPTION_KEY"] assert len(key) == 32 return AES.new(key, AES.MODE_CBC, iv) @@ -50,10 +50,9 @@ class EncryptedSerializer(TaggedJSONSerializer): `config.SESSION_ENCRYPTION_KEY`. """ decoded = b64decode(value.encode("UTF-8")) - iv = decoded[:self.block_size] - raw = self._cipher(iv).decrypt(decoded[AES.block_size:]) - return super(EncryptedSerializer, self) \ - .loads(_unpad(raw)) + iv = decoded[: self.block_size] + raw = self._cipher(iv).decrypt(decoded[AES.block_size :]) + return super(EncryptedSerializer, self).loads(_unpad(raw)) class EncryptedSessionInterface(SecureCookieSessionInterface): @@ -63,13 +62,15 @@ class EncryptedSessionInterface(SecureCookieSessionInterface): session = None try: parent = super(EncryptedSessionInterface, self) - session = cast(EncryptedSessionInterface, parent) \ - .open_session(app, request) + session = cast(EncryptedSessionInterface, parent).open_session( + app, request + ) except BadPayload: session = self.session_class() if session is not None: - session.permanent = \ - app.config.get('PERMANENT_SESSION_LIFETIME') is not None + session.permanent = ( + app.config.get("PERMANENT_SESSION_LIFETIME") is not None + ) return session |