dictature 0.13.2__tar.gz → 0.14.0__tar.gz

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.
Files changed (27) hide show
  1. {dictature-0.13.2/src/dictature.egg-info → dictature-0.14.0}/PKG-INFO +1 -1
  2. {dictature-0.13.2 → dictature-0.14.0}/pyproject.toml +1 -1
  3. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/mysql.py +1 -1
  4. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/sqlite.py +1 -1
  5. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/transformer/aes.py +19 -4
  6. {dictature-0.13.2 → dictature-0.14.0/src/dictature.egg-info}/PKG-INFO +1 -1
  7. {dictature-0.13.2 → dictature-0.14.0}/tests/test_operations.py +2 -0
  8. {dictature-0.13.2 → dictature-0.14.0}/LICENSE +0 -0
  9. {dictature-0.13.2 → dictature-0.14.0}/README.md +0 -0
  10. {dictature-0.13.2 → dictature-0.14.0}/setup.cfg +0 -0
  11. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/__init__.py +0 -0
  12. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/__init__.py +0 -0
  13. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/directory.py +0 -0
  14. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/misp.py +0 -0
  15. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/mock.py +0 -0
  16. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/s3.py +0 -0
  17. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/backend/webdav.py +0 -0
  18. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/dictature.py +0 -0
  19. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/transformer/__init__.py +0 -0
  20. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/transformer/gzip.py +0 -0
  21. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/transformer/hmac.py +0 -0
  22. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/transformer/mock.py +0 -0
  23. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/transformer/passthrough.py +0 -0
  24. {dictature-0.13.2 → dictature-0.14.0}/src/dictature/transformer/pipeline.py +0 -0
  25. {dictature-0.13.2 → dictature-0.14.0}/src/dictature.egg-info/SOURCES.txt +0 -0
  26. {dictature-0.13.2 → dictature-0.14.0}/src/dictature.egg-info/dependency_links.txt +0 -0
  27. {dictature-0.13.2 → dictature-0.14.0}/src/dictature.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dictature
3
- Version: 0.13.2
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dictature"
7
- version = "0.13.2"
7
+ version = "0.14.0"
8
8
  description = "dictature -- A generic wrapper around dict-like interface with mulitple backends"
9
9
  authors = [
10
10
  { name = "Adam Hlavacek", email = "git@adamhlavacek.com" }
@@ -38,7 +38,7 @@ class DictatureBackendMySQL(DictatureBackendMock):
38
38
  def keys(self) -> Iterable[str]:
39
39
  # noinspection SqlResolve
40
40
  tables = self._execute(f"SELECT table_name FROM information_schema.tables WHERE table_schema = %s AND table_name LIKE '{self.__prefix}%'", (self.__connection_params['database'],))
41
- return {table[0][3:] for table in tables}
41
+ return {table[0][len(self.__prefix):] for table in tables}
42
42
 
43
43
  def table(self, name: str) -> 'DictatureTableMock':
44
44
  return DictatureTableMySQL(self, name, self.__prefix)
@@ -24,7 +24,7 @@ class DictatureBackendSQLite(DictatureBackendMock):
24
24
 
25
25
  def keys(self) -> Iterable[str]:
26
26
  tables = self._execute(f"SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name LIKE '{self.__prefix}%'")
27
- return {table[0][3:] for table in tables}
27
+ return {table[0][len(self.__prefix):] for table in tables}
28
28
 
29
29
  def table(self, name: str) -> 'DictatureTableMock':
30
30
  return DictatureTableSQLite(self, name, self.__prefix)
@@ -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__(self, passphrase: str, static_names_mode: bool, salt: str = 'dictature') -> None:
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
- return (cipher.nonce + tag + ciphertext).hex()
40
+ data = (cipher.nonce + tag + ciphertext)
28
41
  else:
29
- return cipher.encrypt(pad(text.encode('utf8'), AES.block_size)).hex()
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 = bytes.fromhex(text)
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.13.2
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
@@ -2,6 +2,7 @@ import unittest
2
2
  from itertools import product
3
3
  from typing import NamedTuple, Optional
4
4
  from tempfile import mkdtemp, mktemp
5
+ from base64 import b64decode, b64encode
5
6
 
6
7
  from parameterized import parameterized
7
8
 
@@ -25,6 +26,7 @@ TRANSFORMERS = [
25
26
  PassthroughTransformer(),
26
27
  AESTransformer('password', False),
27
28
  AESTransformer('password', True),
29
+ AESTransformer('password', True, bytes_encoder=(lambda x: b64encode(x).decode('ascii')), bytes_decoder=(lambda x: b64decode(x.encode('ascii')))),
28
30
  HmacTransformer(),
29
31
  HmacTransformer('password'),
30
32
  GzipTransformer(),
File without changes
File without changes
File without changes