passphera-core 0.21.0__py3-none-any.whl → 0.23.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.
- passphera_core/application/generator.py +15 -7
- passphera_core/entities.py +52 -37
- {passphera_core-0.21.0.dist-info → passphera_core-0.23.0.dist-info}/METADATA +1 -1
- {passphera_core-0.21.0.dist-info → passphera_core-0.23.0.dist-info}/RECORD +6 -6
- {passphera_core-0.21.0.dist-info → passphera_core-0.23.0.dist-info}/WHEEL +0 -0
- {passphera_core-0.21.0.dist-info → passphera_core-0.23.0.dist-info}/top_level.txt +0 -0
@@ -10,29 +10,37 @@ class GetGeneratorUseCase:
|
|
10
10
|
return self.generator_repository.get()
|
11
11
|
|
12
12
|
|
13
|
-
class
|
13
|
+
class GetPropertiesUseCase:
|
14
14
|
def __init__(self, generator_repository: GeneratorRepository):
|
15
15
|
self.generator_repository: GeneratorRepository = generator_repository
|
16
16
|
|
17
|
-
def __call__(self
|
17
|
+
def __call__(self) -> dict:
|
18
|
+
return self.generator_repository.get().get_properties()
|
19
|
+
|
20
|
+
|
21
|
+
class SetPropertyUseCase:
|
22
|
+
def __init__(self, generator_repository: GeneratorRepository):
|
23
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
24
|
+
|
25
|
+
def __call__(self, prop: str, value: str) -> Generator:
|
18
26
|
generator_entity: Generator = self.generator_repository.get()
|
19
|
-
generator_entity.set_property(
|
27
|
+
generator_entity.set_property(prop, value)
|
20
28
|
self.generator_repository.update(generator_entity)
|
21
29
|
return generator_entity
|
22
30
|
|
23
31
|
|
24
|
-
class
|
32
|
+
class ResetPropertyUseCase:
|
25
33
|
def __init__(self, generator_repository: GeneratorRepository):
|
26
34
|
self.generator_repository: GeneratorRepository = generator_repository
|
27
35
|
|
28
|
-
def __call__(self,
|
36
|
+
def __call__(self, prop: str) -> Generator:
|
29
37
|
generator_entity: Generator = self.generator_repository.get()
|
30
|
-
generator_entity.reset_property(
|
38
|
+
generator_entity.reset_property(prop)
|
31
39
|
self.generator_repository.update(generator_entity)
|
32
40
|
return generator_entity
|
33
41
|
|
34
42
|
|
35
|
-
class
|
43
|
+
class SetCharacterReplacementUseCase:
|
36
44
|
def __init__(self, generator_repository: GeneratorRepository):
|
37
45
|
self.generator_repository: GeneratorRepository = generator_repository
|
38
46
|
|
passphera_core/entities.py
CHANGED
@@ -20,33 +20,57 @@ class Password:
|
|
20
20
|
salt: bytes = field(default_factory=lambda: bytes)
|
21
21
|
|
22
22
|
def encrypt(self) -> None:
|
23
|
+
"""
|
24
|
+
Encrypts the password using Fernet symmetric encryption.
|
25
|
+
|
26
|
+
This method generates a new salt, derives an encryption key using the password
|
27
|
+
and salt, and then encrypts the password using Fernet encryption. The encrypted
|
28
|
+
password is stored back in the password field as a base64-encoded string.
|
29
|
+
:return: None
|
30
|
+
"""
|
23
31
|
self.salt = generate_salt()
|
24
32
|
key = derive_key(self.password, self.salt)
|
25
33
|
self.password = Fernet(key).encrypt(self.password.encode()).decode()
|
26
34
|
|
27
35
|
def decrypt(self) -> str:
|
36
|
+
"""
|
37
|
+
Decrypts the encrypted password using Fernet symmetric decryption.
|
38
|
+
|
39
|
+
This method uses the stored salt to derive the encryption key and then
|
40
|
+
decrypts the stored encrypted password using Fernet decryption.
|
41
|
+
:return: str: The decrypted original password
|
42
|
+
"""
|
28
43
|
key = derive_key(self.password, self.salt)
|
29
44
|
return Fernet(key).decrypt(self.password.encode()).decode()
|
30
45
|
|
31
46
|
|
32
47
|
@dataclass
|
33
48
|
class Generator:
|
34
|
-
id: UUID = field(default_factory=uuid4)
|
35
|
-
created_at: datetime = field(default_factory=datetime.now)
|
36
|
-
updated_at: datetime = field(default_factory=datetime.now)
|
37
|
-
shift: int = field(default=3)
|
38
|
-
multiplier: int = field(default=3)
|
39
|
-
key: str = field(default="hill")
|
40
|
-
algorithm: str = field(default="hill")
|
41
|
-
prefix: str = field(default="secret")
|
42
|
-
postfix: str = field(default="secret")
|
43
|
-
characters_replacements: dict[str, str] = field(default_factory=dict[str, str])
|
44
49
|
_cipher_registry: dict[str, BaseCipherAlgorithm] = field(default_factory=lambda: {
|
45
50
|
'caesar': CaesarCipherAlgorithm,
|
46
51
|
'affine': AffineCipherAlgorithm,
|
47
52
|
'playfair': PlayfairCipherAlgorithm,
|
48
53
|
'hill': HillCipherAlgorithm,
|
49
54
|
}, init=False)
|
55
|
+
_default_properties: dict[str, str] = field(default_factory=lambda:{
|
56
|
+
"shift": 3,
|
57
|
+
"multiplier": 3,
|
58
|
+
"key": "hill",
|
59
|
+
"algorithm": "hill",
|
60
|
+
"prefix": "secret",
|
61
|
+
"postfix": "secret"
|
62
|
+
}, init=False)
|
63
|
+
|
64
|
+
id: UUID = field(default_factory=uuid4)
|
65
|
+
created_at: datetime = field(default_factory=datetime.now)
|
66
|
+
updated_at: datetime = field(default_factory=datetime.now)
|
67
|
+
shift: int = field(default=_default_properties["shift"])
|
68
|
+
multiplier: int = field(default=_default_properties["multiplier"])
|
69
|
+
key: str = field(default=_default_properties["key"])
|
70
|
+
algorithm: str = field(default=_default_properties["algorithm"])
|
71
|
+
prefix: str = field(default=_default_properties["prefix"])
|
72
|
+
postfix: str = field(default=_default_properties["postfix"])
|
73
|
+
characters_replacements: dict[str, str] = field(default_factory=dict[str, str])
|
50
74
|
|
51
75
|
def get_algorithm(self) -> BaseCipherAlgorithm:
|
52
76
|
"""
|
@@ -57,17 +81,17 @@ class Generator:
|
|
57
81
|
raise InvalidAlgorithmException(self.algorithm)
|
58
82
|
return self._cipher_registry[self.algorithm.lower()]
|
59
83
|
|
60
|
-
def
|
84
|
+
def get_properties(self) -> dict:
|
61
85
|
"""
|
62
|
-
Retrieves the application
|
86
|
+
Retrieves the application properties.
|
63
87
|
|
64
88
|
This method is responsible for providing a dictionary containing
|
65
|
-
the current configuration
|
66
|
-
that the
|
89
|
+
the current configuration properties of the application. It ensures
|
90
|
+
that the properties are properly assembled and returned for use
|
67
91
|
elsewhere in the application.
|
68
92
|
|
69
93
|
Returns:
|
70
|
-
dict: A dictionary containing the application
|
94
|
+
dict: A dictionary containing the application properties.
|
71
95
|
"""
|
72
96
|
return {
|
73
97
|
"shift": self.shift,
|
@@ -79,44 +103,35 @@ class Generator:
|
|
79
103
|
"characters_replacements": self.characters_replacements,
|
80
104
|
}
|
81
105
|
|
82
|
-
def set_property(self,
|
106
|
+
def set_property(self, prop: str, value: str):
|
83
107
|
"""
|
84
108
|
Update a generator property with a new value
|
85
|
-
:param
|
109
|
+
:param prop: The property name to update; must be one of: shift, multiplier, key, algorithm, prefix, postfix
|
86
110
|
:param value: The new value to set for the property
|
87
111
|
:raises ValueError: If the property name is not one of the allowed properties
|
88
112
|
:return: None
|
89
113
|
"""
|
90
|
-
if
|
91
|
-
raise ValueError(f"Invalid property: {
|
92
|
-
if
|
114
|
+
if prop not in {"shift", "multiplier", "key", "algorithm", "prefix", "postfix"}:
|
115
|
+
raise ValueError(f"Invalid property: {prop}")
|
116
|
+
if prop in ["shift", "multiplier"]:
|
93
117
|
value = int(value)
|
94
|
-
setattr(self,
|
95
|
-
if
|
118
|
+
setattr(self, prop, value)
|
119
|
+
if prop == "algorithm":
|
96
120
|
self.get_algorithm()
|
97
121
|
self.updated_at = datetime.now(timezone.utc)
|
98
122
|
|
99
|
-
def reset_property(self,
|
123
|
+
def reset_property(self, prop: str):
|
100
124
|
"""
|
101
125
|
Reset a generator property to its default value
|
102
|
-
:param
|
126
|
+
:param prop: The property name to reset, it must be one of: shift, multiplier, key, algorithm, prefix, postfix
|
103
127
|
:raises ValueError: If the property name is not one of the allowed properties
|
104
128
|
:return: None
|
105
129
|
"""
|
106
|
-
if
|
107
|
-
raise ValueError(f"Invalid property: {
|
108
|
-
|
109
|
-
defaults = {
|
110
|
-
"shift": 3,
|
111
|
-
"multiplier": 3,
|
112
|
-
"key": "hill",
|
113
|
-
"algorithm": "hill",
|
114
|
-
"prefix": "secret",
|
115
|
-
"postfix": "secret"
|
116
|
-
}
|
130
|
+
if prop not in {"shift", "multiplier", "key", "algorithm", "prefix", "postfix"}:
|
131
|
+
raise ValueError(f"Invalid property: {prop}")
|
117
132
|
|
118
|
-
setattr(self,
|
119
|
-
if
|
133
|
+
setattr(self, prop, self._default_properties[prop])
|
134
|
+
if prop == "algorithm":
|
120
135
|
self.get_algorithm()
|
121
136
|
self.updated_at = datetime.now(timezone.utc)
|
122
137
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
passphera_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
passphera_core/entities.py,sha256=
|
2
|
+
passphera_core/entities.py,sha256=ds0BfJPiUoZsv4Sd6mocLfO9cR7wAKvtjswusSe8-Nk,7222
|
3
3
|
passphera_core/exceptions.py,sha256=Xir2lYIH7QYHfjDQu8WJ9qIhCvP-mYcPWYN2LbbbDj8,640
|
4
4
|
passphera_core/interfaces.py,sha256=DpHFh_vnamORf69P1dwLrZ8AYZPcYIol0Lq_VKRBkXc,855
|
5
5
|
passphera_core/utilities.py,sha256=n7cAVox-yGd60595RjLvrGKSGqFQRm279YqKS3-R1X0,748
|
6
6
|
passphera_core/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
passphera_core/application/generator.py,sha256=
|
7
|
+
passphera_core/application/generator.py,sha256=WnMuv-zBPa6d_eCOKtbtsDl1CmZ_YcnXqH5bpVIXhgs,2452
|
8
8
|
passphera_core/application/password.py,sha256=9wsSz3uMWEZCgfnX5V7WYiWp2OqjSmsn6OSWK4HIIfo,2876
|
9
|
-
passphera_core-0.
|
10
|
-
passphera_core-0.
|
11
|
-
passphera_core-0.
|
12
|
-
passphera_core-0.
|
9
|
+
passphera_core-0.23.0.dist-info/METADATA,sha256=8ohLZ-JaOXGQMQW7hFhGbYCppJOPWCtyV8BvyUCdZQo,868
|
10
|
+
passphera_core-0.23.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
passphera_core-0.23.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
12
|
+
passphera_core-0.23.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|