maleo-foundation 0.1.74__tar.gz → 0.1.76__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.
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/PKG-INFO +2 -1
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/manager.py +14 -2
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/__init__.py +2 -0
- maleo_foundation-0.1.76/maleo_foundation/client/services/encryption/__init__.py +9 -0
- maleo_foundation-0.1.76/maleo_foundation/client/services/encryption/aes.py +54 -0
- maleo_foundation-0.1.76/maleo_foundation/client/services/encryption/rsa.py +68 -0
- maleo_foundation-0.1.76/maleo_foundation/expanded_types/encryption/__init__.py +7 -0
- maleo_foundation-0.1.76/maleo_foundation/expanded_types/encryption/aes.py +13 -0
- maleo_foundation-0.1.76/maleo_foundation/expanded_types/encryption/rsa.py +13 -0
- maleo_foundation-0.1.76/maleo_foundation/models/schemas/encryption.py +18 -0
- maleo_foundation-0.1.76/maleo_foundation/models/transfers/parameters/encryption/__init__.py +7 -0
- maleo_foundation-0.1.76/maleo_foundation/models/transfers/parameters/encryption/aes.py +13 -0
- maleo_foundation-0.1.76/maleo_foundation/models/transfers/parameters/encryption/rsa.py +12 -0
- maleo_foundation-0.1.76/maleo_foundation/models/transfers/results/encryption/__init__.py +7 -0
- maleo_foundation-0.1.76/maleo_foundation/models/transfers/results/encryption/aes.py +18 -0
- maleo_foundation-0.1.76/maleo_foundation/models/transfers/results/encryption/rsa.py +12 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation.egg-info/PKG-INFO +2 -1
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation.egg-info/SOURCES.txt +13 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation.egg-info/requires.txt +1 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/pyproject.toml +2 -1
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/README.md +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/authentication.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/hash/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/hash/bcrypt.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/hash/hmac.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/hash/sha256.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/signature.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/token.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/constants.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/enums.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/client.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/general.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/hash.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/query.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/service.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/signature.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/token.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/extended_types.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/base.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/google/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/google/base.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/google/secret.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/google/storage.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/maleo.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/db.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/middleware.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/service.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/middlewares/authentication.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/middlewares/base.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/middlewares/cors.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/responses.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/general.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/hash.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/parameter.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/result.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/signature.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/token.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/table.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/general/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/general/signature.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/general/token.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/client.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/general.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/hash/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/hash/bcrypt.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/hash/hmac.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/hash/sha256.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/service.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/signature.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/parameters/token.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/client/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/client/controllers/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/client/controllers/http.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/client/service.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/hash.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/service/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/service/controllers/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/service/controllers/rest.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/service/general.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/service/query.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/signature.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/results/token.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/types.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/controller.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/exceptions.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/extractor.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/formatter/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/formatter/case.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/json.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/key/__init__.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/key/rsa.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/yaml.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/logging.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/mergers.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/query.py +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation.egg-info/dependency_links.txt +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation.egg-info/top_level.txt +0 -0
- {maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: maleo_foundation
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.76
|
4
4
|
Summary: Foundation package for Maleo
|
5
5
|
Author-email: Agra Bima Yuda <agra@nexmedis.com>
|
6
6
|
License: MIT
|
@@ -8,6 +8,7 @@ Requires-Python: >=3.7
|
|
8
8
|
Description-Content-Type: text/markdown
|
9
9
|
Requires-Dist: annotated-types>=0.7.0
|
10
10
|
Requires-Dist: anyio>=4.9.0
|
11
|
+
Requires-Dist: bcrypt>=4.3.0
|
11
12
|
Requires-Dist: build>=1.2.2.post1
|
12
13
|
Requires-Dist: cachetools>=5.5.2
|
13
14
|
Requires-Dist: certifi>=2025.1.31
|
@@ -2,12 +2,17 @@ from __future__ import annotations
|
|
2
2
|
from maleo_foundation.managers.client.base import ClientManager
|
3
3
|
from maleo_foundation.types import BaseTypes
|
4
4
|
from maleo_foundation.utils.logging import SimpleConfig
|
5
|
+
from maleo_foundation.client.services.encryption import (
|
6
|
+
MaleoFoundationAESEncryptionClientService,
|
7
|
+
MaleoFoundationRSAEncryptionClientService
|
8
|
+
)
|
5
9
|
from maleo_foundation.client.services.hash import (
|
6
10
|
MaleoFoundationSHA256HashClientService,
|
7
11
|
MaleoFoundationHMACHashClientService,
|
8
12
|
MaleoFoundationBcryptHashClientService
|
9
13
|
)
|
10
14
|
from maleo_foundation.client.services import (
|
15
|
+
MaleoFoundationEncryptionServices,
|
11
16
|
MaleoFoundationHashServices,
|
12
17
|
MaleoFoundationSignatureClientService,
|
13
18
|
MaleoFoundationTokenClientService,
|
@@ -24,6 +29,12 @@ class MaleoFoundationClientManager(ClientManager):
|
|
24
29
|
|
25
30
|
def _initialize_services(self):
|
26
31
|
super()._initialize_services()
|
32
|
+
aes_encryption_service = MaleoFoundationAESEncryptionClientService(logger=self._logger)
|
33
|
+
rsa_encryption_service = MaleoFoundationRSAEncryptionClientService(logger=self._logger)
|
34
|
+
encryption_services = MaleoFoundationEncryptionServices(
|
35
|
+
aes=aes_encryption_service,
|
36
|
+
rsa=rsa_encryption_service
|
37
|
+
)
|
27
38
|
bcrypt_hash_service = MaleoFoundationBcryptHashClientService(logger=self._logger)
|
28
39
|
hmac_hash_service = MaleoFoundationHMACHashClientService(logger=self._logger)
|
29
40
|
sha256_hash_service = MaleoFoundationSHA256HashClientService(logger=self._logger)
|
@@ -35,9 +46,10 @@ class MaleoFoundationClientManager(ClientManager):
|
|
35
46
|
signature_service = MaleoFoundationSignatureClientService(logger=self._logger)
|
36
47
|
token_service = MaleoFoundationTokenClientService(logger=self._logger)
|
37
48
|
self._services = MaleoFoundationServices(
|
49
|
+
encryption=encryption_services,
|
50
|
+
hash=hash_services,
|
38
51
|
signature=signature_service,
|
39
|
-
token=token_service
|
40
|
-
hash=hash_services
|
52
|
+
token=token_service
|
41
53
|
)
|
42
54
|
|
43
55
|
@property
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/__init__.py
RENAMED
@@ -1,11 +1,13 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
from pydantic import Field
|
3
3
|
from maleo_foundation.managers.client.base import ClientServices
|
4
|
+
from maleo_foundation.client.services.encryption import MaleoFoundationEncryptionServices
|
4
5
|
from maleo_foundation.client.services.hash import MaleoFoundationHashServices
|
5
6
|
from maleo_foundation.client.services.signature import MaleoFoundationSignatureClientService
|
6
7
|
from maleo_foundation.client.services.token import MaleoFoundationTokenClientService
|
7
8
|
|
8
9
|
class MaleoFoundationServices(ClientServices):
|
10
|
+
encryption:MaleoFoundationEncryptionServices = Field(..., description="Encryption's services")
|
9
11
|
hash:MaleoFoundationHashServices = Field(..., description="Hash's services")
|
10
12
|
signature:MaleoFoundationSignatureClientService = Field(..., description="Signature's service")
|
11
13
|
token:MaleoFoundationTokenClientService = Field(..., description="Token's service")
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from pydantic import Field
|
3
|
+
from maleo_foundation.managers.client.base import ClientServices
|
4
|
+
from maleo_foundation.client.services.encryption.aes import MaleoFoundationAESEncryptionClientService
|
5
|
+
from maleo_foundation.client.services.encryption.rsa import MaleoFoundationRSAEncryptionClientService
|
6
|
+
|
7
|
+
class MaleoFoundationEncryptionServices(ClientServices):
|
8
|
+
aes:MaleoFoundationAESEncryptionClientService = Field(..., description="AES encryption's service")
|
9
|
+
rsa:MaleoFoundationRSAEncryptionClientService = Field(..., description="RSA encryption's service")
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import os
|
2
|
+
from base64 import b64decode, b64encode
|
3
|
+
from cryptography.hazmat.backends import default_backend
|
4
|
+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
5
|
+
from maleo_foundation.expanded_types.encryption.aes import BaseAESEncryptionResultsTypes
|
6
|
+
from maleo_foundation.managers.client.base import ClientService
|
7
|
+
from maleo_foundation.models.schemas.encryption import BaseEncryptionSchemas
|
8
|
+
from maleo_foundation.models.transfers.parameters.encryption.aes import BaseAESEncryptionParametersTransfers
|
9
|
+
from maleo_foundation.models.transfers.results.encryption.aes import EncryptData, BaseAESEncryptionResultsTransfers
|
10
|
+
from maleo_foundation.utils.exceptions import BaseExceptions
|
11
|
+
|
12
|
+
class MaleoFoundationAESEncryptionClientService(ClientService):
|
13
|
+
def encrypt(self, parameters:BaseAESEncryptionParametersTransfers.Encrypt) -> BaseAESEncryptionResultsTypes.Hash:
|
14
|
+
"""Encrypt a plaintext using AES algorithm."""
|
15
|
+
@BaseExceptions.service_exception_handler(
|
16
|
+
operation="encrypting plaintext",
|
17
|
+
logger=self._logger,
|
18
|
+
fail_result_class=BaseAESEncryptionResultsTransfers.Fail
|
19
|
+
)
|
20
|
+
def _impl():
|
21
|
+
#* Define random key and initialization vector bytes
|
22
|
+
key_bytes = os.urandom(32)
|
23
|
+
initialization_vector_bytes = os.urandom(16)
|
24
|
+
#* Encrypt message with encryptor instance
|
25
|
+
cipher = Cipher(algorithms.AES(key_bytes), modes.CFB(initialization_vector_bytes), backend=default_backend())
|
26
|
+
encryptor = cipher.encryptor()
|
27
|
+
ciphertext = b64encode(encryptor.update(parameters.plaintext.encode()) + encryptor.finalize()).decode('utf-8')
|
28
|
+
#* Encode the results to base64 strings
|
29
|
+
key = b64encode(key_bytes).decode('utf-8')
|
30
|
+
initialization_vector = b64encode(initialization_vector_bytes).decode('utf-8')
|
31
|
+
data = EncryptData(key=key, initialization_vector=initialization_vector, ciphertext=ciphertext)
|
32
|
+
self._logger.info("Plaintext successfully encrypted")
|
33
|
+
return BaseAESEncryptionResultsTransfers.Encrypt(data=data)
|
34
|
+
return _impl()
|
35
|
+
|
36
|
+
def decrypt(self, parameters:BaseAESEncryptionParametersTransfers.Decrypt) -> BaseAESEncryptionResultsTypes.Decrypt:
|
37
|
+
"""Decrypt a ciphertext using AES algorithm."""
|
38
|
+
@BaseExceptions.service_exception_handler(
|
39
|
+
operation="verify single encryption",
|
40
|
+
logger=self._logger,
|
41
|
+
fail_result_class=BaseAESEncryptionResultsTransfers.Fail
|
42
|
+
)
|
43
|
+
def _impl():
|
44
|
+
#* Decode base64-encoded AES key, IV, and encrypted message
|
45
|
+
key_bytes = b64decode(parameters.key)
|
46
|
+
initialization_vector_bytes = b64decode(parameters.initialization_vector)
|
47
|
+
#* Decrypt message with decryptor instance
|
48
|
+
cipher = Cipher(algorithms.AES(key_bytes), modes.CFB(initialization_vector_bytes), backend=default_backend())
|
49
|
+
decryptor = cipher.decryptor()
|
50
|
+
plaintext = decryptor.update(b64decode(parameters.ciphertext)) + decryptor.finalize()
|
51
|
+
data = BaseEncryptionSchemas.Plaintext(plaintext=plaintext)
|
52
|
+
self._logger.info("Ciphertext successfully decrypted")
|
53
|
+
return BaseAESEncryptionResultsTransfers.Decrypt(data=data)
|
54
|
+
return _impl()
|
@@ -0,0 +1,68 @@
|
|
1
|
+
from base64 import b64decode, b64encode
|
2
|
+
from Crypto.Cipher import PKCS1_OAEP
|
3
|
+
from Crypto.Hash import SHA256
|
4
|
+
from maleo_foundation.enums import BaseEnums
|
5
|
+
from maleo_foundation.expanded_types.encryption.rsa import BaseRSAEncryptionResultsTypes
|
6
|
+
from maleo_foundation.managers.client.base import ClientService
|
7
|
+
from maleo_foundation.models.schemas.encryption import BaseEncryptionSchemas
|
8
|
+
from maleo_foundation.models.transfers.parameters.encryption.rsa import BaseRSAEncryptionParametersTransfers
|
9
|
+
from maleo_foundation.models.transfers.results.encryption.rsa import BaseRSAEncryptionResultsTransfers
|
10
|
+
from maleo_foundation.utils.exceptions import BaseExceptions
|
11
|
+
from maleo_foundation.utils.loaders.key.rsa import RSAKeyLoader
|
12
|
+
|
13
|
+
class MaleoFoundationRSAEncryptionClientService(ClientService):
|
14
|
+
def encrypt(self, parameters:BaseRSAEncryptionParametersTransfers.Encrypt) -> BaseRSAEncryptionResultsTypes.Hash:
|
15
|
+
"""Encrypt a plaintext using RSA algorithm."""
|
16
|
+
@BaseExceptions.service_exception_handler(
|
17
|
+
operation="encrypting plaintext",
|
18
|
+
logger=self._logger,
|
19
|
+
fail_result_class=BaseRSAEncryptionResultsTransfers.Fail
|
20
|
+
)
|
21
|
+
def _impl():
|
22
|
+
try:
|
23
|
+
public_key = RSAKeyLoader.load_with_pycryptodome(type=BaseEnums.KeyType.PUBLIC, extern_key=parameters.key)
|
24
|
+
except TypeError:
|
25
|
+
message = "Invalid key type"
|
26
|
+
description = "A public key must be used for encrypting a plaintext"
|
27
|
+
other = "Ensure the given key is of type public key"
|
28
|
+
return BaseRSAEncryptionResultsTransfers.Fail(message=message, description=description, other=other)
|
29
|
+
except Exception as e:
|
30
|
+
self._logger.error("Unexpected error occured while trying to import key:\n'%s'", str(e), exc_info=True)
|
31
|
+
message = "Invalid key"
|
32
|
+
description = "Unexpected error occured while trying to import key"
|
33
|
+
other = "Ensure given key is valid"
|
34
|
+
return BaseRSAEncryptionResultsTransfers.Fail(message=message, description=description, other=other)
|
35
|
+
cipher = PKCS1_OAEP.new(public_key, hashAlgo=SHA256) #* Initialize cipher with OAEP padding and SHA-256
|
36
|
+
ciphertext = b64encode(cipher.encrypt(parameters.plaintext.encode('utf-8'))).decode('utf-8') #* Encrypt the plaintext and return as base64-encoded string
|
37
|
+
data = BaseEncryptionSchemas.Ciphertext(ciphertext=ciphertext)
|
38
|
+
self._logger.info("Plaintext successfully encrypted")
|
39
|
+
return BaseRSAEncryptionResultsTransfers.Encrypt(data=data)
|
40
|
+
return _impl()
|
41
|
+
|
42
|
+
def decrypt(self, parameters:BaseRSAEncryptionParametersTransfers.Decrypt) -> BaseRSAEncryptionResultsTypes.Decrypt:
|
43
|
+
"""Decrypt a ciphertext using RSA algorithm."""
|
44
|
+
@BaseExceptions.service_exception_handler(
|
45
|
+
operation="verify single encryption",
|
46
|
+
logger=self._logger,
|
47
|
+
fail_result_class=BaseRSAEncryptionResultsTransfers.Fail
|
48
|
+
)
|
49
|
+
def _impl():
|
50
|
+
try:
|
51
|
+
private_key = RSAKeyLoader.load_with_pycryptodome(type=BaseEnums.KeyType.PRIVATE, extern_key=parameters.key, passphrase=parameters.password)
|
52
|
+
except TypeError:
|
53
|
+
message = "Invalid key type"
|
54
|
+
description = "A private key must be used for decrypting a ciphertext"
|
55
|
+
other = "Ensure the given key is of type private key"
|
56
|
+
return BaseRSAEncryptionResultsTransfers.Fail(message=message, description=description, other=other)
|
57
|
+
except Exception as e:
|
58
|
+
self._logger.error("Unexpected error occured while trying to import key:\n'%s'", str(e), exc_info=True)
|
59
|
+
message = "Invalid key"
|
60
|
+
description = "Unexpected error occured while trying to import key"
|
61
|
+
other = "Ensure given key is valid"
|
62
|
+
return BaseRSAEncryptionResultsTransfers.Fail(message=message, description=description, other=other)
|
63
|
+
cipher = PKCS1_OAEP.new(private_key, hashAlgo=SHA256) #* Initialize cipher with OAEP padding and SHA-256
|
64
|
+
plaintext = cipher.decrypt(b64decode(parameters.ciphertext)) #* Decode the base64-encoded ciphertext and then decrypt
|
65
|
+
data = BaseEncryptionSchemas.Plaintext(plaintext=plaintext)
|
66
|
+
self._logger.info("Ciphertext successfully decrypted")
|
67
|
+
return BaseRSAEncryptionResultsTransfers.Decrypt(data=data)
|
68
|
+
return _impl()
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from typing import Union
|
2
|
+
from maleo_foundation.models.transfers.results.encryption.aes import BaseAESEncryptionResultsTransfers
|
3
|
+
|
4
|
+
class BaseAESEncryptionResultsTypes:
|
5
|
+
Encrypt = Union[
|
6
|
+
BaseAESEncryptionResultsTransfers.Fail,
|
7
|
+
BaseAESEncryptionResultsTransfers.Encrypt
|
8
|
+
]
|
9
|
+
|
10
|
+
Decrypt = Union[
|
11
|
+
BaseAESEncryptionResultsTransfers.Fail,
|
12
|
+
BaseAESEncryptionResultsTransfers.Decrypt
|
13
|
+
]
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from typing import Union
|
2
|
+
from maleo_foundation.models.transfers.results.encryption.rsa import BaseRSAEncryptionResultsTransfers
|
3
|
+
|
4
|
+
class BaseRSAEncryptionResultsTypes:
|
5
|
+
Encrypt = Union[
|
6
|
+
BaseRSAEncryptionResultsTransfers.Fail,
|
7
|
+
BaseRSAEncryptionResultsTransfers.Encrypt
|
8
|
+
]
|
9
|
+
|
10
|
+
Decrypt = Union[
|
11
|
+
BaseRSAEncryptionResultsTransfers.Fail,
|
12
|
+
BaseRSAEncryptionResultsTransfers.Decrypt
|
13
|
+
]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
from pydantic import BaseModel, Field
|
2
|
+
from maleo_foundation.types import BaseTypes
|
3
|
+
|
4
|
+
class BaseEncryptionSchemas:
|
5
|
+
class Key(BaseModel):
|
6
|
+
key:str = Field(..., description="Key")
|
7
|
+
|
8
|
+
class Password(BaseModel):
|
9
|
+
password:BaseTypes.OptionalString = Field(None, min_length=32, max_length=1024, description="password")
|
10
|
+
|
11
|
+
class InitializationVector(BaseModel):
|
12
|
+
initialization_vector:str = Field(..., description="Initialization vector")
|
13
|
+
|
14
|
+
class Plaintext(BaseModel):
|
15
|
+
plaintext:str = Field(..., description="Plaintext")
|
16
|
+
|
17
|
+
class Ciphertext(BaseModel):
|
18
|
+
ciphertext:str = Field(..., description="Ciphertext")
|
@@ -0,0 +1,7 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from .aes import BaseAESEncryptionParametersTransfers
|
3
|
+
from .rsa import BaseRSAEncryptionParametersTransfers
|
4
|
+
|
5
|
+
class BaseEncryptionParametersTransfers:
|
6
|
+
AES = BaseAESEncryptionParametersTransfers
|
7
|
+
RSA = BaseRSAEncryptionParametersTransfers
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from maleo_foundation.models.schemas.encryption import BaseEncryptionSchemas
|
2
|
+
|
3
|
+
class BaseAESEncryptionParametersTransfers:
|
4
|
+
class Encrypt(
|
5
|
+
BaseEncryptionSchemas.Plaintext,
|
6
|
+
BaseEncryptionSchemas.Key
|
7
|
+
): pass
|
8
|
+
|
9
|
+
class Decrypt(
|
10
|
+
BaseEncryptionSchemas.Ciphertext,
|
11
|
+
BaseEncryptionSchemas.InitializationVector,
|
12
|
+
BaseEncryptionSchemas.Key
|
13
|
+
): pass
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from maleo_foundation.models.schemas.encryption import BaseEncryptionSchemas
|
2
|
+
|
3
|
+
class BaseRSAEncryptionParametersTransfers:
|
4
|
+
class Encrypt(
|
5
|
+
BaseEncryptionSchemas.Plaintext,
|
6
|
+
BaseEncryptionSchemas.Key
|
7
|
+
): pass
|
8
|
+
|
9
|
+
class Decrypt(
|
10
|
+
BaseEncryptionSchemas.Ciphertext,
|
11
|
+
BaseEncryptionSchemas.Key
|
12
|
+
): pass
|
@@ -0,0 +1,18 @@
|
|
1
|
+
from pydantic import Field
|
2
|
+
from maleo_foundation.models.transfers.results.service.general import BaseServiceGeneralResultsTransfers
|
3
|
+
from maleo_foundation.models.schemas.encryption import BaseEncryptionSchemas
|
4
|
+
|
5
|
+
class EncryptData(
|
6
|
+
BaseEncryptionSchemas.Ciphertext,
|
7
|
+
BaseEncryptionSchemas.InitializationVector,
|
8
|
+
BaseEncryptionSchemas.Key
|
9
|
+
): pass
|
10
|
+
|
11
|
+
class BaseAESEncryptionResultsTransfers:
|
12
|
+
class Fail(BaseServiceGeneralResultsTransfers.Fail): pass
|
13
|
+
|
14
|
+
class Encrypt(BaseServiceGeneralResultsTransfers.SingleData):
|
15
|
+
data:EncryptData = Field(..., description="Single encryption data")
|
16
|
+
|
17
|
+
class Decrypt(BaseServiceGeneralResultsTransfers.SingleData):
|
18
|
+
data:BaseEncryptionSchemas.Plaintext = Field(..., description="Single decryption data")
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from pydantic import Field
|
2
|
+
from maleo_foundation.models.transfers.results.service.general import BaseServiceGeneralResultsTransfers
|
3
|
+
from maleo_foundation.models.schemas.encryption import BaseEncryptionSchemas
|
4
|
+
|
5
|
+
class BaseRSAEncryptionResultsTransfers:
|
6
|
+
class Fail(BaseServiceGeneralResultsTransfers.Fail): pass
|
7
|
+
|
8
|
+
class Encrypt(BaseServiceGeneralResultsTransfers.SingleData):
|
9
|
+
data:BaseEncryptionSchemas.Ciphertext = Field(..., description="Single encryption data")
|
10
|
+
|
11
|
+
class Decrypt(BaseServiceGeneralResultsTransfers.SingleData):
|
12
|
+
data:BaseEncryptionSchemas.Plaintext = Field(..., description="Single decryption data")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: maleo_foundation
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.76
|
4
4
|
Summary: Foundation package for Maleo
|
5
5
|
Author-email: Agra Bima Yuda <agra@nexmedis.com>
|
6
6
|
License: MIT
|
@@ -8,6 +8,7 @@ Requires-Python: >=3.7
|
|
8
8
|
Description-Content-Type: text/markdown
|
9
9
|
Requires-Dist: annotated-types>=0.7.0
|
10
10
|
Requires-Dist: anyio>=4.9.0
|
11
|
+
Requires-Dist: bcrypt>=4.3.0
|
11
12
|
Requires-Dist: build>=1.2.2.post1
|
12
13
|
Requires-Dist: cachetools>=5.5.2
|
13
14
|
Requires-Dist: certifi>=2025.1.31
|
@@ -16,6 +16,9 @@ maleo_foundation/client/manager.py
|
|
16
16
|
maleo_foundation/client/services/__init__.py
|
17
17
|
maleo_foundation/client/services/signature.py
|
18
18
|
maleo_foundation/client/services/token.py
|
19
|
+
maleo_foundation/client/services/encryption/__init__.py
|
20
|
+
maleo_foundation/client/services/encryption/aes.py
|
21
|
+
maleo_foundation/client/services/encryption/rsa.py
|
19
22
|
maleo_foundation/client/services/hash/__init__.py
|
20
23
|
maleo_foundation/client/services/hash/bcrypt.py
|
21
24
|
maleo_foundation/client/services/hash/hmac.py
|
@@ -28,6 +31,9 @@ maleo_foundation/expanded_types/query.py
|
|
28
31
|
maleo_foundation/expanded_types/service.py
|
29
32
|
maleo_foundation/expanded_types/signature.py
|
30
33
|
maleo_foundation/expanded_types/token.py
|
34
|
+
maleo_foundation/expanded_types/encryption/__init__.py
|
35
|
+
maleo_foundation/expanded_types/encryption/aes.py
|
36
|
+
maleo_foundation/expanded_types/encryption/rsa.py
|
31
37
|
maleo_foundation/managers/__init__.py
|
32
38
|
maleo_foundation/managers/db.py
|
33
39
|
maleo_foundation/managers/middleware.py
|
@@ -46,6 +52,7 @@ maleo_foundation/models/__init__.py
|
|
46
52
|
maleo_foundation/models/responses.py
|
47
53
|
maleo_foundation/models/table.py
|
48
54
|
maleo_foundation/models/schemas/__init__.py
|
55
|
+
maleo_foundation/models/schemas/encryption.py
|
49
56
|
maleo_foundation/models/schemas/general.py
|
50
57
|
maleo_foundation/models/schemas/hash.py
|
51
58
|
maleo_foundation/models/schemas/parameter.py
|
@@ -62,6 +69,9 @@ maleo_foundation/models/transfers/parameters/general.py
|
|
62
69
|
maleo_foundation/models/transfers/parameters/service.py
|
63
70
|
maleo_foundation/models/transfers/parameters/signature.py
|
64
71
|
maleo_foundation/models/transfers/parameters/token.py
|
72
|
+
maleo_foundation/models/transfers/parameters/encryption/__init__.py
|
73
|
+
maleo_foundation/models/transfers/parameters/encryption/aes.py
|
74
|
+
maleo_foundation/models/transfers/parameters/encryption/rsa.py
|
65
75
|
maleo_foundation/models/transfers/parameters/hash/__init__.py
|
66
76
|
maleo_foundation/models/transfers/parameters/hash/bcrypt.py
|
67
77
|
maleo_foundation/models/transfers/parameters/hash/hmac.py
|
@@ -74,6 +84,9 @@ maleo_foundation/models/transfers/results/client/__init__.py
|
|
74
84
|
maleo_foundation/models/transfers/results/client/service.py
|
75
85
|
maleo_foundation/models/transfers/results/client/controllers/__init__.py
|
76
86
|
maleo_foundation/models/transfers/results/client/controllers/http.py
|
87
|
+
maleo_foundation/models/transfers/results/encryption/__init__.py
|
88
|
+
maleo_foundation/models/transfers/results/encryption/aes.py
|
89
|
+
maleo_foundation/models/transfers/results/encryption/rsa.py
|
77
90
|
maleo_foundation/models/transfers/results/service/__init__.py
|
78
91
|
maleo_foundation/models/transfers/results/service/general.py
|
79
92
|
maleo_foundation/models/transfers/results/service/query.py
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "maleo_foundation"
|
7
|
-
version = "0.1.
|
7
|
+
version = "0.1.76"
|
8
8
|
description = "Foundation package for Maleo"
|
9
9
|
authors = [
|
10
10
|
{ name = "Agra Bima Yuda", email = "agra@nexmedis.com" }
|
@@ -15,6 +15,7 @@ requires-python = ">=3.7"
|
|
15
15
|
dependencies = [
|
16
16
|
"annotated-types>=0.7.0",
|
17
17
|
"anyio>=4.9.0",
|
18
|
+
"bcrypt>=4.3.0",
|
18
19
|
"build>=1.2.2.post1",
|
19
20
|
"cachetools>=5.5.2",
|
20
21
|
"certifi>=2025.1.31",
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/hash/bcrypt.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/hash/hmac.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/hash/sha256.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/signature.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/client/services/token.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/client.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/general.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/query.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/service.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/signature.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/expanded_types/token.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/base.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/google/base.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/managers/client/maleo.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/middlewares/authentication.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/general.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/parameter.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/result.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/signature.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/schemas/token.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/models/transfers/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/formatter/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/formatter/case.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/__init__.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/key/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation/utils/loaders/key/rsa.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.74 → maleo_foundation-0.1.76}/maleo_foundation.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|