maleo-foundation 0.1.73__py3-none-any.whl → 0.1.75__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.
@@ -2,7 +2,13 @@ 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.hash import (
6
+ MaleoFoundationSHA256HashClientService,
7
+ MaleoFoundationHMACHashClientService,
8
+ MaleoFoundationBcryptHashClientService
9
+ )
5
10
  from maleo_foundation.client.services import (
11
+ MaleoFoundationHashServices,
6
12
  MaleoFoundationSignatureClientService,
7
13
  MaleoFoundationTokenClientService,
8
14
  MaleoFoundationServices
@@ -18,11 +24,20 @@ class MaleoFoundationClientManager(ClientManager):
18
24
 
19
25
  def _initialize_services(self):
20
26
  super()._initialize_services()
27
+ bcrypt_hash_service = MaleoFoundationBcryptHashClientService(logger=self._logger)
28
+ hmac_hash_service = MaleoFoundationHMACHashClientService(logger=self._logger)
29
+ sha256_hash_service = MaleoFoundationSHA256HashClientService(logger=self._logger)
30
+ hash_services = MaleoFoundationHashServices(
31
+ bcrypt=bcrypt_hash_service,
32
+ hmac=hmac_hash_service,
33
+ sha256=sha256_hash_service
34
+ )
21
35
  signature_service = MaleoFoundationSignatureClientService(logger=self._logger)
22
36
  token_service = MaleoFoundationTokenClientService(logger=self._logger)
23
37
  self._services = MaleoFoundationServices(
24
38
  signature=signature_service,
25
39
  token=token_service,
40
+ hash=hash_services
26
41
  )
27
42
 
28
43
  @property
@@ -1,9 +1,11 @@
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.hash import MaleoFoundationHashServices
4
5
  from maleo_foundation.client.services.signature import MaleoFoundationSignatureClientService
5
6
  from maleo_foundation.client.services.token import MaleoFoundationTokenClientService
6
7
 
7
8
  class MaleoFoundationServices(ClientServices):
9
+ hash:MaleoFoundationHashServices = Field(..., description="Hash's services")
8
10
  signature:MaleoFoundationSignatureClientService = Field(..., description="Signature's service")
9
11
  token:MaleoFoundationTokenClientService = Field(..., description="Token's service")
@@ -0,0 +1,11 @@
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.hash.bcrypt import MaleoFoundationBcryptHashClientService
5
+ from maleo_foundation.client.services.hash.hmac import MaleoFoundationHMACHashClientService
6
+ from maleo_foundation.client.services.hash.sha256 import MaleoFoundationSHA256HashClientService
7
+
8
+ class MaleoFoundationHashServices(ClientServices):
9
+ bcrypt:MaleoFoundationBcryptHashClientService = Field(..., description="Bcrypt hash's service")
10
+ hmac:MaleoFoundationHMACHashClientService = Field(..., description="HMAC hash's service")
11
+ sha256:MaleoFoundationSHA256HashClientService = Field(..., description="SHA256 hash's service")
@@ -0,0 +1,37 @@
1
+ import bcrypt
2
+ from maleo_foundation.expanded_types.hash import BaseHashResultsTypes
3
+ from maleo_foundation.managers.client.base import ClientService
4
+ from maleo_foundation.models.schemas.hash import BaseHashSchemas
5
+ from maleo_foundation.models.transfers.parameters.hash.bcrypt import BaseBcryptHashParametersTransfers
6
+ from maleo_foundation.models.transfers.results.hash import BaseHashResultsTransfers
7
+ from maleo_foundation.utils.exceptions import BaseExceptions
8
+
9
+ class MaleoFoundationBcryptHashClientService(ClientService):
10
+ def hash(self, parameters:BaseBcryptHashParametersTransfers.Hash) -> BaseHashResultsTypes.Hash:
11
+ """Generate a bcrypt hash for the given message."""
12
+ @BaseExceptions.service_exception_handler(
13
+ operation="hashing single message",
14
+ logger=self._logger,
15
+ fail_result_class=BaseHashResultsTransfers.Fail
16
+ )
17
+ def _impl():
18
+ salt = bcrypt.gensalt()
19
+ hash = bcrypt.hashpw(parameters.message.encode(), salt).decode()
20
+ data = BaseHashSchemas.Hash(hash=hash)
21
+ self._logger.info("Message successfully hashed")
22
+ return BaseHashResultsTransfers.Hash(data=data)
23
+ return _impl()
24
+
25
+ def verify(self, parameters:BaseBcryptHashParametersTransfers.Verify) -> BaseHashResultsTypes.Verify:
26
+ """Verify a message against the given message hash."""
27
+ @BaseExceptions.service_exception_handler(
28
+ operation="verify single hash",
29
+ logger=self._logger,
30
+ fail_result_class=BaseHashResultsTransfers.Fail
31
+ )
32
+ def _impl():
33
+ is_valid = bcrypt.checkpw(parameters.message.encode(), parameters.hash.encode())
34
+ data = BaseHashSchemas.IsValid(is_valid=is_valid)
35
+ self._logger.info("Hash successfully verified")
36
+ return BaseHashResultsTransfers.Verify(data=data)
37
+ return _impl()
@@ -0,0 +1,37 @@
1
+ from Crypto.Hash import HMAC, SHA256
2
+ from maleo_foundation.expanded_types.hash import BaseHashResultsTypes
3
+ from maleo_foundation.managers.client.base import ClientService
4
+ from maleo_foundation.models.schemas.hash import BaseHashSchemas
5
+ from maleo_foundation.models.transfers.parameters.hash.hmac import BaseHMACHashParametersTransfers
6
+ from maleo_foundation.models.transfers.results.hash import BaseHashResultsTransfers
7
+ from maleo_foundation.utils.exceptions import BaseExceptions
8
+
9
+ class MaleoFoundationHMACHashClientService(ClientService):
10
+ def hash(self, parameters:BaseHMACHashParametersTransfers.Hash) -> BaseHashResultsTypes.Hash:
11
+ """Generate a hmac hash for the given message."""
12
+ @BaseExceptions.service_exception_handler(
13
+ operation="hashing single message",
14
+ logger=self._logger,
15
+ fail_result_class=BaseHashResultsTransfers.Fail
16
+ )
17
+ def _impl():
18
+ hash = HMAC.new(parameters.key.encode(), parameters.message.encode(), SHA256).hexdigest()
19
+ data = BaseHashSchemas.Hash(hash=hash)
20
+ self._logger.info("Message successfully hashed")
21
+ return BaseHashResultsTransfers.Hash(data=data)
22
+ return _impl()
23
+
24
+ def verify(self, parameters:BaseHMACHashParametersTransfers.Verify) -> BaseHashResultsTypes.Verify:
25
+ """Verify a message against the given message hash."""
26
+ @BaseExceptions.service_exception_handler(
27
+ operation="verify single hash",
28
+ logger=self._logger,
29
+ fail_result_class=BaseHashResultsTransfers.Fail
30
+ )
31
+ def _impl():
32
+ computed_hash = HMAC.new(parameters.key.encode(), parameters.message.encode(), SHA256).hexdigest()
33
+ is_valid = computed_hash == parameters.hash
34
+ data = BaseHashSchemas.IsValid(is_valid=is_valid)
35
+ self._logger.info("Hash successfully verified")
36
+ return BaseHashResultsTransfers.Verify(data=data)
37
+ return _impl()
@@ -0,0 +1,37 @@
1
+ from Crypto.Hash import SHA256
2
+ from maleo_foundation.expanded_types.hash import BaseHashResultsTypes
3
+ from maleo_foundation.managers.client.base import ClientService
4
+ from maleo_foundation.models.schemas.hash import BaseHashSchemas
5
+ from maleo_foundation.models.transfers.parameters.hash.sha256 import BaseSHA256HashParametersTransfers
6
+ from maleo_foundation.models.transfers.results.hash import BaseHashResultsTransfers
7
+ from maleo_foundation.utils.exceptions import BaseExceptions
8
+
9
+ class MaleoFoundationSHA256HashClientService(ClientService):
10
+ def hash(self, parameters:BaseSHA256HashParametersTransfers.Hash) -> BaseHashResultsTypes.Hash:
11
+ """Generate a sha256 hash for the given message."""
12
+ @BaseExceptions.service_exception_handler(
13
+ operation="hashing single message",
14
+ logger=self._logger,
15
+ fail_result_class=BaseHashResultsTransfers.Fail
16
+ )
17
+ def _impl():
18
+ hash = SHA256.new(parameters.message.encode()).hexdigest()
19
+ data = BaseHashSchemas.Hash(hash=hash)
20
+ self._logger.info("Message successfully hashed")
21
+ return BaseHashResultsTransfers.Hash(data=data)
22
+ return _impl()
23
+
24
+ def verify(self, parameters:BaseSHA256HashParametersTransfers.Verify) -> BaseHashResultsTypes.Verify:
25
+ """Verify a message against the given message hash."""
26
+ @BaseExceptions.service_exception_handler(
27
+ operation="verify single hash",
28
+ logger=self._logger,
29
+ fail_result_class=BaseHashResultsTransfers.Fail
30
+ )
31
+ def _impl():
32
+ computed_hash = SHA256.new(parameters.message.encode()).hexdigest()
33
+ is_valid = computed_hash == parameters.hash
34
+ data = BaseHashSchemas.IsValid(is_valid=is_valid)
35
+ self._logger.info("Hash successfully verified")
36
+ return BaseHashResultsTransfers.Verify(data=data)
37
+ return _impl()
@@ -38,7 +38,7 @@ class MaleoFoundationSignatureClientService(ClientService):
38
38
  return BaseSignatureResultsTransfers.Sign(data=data)
39
39
  return _impl()
40
40
 
41
- def decode(self, parameters:BaseSignatureParametersTransfers.Verify) -> BaseSignatureResultsTypes.Verify:
41
+ def verify(self, parameters:BaseSignatureParametersTransfers.Verify) -> BaseSignatureResultsTypes.Verify:
42
42
  @BaseExceptions.service_exception_handler(
43
43
  operation="verify single signature",
44
44
  logger=self._logger,
@@ -0,0 +1,13 @@
1
+ from typing import Union
2
+ from maleo_foundation.models.transfers.results.hash import BaseHashResultsTransfers
3
+
4
+ class BaseHashResultsTypes:
5
+ Hash = Union[
6
+ BaseHashResultsTransfers.Fail,
7
+ BaseHashResultsTransfers.Hash
8
+ ]
9
+
10
+ Verify = Union[
11
+ BaseHashResultsTransfers.Fail,
12
+ BaseHashResultsTransfers.Verify
13
+ ]
@@ -0,0 +1,15 @@
1
+ from __future__ import annotations
2
+ from pydantic import BaseModel, Field
3
+
4
+ class BaseHashSchemas:
5
+ class Key(BaseModel):
6
+ key:str = Field(..., description="Key")
7
+
8
+ class Message(BaseModel):
9
+ message:str = Field(..., description="Message")
10
+
11
+ class Hash(BaseModel):
12
+ hash:str = Field(..., description="Hash")
13
+
14
+ class IsValid(BaseModel):
15
+ is_valid:bool = Field(..., description="Is valid hash")
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+ from .bcrypt import BaseBcryptHashParametersTransfers
3
+ from .hmac import BaseHMACHashParametersTransfers
4
+ from .sha256 import BaseSHA256HashParametersTransfers
5
+
6
+ class BaseHashParametersTransfers:
7
+ Bcrypt = BaseBcryptHashParametersTransfers
8
+ HMAC = BaseHMACHashParametersTransfers
9
+ SHA256 = BaseSHA256HashParametersTransfers
@@ -0,0 +1,9 @@
1
+ from maleo_foundation.models.schemas.hash import BaseHashSchemas
2
+
3
+ class BaseBcryptHashParametersTransfers:
4
+ class Hash(BaseHashSchemas.Message): pass
5
+
6
+ class Verify(
7
+ BaseHashSchemas.Hash,
8
+ BaseHashSchemas.Message
9
+ ): pass
@@ -0,0 +1,13 @@
1
+ from maleo_foundation.models.schemas.hash import BaseHashSchemas
2
+
3
+ class BaseHMACHashParametersTransfers:
4
+ class Hash(
5
+ BaseHashSchemas.Message,
6
+ BaseHashSchemas.Key
7
+ ): pass
8
+
9
+ class Verify(
10
+ BaseHashSchemas.Hash,
11
+ BaseHashSchemas.Message,
12
+ BaseHashSchemas.Key
13
+ ): pass
@@ -0,0 +1,9 @@
1
+ from maleo_foundation.models.schemas.hash import BaseHashSchemas
2
+
3
+ class BaseSHA256HashParametersTransfers:
4
+ class Hash(BaseHashSchemas.Message): pass
5
+
6
+ class Verify(
7
+ BaseHashSchemas.Hash,
8
+ BaseHashSchemas.Message
9
+ ): pass
@@ -0,0 +1,13 @@
1
+ from __future__ import annotations
2
+ from pydantic import Field
3
+ from maleo_foundation.models.transfers.results.service.general import BaseServiceGeneralResultsTransfers
4
+ from maleo_foundation.models.schemas.hash import BaseHashSchemas
5
+
6
+ class BaseHashResultsTransfers:
7
+ class Fail(BaseServiceGeneralResultsTransfers.Fail): pass
8
+
9
+ class Hash(BaseServiceGeneralResultsTransfers.SingleData):
10
+ data:BaseHashSchemas.Hash = Field(..., description="Hash data")
11
+
12
+ class Verify(BaseServiceGeneralResultsTransfers.SingleData):
13
+ data:BaseHashSchemas.IsValid = Field(..., description="Verify data")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.1.73
3
+ Version: 0.1.75
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
@@ -5,13 +5,18 @@ maleo_foundation/enums.py,sha256=uvwl3dl2r6BoJMEbtSETiLoyJubHup9Lc7VOg7w7zQo,294
5
5
  maleo_foundation/extended_types.py,sha256=pIKt-_9tby4rmune3fmWcCW_mohaNRh_1lywBmdc-L4,301
6
6
  maleo_foundation/types.py,sha256=aKXnIgEhYGSfFqNMGLc4qIKGkINBRpkOo9R9cb2CbwI,2414
7
7
  maleo_foundation/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- maleo_foundation/client/manager.py,sha256=3YO2uoBLoC9nbe1yNuqPjhgORSDwb5Zu68KLS2zvKXY,1206
9
- maleo_foundation/client/services/__init__.py,sha256=SUGBVhs_Zu9rNUxWIxcjGmi54W6RRlwSTqW4h8E0vW0,540
10
- maleo_foundation/client/services/signature.py,sha256=HGFhdva-4FkEx5s4QSwI2U8y0i2hIyRQCCWLWKQwGp8,4300
8
+ maleo_foundation/client/manager.py,sha256=Lx5k34RxI34qP6XVoHZ7PpAw_L28ByPR6fnZCJX04fk,1897
9
+ maleo_foundation/client/services/__init__.py,sha256=_A-jySpCciIVB-VHgjqvJNkRYmAwzcq9SuWWV6iWW7g,699
10
+ maleo_foundation/client/services/signature.py,sha256=ePO0T9cJ8BIIYbFw2ZJSW4MUM96Sk-Vu-ha0X7XTSGw,4300
11
11
  maleo_foundation/client/services/token.py,sha256=p1cA60ofeFJeL2MVKnAjnggIFniVSp2Hbd7VTYE255E,3880
12
+ maleo_foundation/client/services/hash/__init__.py,sha256=A4Olb-RpeNFQEfToU9t8LfZ8e2WXeR8c_grot-JCFjI,756
13
+ maleo_foundation/client/services/hash/bcrypt.py,sha256=1pl_X0IREGsGmx83w1cy81-6W-Xr3TcMHuD3u-N4TuA,1902
14
+ maleo_foundation/client/services/hash/hmac.py,sha256=lrmcqU88Rpvixi_1Q9a7RnUoV6OwOEnyHiLz4istjYk,1976
15
+ maleo_foundation/client/services/hash/sha256.py,sha256=Vhgoswo6fBik4s2AwcgvNCKKK1q6rQ5V4CqBLl1CE8c,1920
12
16
  maleo_foundation/expanded_types/__init__.py,sha256=lm_r7rxlLA0sgSTGQBMR9ZbZbVDpD7Te-UYb3oRVi1g,364
13
17
  maleo_foundation/expanded_types/client.py,sha256=To0kRXp3QTmuSu5rWKaCiTsMK9qkYiyYKYbHfw-y1fY,2396
14
18
  maleo_foundation/expanded_types/general.py,sha256=bjIBREYTS73tvS-Key7P7db82a2HHlSJ1XBAvKuYmT0,826
19
+ maleo_foundation/expanded_types/hash.py,sha256=KERzp_Gl2Z7urcw8i0ab1MXxU_BIlCY9V5d8X4Edq5s,344
15
20
  maleo_foundation/expanded_types/query.py,sha256=0yUG-JIVsanzB7KAkrRz_OsrhP6J0bRqD9Q3l3atQnk,2384
16
21
  maleo_foundation/expanded_types/service.py,sha256=q8jpKdbCbLWwH1UPQavKpVE14rC5rveduk2cFWzuhGw,2416
17
22
  maleo_foundation/expanded_types/signature.py,sha256=zNgXRrxVCfEIGXsRANIa1Ljj-ebHjC2pWOTtw_ABJlQ,379
@@ -35,6 +40,7 @@ maleo_foundation/models/responses.py,sha256=yKK_5p0dYCnUx-09mRKHkBv485bcngaCp9lw
35
40
  maleo_foundation/models/table.py,sha256=Dk5GXeO0gbBBPN2PJtZhlUx2x3vMbT4dxTBc3YLBbuc,1199
36
41
  maleo_foundation/models/schemas/__init__.py,sha256=Xj8Ahsqyra-fmEaVcGPok5GOOsPQlKcknHYMvbjvENA,277
37
42
  maleo_foundation/models/schemas/general.py,sha256=KGPP67ciKeL8cvOS3kYrVwmRx3kD33OcS88UmMn1JPE,3822
43
+ maleo_foundation/models/schemas/hash.py,sha256=ieRrAwp9ssYP74xQybv1_gT2gDyAcXLNMwqbYEcLwvg,430
38
44
  maleo_foundation/models/schemas/parameter.py,sha256=K47z2NzmTEhUiOfRiRLyRPXoQurbWsKBL7ObXAxIWRY,2100
39
45
  maleo_foundation/models/schemas/result.py,sha256=V3dljS2AdtWW4Pf8YsnQuiCylN1bZtEY1AtYC7okWuI,1747
40
46
  maleo_foundation/models/schemas/signature.py,sha256=4DVcsBR9TnxD2R28oWk51jMtF1j5ylmorVM3jDNVlrU,609
@@ -49,7 +55,12 @@ maleo_foundation/models/transfers/parameters/general.py,sha256=WoekZJCIoAllhXdRI
49
55
  maleo_foundation/models/transfers/parameters/service.py,sha256=d7Xy_R-DtLBRozyD6r8YnTiuKlE3sb9HMDCCq9WmUbY,6757
50
56
  maleo_foundation/models/transfers/parameters/signature.py,sha256=Kn6gJrQUHyn2uG6LyYnhbUEMfXJVTLgMG6n3CXZ4hu8,395
51
57
  maleo_foundation/models/transfers/parameters/token.py,sha256=WTmCKoP-KJLqZjdwr__BeVnBrnRrsxzHSQ0IBaOKvqw,535
58
+ maleo_foundation/models/transfers/parameters/hash/__init__.py,sha256=ix4AXSS-8EtKTSPwXOzkpIpyfx86QIJIQpp6zTLbIs4,365
59
+ maleo_foundation/models/transfers/parameters/hash/bcrypt.py,sha256=t_VpQL7YXokJf1Yp9TC8-ZD9AGQ0V0ZjFJpZZgfPqSA,245
60
+ maleo_foundation/models/transfers/parameters/hash/hmac.py,sha256=vCEVQPh51wXrbOfIp6ByyZwIKTUJTT02WMBfHOjwmZA,315
61
+ maleo_foundation/models/transfers/parameters/hash/sha256.py,sha256=tc2j-BKJYeLYuwXS19kOsvwTsiMWyWDFORB0vIV0imM,245
52
62
  maleo_foundation/models/transfers/results/__init__.py,sha256=0_8uJ1IQW87RZ4nIxzWkQVi3Fxb7B8myZTngXfoxgNc,241
63
+ maleo_foundation/models/transfers/results/hash.py,sha256=W8JMmL1YZsRxpnPsWJEM-RL2LypMgs4A_R3RAGHIolQ,605
53
64
  maleo_foundation/models/transfers/results/signature.py,sha256=md3tBOfjJlg-35ICSt8h_EZZett_x7obdlx_GQ3lB00,619
54
65
  maleo_foundation/models/transfers/results/token.py,sha256=4zDgj8FWGK6Rcz_pprwnLcpRyyXKRBPbrCl3IOrRvVg,574
55
66
  maleo_foundation/models/transfers/results/client/__init__.py,sha256=xBRuY0NUIPpQEGQ2qoBnqLZGX4W1YSrQ0VnDf5OYJBo,290
@@ -75,7 +86,7 @@ maleo_foundation/utils/loaders/json.py,sha256=NsXLq3VZSgzmEf99tV1VtrmiudWdQ8Pzh_
75
86
  maleo_foundation/utils/loaders/yaml.py,sha256=jr8v3BlgmRCMTzdNgKhIYt1tnubaJXcDSSGkKVR8pbw,362
76
87
  maleo_foundation/utils/loaders/key/__init__.py,sha256=G03cA_Oxu02uDsg0WBPfPkIM2uUsxnjwOPgtBKe02kc,110
77
88
  maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
78
- maleo_foundation-0.1.73.dist-info/METADATA,sha256=lKCQj6cm0WqQHHgAkq_cd5dNwJ_WO91SdoRY99crx3A,3390
79
- maleo_foundation-0.1.73.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
80
- maleo_foundation-0.1.73.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
81
- maleo_foundation-0.1.73.dist-info/RECORD,,
89
+ maleo_foundation-0.1.75.dist-info/METADATA,sha256=W-HjQ8Twjp2fr8JTSCBsuKrOqKRhAuI5XGmsH4Ge-KE,3419
90
+ maleo_foundation-0.1.75.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
91
+ maleo_foundation-0.1.75.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
92
+ maleo_foundation-0.1.75.dist-info/RECORD,,