spei-python 0.48.5__tar.gz → 0.48.7__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 (39) hide show
  1. {spei_python-0.48.5 → spei_python-0.48.7}/PKG-INFO +1 -1
  2. {spei_python-0.48.5 → spei_python-0.48.7}/pyproject.toml +2 -2
  3. {spei_python-0.48.5 → spei_python-0.48.7}/spei/cep_generator.py +44 -27
  4. {spei_python-0.48.5 → spei_python-0.48.7}/README.md +0 -0
  5. {spei_python-0.48.5 → spei_python-0.48.7}/spei/README.md +0 -0
  6. {spei_python-0.48.5 → spei_python-0.48.7}/spei/__init__.py +0 -0
  7. {spei_python-0.48.5 → spei_python-0.48.7}/spei/checksum/__init__.py +0 -0
  8. {spei_python-0.48.5 → spei_python-0.48.7}/spei/checksum/factory.py +0 -0
  9. {spei_python-0.48.5 → spei_python-0.48.7}/spei/checksum/generator.py +0 -0
  10. {spei_python-0.48.5 → spei_python-0.48.7}/spei/checksum/types.py +0 -0
  11. {spei_python-0.48.5 → spei_python-0.48.7}/spei/client.py +0 -0
  12. {spei_python-0.48.5 → spei_python-0.48.7}/spei/errors/__init__.py +0 -0
  13. {spei_python-0.48.5 → spei_python-0.48.7}/spei/errors/sice.py +0 -0
  14. {spei_python-0.48.5 → spei_python-0.48.7}/spei/errors/spei.py +0 -0
  15. {spei_python-0.48.5 → spei_python-0.48.7}/spei/exceptions.py +0 -0
  16. {spei_python-0.48.5 → spei_python-0.48.7}/spei/mappings.py +0 -0
  17. {spei_python-0.48.5 → spei_python-0.48.7}/spei/requests/__init__.py +0 -0
  18. {spei_python-0.48.5 → spei_python-0.48.7}/spei/requests/acuse.py +0 -0
  19. {spei_python-0.48.5 → spei_python-0.48.7}/spei/requests/cda.py +0 -0
  20. {spei_python-0.48.5 → spei_python-0.48.7}/spei/requests/orden.py +0 -0
  21. {spei_python-0.48.5 → spei_python-0.48.7}/spei/requests/respuesta.py +0 -0
  22. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/__init__.py +0 -0
  23. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/acuse.py +0 -0
  24. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/cda.py +0 -0
  25. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/ensesion.py +0 -0
  26. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/mensaje.py +0 -0
  27. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/orden.py +0 -0
  28. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/payments.py +0 -0
  29. {spei_python-0.48.5 → spei_python-0.48.7}/spei/resources/respuesta.py +0 -0
  30. {spei_python-0.48.5 → spei_python-0.48.7}/spei/responses/__init__.py +0 -0
  31. {spei_python-0.48.5 → spei_python-0.48.7}/spei/responses/acuse.py +0 -0
  32. {spei_python-0.48.5 → spei_python-0.48.7}/spei/responses/orden.py +0 -0
  33. {spei_python-0.48.5 → spei_python-0.48.7}/spei/responses/respuesta.py +0 -0
  34. {spei_python-0.48.5 → spei_python-0.48.7}/spei/sice.py +0 -0
  35. {spei_python-0.48.5 → spei_python-0.48.7}/spei/types/__init__.py +0 -0
  36. {spei_python-0.48.5 → spei_python-0.48.7}/spei/types/sice.py +0 -0
  37. {spei_python-0.48.5 → spei_python-0.48.7}/spei/types/spei.py +0 -0
  38. {spei_python-0.48.5 → spei_python-0.48.7}/spei/utils.py +0 -0
  39. {spei_python-0.48.5 → spei_python-0.48.7}/spei/validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spei-python
3
- Version: 0.48.5
3
+ Version: 0.48.7
4
4
  Summary:
5
5
  Author: tech
6
6
  Author-email: tech@fondeadora.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "spei-python"
3
- version = "0.48.5"
3
+ version = "0.48.7"
4
4
  description = ""
5
5
  authors = ["tech <tech@fondeadora.com>"]
6
6
  readme = "README.md"
@@ -32,7 +32,7 @@ build-backend = "poetry.core.masonry.api"
32
32
 
33
33
  [tool.commitizen]
34
34
  name = "cz_conventional_commits"
35
- version = "0.48.5"
35
+ version = "0.48.7"
36
36
  tag_format = "v$version"
37
37
  bump_message = "bump: Semantic Release Bot: Release Version: $new_version 🤖🚀 [skip ci]"
38
38
  version_files = [
@@ -1,13 +1,14 @@
1
1
  import base64
2
+ import binascii
2
3
  import datetime
3
4
  from enum import Enum
4
- from os import urandom
5
5
 
6
6
  from cryptography.hazmat.backends import default_backend
7
7
  from cryptography.hazmat.primitives import padding
8
8
  from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
9
9
 
10
- IV_LIMIT = 16
10
+ AES_128 = algorithms.AES128
11
+ KEY_SIZE = int(AES_128.block_size / 8)
11
12
 
12
13
 
13
14
  class SearchCriteria(Enum):
@@ -16,9 +17,12 @@ class SearchCriteria(Enum):
16
17
 
17
18
 
18
19
  class CepGenerator(object):
19
- def __init__(self, key_base64, rng=urandom):
20
- self.key_base64 = key_base64
21
- self.rng = rng
20
+ def __init__(self, hex_key: str):
21
+ cleaned_hex_key = hex_key.replace(':', '')
22
+ raw_key = binascii.unhexlify(cleaned_hex_key)
23
+
24
+ self.key = raw_key[:KEY_SIZE]
25
+ self.iv = raw_key[KEY_SIZE:]
22
26
 
23
27
  def generate_cep(
24
28
  self,
@@ -44,38 +48,51 @@ class CepGenerator(object):
44
48
  return self._encrypt_string(string)
45
49
 
46
50
  def decrypt_string(self, encrypted_data_base64: str) -> str: # noqa: WPS210
47
- backend = default_backend()
48
51
  encrypted_data = base64.b64decode(encrypted_data_base64)
49
- iv = encrypted_data[:IV_LIMIT]
50
- cipher = Cipher(
51
- algorithms.AES(base64.b64decode(self.key_base64)),
52
- modes.CBC(iv),
53
- backend=backend,
54
- )
55
- decryptor = cipher.decryptor()
56
- decrypted_data = decryptor.update(
57
- encrypted_data[IV_LIMIT:],
58
- ) + decryptor.finalize()
59
- unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
52
+ decryptor = self.decryptor()
53
+
54
+ decrypted_data = decryptor.update(encrypted_data) + decryptor.finalize()
55
+
56
+ unpadder = self.unpadder
60
57
  unpadded_data = unpadder.update(decrypted_data) + unpadder.finalize()
61
58
 
62
59
  return unpadded_data.decode()
63
60
 
61
+ def encryptor(self, backend=None):
62
+ return self.cipher(backend=backend).encryptor()
63
+
64
+ def decryptor(self, backend=None):
65
+ return self.cipher(backend=backend).decryptor()
66
+
67
+ def cipher(self, backend=None):
68
+ return Cipher(
69
+ AES_128(self.key),
70
+ modes.CBC(self.iv),
71
+ backend=backend or default_backend(),
72
+ )
73
+
74
+ @property
75
+ def padder(self):
76
+ return self.padding.padder()
77
+
78
+ @property
79
+ def unpadder(self):
80
+ return self.padding.unpadder()
81
+
82
+ @property
83
+ def padding(self):
84
+ return padding.PKCS7(AES_128.block_size)
85
+
64
86
  def _format_date(self, date: datetime.datetime) -> str:
65
87
  return date.strftime('%Y%m%d')
66
88
 
67
89
  def _encrypt_string(self, string: str) -> str: # noqa: WPS210
68
- backend = default_backend()
69
- iv = self.rng(IV_LIMIT)
70
- cipher = Cipher(
71
- algorithms.AES(base64.b64decode(self.key_base64)),
72
- modes.CBC(iv),
73
- backend=backend,
74
- )
75
- encryptor = cipher.encryptor()
76
- padder = padding.PKCS7(algorithms.AES.block_size).padder()
90
+ encryptor = self.encryptor()
91
+
92
+ padder = self.padder
77
93
  padded_data = padder.update(string.encode()) + padder.finalize()
94
+
78
95
  encrypted_data = encryptor.update(padded_data) + encryptor.finalize()
79
- encrypted_data_base64 = base64.b64encode(iv + encrypted_data)
96
+ encrypted_data_base64 = base64.b64encode(encrypted_data)
80
97
 
81
98
  return encrypted_data_base64.decode()
File without changes
File without changes
File without changes