black formating

This commit is contained in:
callebtc
2022-06-01 14:53:05 +02:00
parent 7c4ce9bf96
commit f8400512f7
28 changed files with 127 additions and 81 deletions
+1 -1
View File
@@ -1 +1 @@
from .macaroon import load_macaroon, AESCipher
from .macaroon import load_macaroon, AESCipher
+10 -6
View File
@@ -5,10 +5,11 @@ from hashlib import md5
import getpass
BLOCK_SIZE = 16
import getpass
import getpass
def load_macaroon(macaroon: str) -> str:
"""Returns hex version of a macaroon encoded in base64 or the file path.
"""Returns hex version of a macaroon encoded in base64 or the file path.
:param macaroon: Macaroon encoded in base64 or file path.
:type macaroon: str
@@ -29,6 +30,7 @@ def load_macaroon(macaroon: str) -> str:
pass
return macaroon
class AESCipher(object):
"""This class is compatible with crypto-js/aes.js
@@ -39,6 +41,7 @@ class AESCipher(object):
AES.decrypt(encrypted, password).toString(Utf8);
"""
def __init__(self, key=None, description=""):
self.key = key
self.description = description + " "
@@ -47,7 +50,6 @@ class AESCipher(object):
length = BLOCK_SIZE - (len(data) % BLOCK_SIZE)
return data + (chr(length) * length).encode()
def unpad(self, data):
return data[: -(data[-1] if type(data[-1]) == int else ord(data[-1]))]
@@ -70,8 +72,7 @@ class AESCipher(object):
return final_key[:output]
def decrypt(self, encrypted: str) -> str:
"""Decrypts a string using AES-256-CBC.
"""
"""Decrypts a string using AES-256-CBC."""
passphrase = self.passphrase
encrypted = base64.b64decode(encrypted)
assert encrypted[0:8] == b"Salted__"
@@ -92,7 +93,10 @@ class AESCipher(object):
key = key_iv[:32]
iv = key_iv[32:]
aes = AES.new(key, AES.MODE_CBC, iv)
return base64.b64encode(b"Salted__" + salt + aes.encrypt(self.pad(message))).decode()
return base64.b64encode(
b"Salted__" + salt + aes.encrypt(self.pad(message))
).decode()
# if this file is executed directly, ask for a macaroon and encrypt it
if __name__ == "__main__":