dictature 0.13.3__py3-none-any.whl → 0.14.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dictature/transformer/aes.py +19 -4
- {dictature-0.13.3.dist-info → dictature-0.14.0.dist-info}/METADATA +1 -1
- {dictature-0.13.3.dist-info → dictature-0.14.0.dist-info}/RECORD +6 -6
- {dictature-0.13.3.dist-info → dictature-0.14.0.dist-info}/LICENSE +0 -0
- {dictature-0.13.3.dist-info → dictature-0.14.0.dist-info}/WHEEL +0 -0
- {dictature-0.13.3.dist-info → dictature-0.14.0.dist-info}/top_level.txt +0 -0
dictature/transformer/aes.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from typing import Callable, Optional
|
2
|
+
|
1
3
|
try:
|
2
4
|
from Crypto.Cipher import AES
|
3
5
|
from Crypto.Util.Padding import pad, unpad
|
@@ -9,27 +11,40 @@ from .mock import MockTransformer
|
|
9
11
|
|
10
12
|
|
11
13
|
class AESTransformer(MockTransformer):
|
12
|
-
def __init__(
|
14
|
+
def __init__(
|
15
|
+
self,
|
16
|
+
passphrase: str,
|
17
|
+
static_names_mode: bool,
|
18
|
+
salt: str = 'dictature',
|
19
|
+
bytes_encoder: Optional[Callable[[bytes], str]] = None,
|
20
|
+
bytes_decoder: Optional[Callable[[str], bytes]] = None
|
21
|
+
) -> None:
|
13
22
|
"""
|
14
23
|
Create a new AES transformer
|
15
24
|
:param passphrase: secret passphrase to encrypt/decrypt the data
|
16
25
|
:param static_names_mode: if True, the transformer will use ECB mode instead of GCM (True decreases security, increases speed)
|
17
26
|
:param salt: salt to use for the key derivation
|
27
|
+
:param bytes_encoder: function to encode bytes to string, can be e.g. b64encode (default: hex)
|
28
|
+
:param bytes_decoder: function to decode string to bytes, can be e.g. b64decode (default: hex)
|
18
29
|
"""
|
19
30
|
self.__key = scrypt(passphrase, salt, 16, N=2 ** 14, r=8, p=1)
|
20
31
|
self.__mode = AES.MODE_GCM if not static_names_mode else AES.MODE_ECB
|
21
32
|
self.__static = static_names_mode
|
33
|
+
self.__bytes_encoder = bytes_encoder if bytes_encoder else (lambda b: b.hex())
|
34
|
+
self.__bytes_decoder = bytes_decoder if bytes_decoder else (lambda s: bytes.fromhex(s))
|
22
35
|
|
23
36
|
def forward(self, text: str) -> str:
|
24
37
|
cipher = self.__cipher()
|
25
38
|
if self.__mode == AES.MODE_GCM:
|
26
39
|
ciphertext, tag = cipher.encrypt_and_digest(pad(text.encode('utf8'), AES.block_size))
|
27
|
-
|
40
|
+
data = (cipher.nonce + tag + ciphertext)
|
28
41
|
else:
|
29
|
-
|
42
|
+
data = cipher.encrypt(pad(text.encode('utf8'), AES.block_size))
|
43
|
+
|
44
|
+
return self.__bytes_encoder(data)
|
30
45
|
|
31
46
|
def backward(self, text: str) -> str:
|
32
|
-
data =
|
47
|
+
data = self.__bytes_decoder(text)
|
33
48
|
if self.__mode == AES.MODE_GCM:
|
34
49
|
nonce, tag, ciphertext = data[:16], data[16:32], data[32:]
|
35
50
|
return unpad(self.__cipher(nonce=nonce).decrypt_and_verify(ciphertext, tag), AES.block_size).decode('utf8')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: dictature
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.14.0
|
4
4
|
Summary: dictature -- A generic wrapper around dict-like interface with mulitple backends
|
5
5
|
Author-email: Adam Hlavacek <git@adamhlavacek.com>
|
6
6
|
Project-URL: Homepage, https://github.com/esoadamo/dictature
|
@@ -9,14 +9,14 @@ dictature/backend/s3.py,sha256=9Vcf4-RagyjpV9F4m9ZQ1vjb4lbZfEcOZQBuD_SPwZg,6580
|
|
9
9
|
dictature/backend/sqlite.py,sha256=4_fBCo1_rmCRXronYbows1gjsuQgzqaOvcFqrz24Efw,5451
|
10
10
|
dictature/backend/webdav.py,sha256=Y-3_WTcMyKVUnsVjiUZAxuy10FK0Yr-7Mgn13clg3po,5039
|
11
11
|
dictature/transformer/__init__.py,sha256=JIFJpXU6iB9hIUM8L7HL2o9Nqjm_YbMEuQBQC8ZJ6b4,124
|
12
|
-
dictature/transformer/aes.py,sha256=
|
12
|
+
dictature/transformer/aes.py,sha256=KGJh6OtQpYVIcn7-DaoGg_cP980s9Ssgt6DlcF-YD2w,2582
|
13
13
|
dictature/transformer/gzip.py,sha256=pngvJQeALa-lv98VBeJ1Pl6_gaAfGcPXD9UR7PexrYA,1921
|
14
14
|
dictature/transformer/hmac.py,sha256=vURsB0HlzRPn_Vkl7lGmZV9OKempQuds8AanmadDxIo,834
|
15
15
|
dictature/transformer/mock.py,sha256=7zu65ZqUV_AVRaPSzNd73cVMXixXt31SeuX9OKZxaJQ,948
|
16
16
|
dictature/transformer/passthrough.py,sha256=Pt3N6G_Qh6HJ_q75ETL5nfAwYHLB-SjkVwUwbbbMik8,344
|
17
17
|
dictature/transformer/pipeline.py,sha256=OaQaJeJ5NpICetJe08r8ontqstsXGuW8jDbKw1zxYs4,842
|
18
|
-
dictature-0.
|
19
|
-
dictature-0.
|
20
|
-
dictature-0.
|
21
|
-
dictature-0.
|
22
|
-
dictature-0.
|
18
|
+
dictature-0.14.0.dist-info/LICENSE,sha256=n1U9DKr8sM5EY2QHcvxSGiKTDWUT8MyXsOC79w94MT0,1072
|
19
|
+
dictature-0.14.0.dist-info/METADATA,sha256=IZXRjbTEfVjIPggFVALBcHJNHK-gc0YiFPCabtbjII0,3394
|
20
|
+
dictature-0.14.0.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
21
|
+
dictature-0.14.0.dist-info/top_level.txt,sha256=-RO39WWCF44lqiXhSUcACVqbk6SkgReZTz7ZmHKH3-U,10
|
22
|
+
dictature-0.14.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|