passphera-core 0.25.1__py3-none-any.whl → 0.26.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/entities.py +55 -18
- {passphera_core-0.25.1.dist-info → passphera_core-0.26.0.dist-info}/METADATA +1 -1
- {passphera_core-0.25.1.dist-info → passphera_core-0.26.0.dist-info}/RECORD +5 -5
- {passphera_core-0.25.1.dist-info → passphera_core-0.26.0.dist-info}/WHEEL +0 -0
- {passphera_core-0.25.1.dist-info → passphera_core-0.26.0.dist-info}/top_level.txt +0 -0
passphera_core/entities.py
CHANGED
@@ -11,6 +11,22 @@ from cipherspy.utilities import generate_salt, derive_key
|
|
11
11
|
from passphera_core.exceptions import InvalidPropertyNameException
|
12
12
|
|
13
13
|
|
14
|
+
_cipher_registry: dict[str, BaseCipherAlgorithm] = {
|
15
|
+
'caesar': CaesarCipherAlgorithm,
|
16
|
+
'affine': AffineCipherAlgorithm,
|
17
|
+
'playfair': PlayfairCipherAlgorithm,
|
18
|
+
'hill': HillCipherAlgorithm,
|
19
|
+
}
|
20
|
+
_default_properties: dict[str, str] = {
|
21
|
+
"shift": 3,
|
22
|
+
"multiplier": 3,
|
23
|
+
"key": "hill",
|
24
|
+
"algorithm": "hill",
|
25
|
+
"prefix": "secret",
|
26
|
+
"postfix": "secret"
|
27
|
+
}
|
28
|
+
|
29
|
+
|
14
30
|
@dataclass
|
15
31
|
class Password:
|
16
32
|
id: UUID = field(default_factory=uuid4)
|
@@ -45,24 +61,26 @@ class Password:
|
|
45
61
|
key = derive_key(self.password, self.salt)
|
46
62
|
return Fernet(key).decrypt(self.password.encode()).decode()
|
47
63
|
|
64
|
+
def to_dict(self) -> dict:
|
65
|
+
"""Convert the Password entity to a dictionary."""
|
66
|
+
return {
|
67
|
+
"id": self.id,
|
68
|
+
"created_at": self.created_at,
|
69
|
+
"updated_at": self.updated_at,
|
70
|
+
"context": self.context,
|
71
|
+
"text": self.text,
|
72
|
+
"password": self.password,
|
73
|
+
"salt": self.salt,
|
74
|
+
}
|
75
|
+
|
76
|
+
def from_dict(self, data: dict) -> None:
|
77
|
+
"""Convert a dictionary to a Password entity."""
|
78
|
+
for key, value in data.items():
|
79
|
+
setattr(self, key, value)
|
80
|
+
|
48
81
|
|
49
82
|
@dataclass
|
50
83
|
class Generator:
|
51
|
-
_cipher_registry: dict[str, BaseCipherAlgorithm] = field(default_factory=lambda: {
|
52
|
-
'caesar': CaesarCipherAlgorithm,
|
53
|
-
'affine': AffineCipherAlgorithm,
|
54
|
-
'playfair': PlayfairCipherAlgorithm,
|
55
|
-
'hill': HillCipherAlgorithm,
|
56
|
-
}, init=False)
|
57
|
-
_default_properties: dict[str, str] = field(default_factory=lambda:{
|
58
|
-
"shift": 3,
|
59
|
-
"multiplier": 3,
|
60
|
-
"key": "hill",
|
61
|
-
"algorithm": "hill",
|
62
|
-
"prefix": "secret",
|
63
|
-
"postfix": "secret"
|
64
|
-
}, init=False)
|
65
|
-
|
66
84
|
id: UUID = field(default_factory=uuid4)
|
67
85
|
created_at: datetime = field(default_factory=datetime.now)
|
68
86
|
updated_at: datetime = field(default_factory=datetime.now)
|
@@ -79,9 +97,9 @@ class Generator:
|
|
79
97
|
Get the primary algorithm used to cipher the password
|
80
98
|
:return: BaseCipherAlgorithm: The primary algorithm used for the cipher
|
81
99
|
"""
|
82
|
-
if self.algorithm.lower() not in
|
100
|
+
if self.algorithm.lower() not in _cipher_registry:
|
83
101
|
raise InvalidAlgorithmException(self.algorithm)
|
84
|
-
return
|
102
|
+
return _cipher_registry[self.algorithm.lower()]
|
85
103
|
|
86
104
|
def get_properties(self) -> dict:
|
87
105
|
"""
|
@@ -131,7 +149,7 @@ class Generator:
|
|
131
149
|
"""
|
132
150
|
if prop not in {"shift", "multiplier", "key", "algorithm", "prefix", "postfix"}:
|
133
151
|
raise InvalidPropertyNameException(prop)
|
134
|
-
setattr(self, prop,
|
152
|
+
setattr(self, prop, _default_properties[prop])
|
135
153
|
if prop == "algorithm":
|
136
154
|
self.get_algorithm()
|
137
155
|
self.updated_at = datetime.now(timezone.utc)
|
@@ -176,3 +194,22 @@ class Generator:
|
|
176
194
|
password: str = main_algorithm.encrypt(intermediate)
|
177
195
|
password = password.translate(str.maketrans(self.characters_replacements))
|
178
196
|
return ''.join(c.upper() if c in text else c for c in password)
|
197
|
+
|
198
|
+
def to_dict(self) -> dict:
|
199
|
+
"""Convert the Generator entity to a dictionary."""
|
200
|
+
return {
|
201
|
+
"id": self.id,
|
202
|
+
"created_at": self.created_at,
|
203
|
+
"updated_at": self.updated_at,
|
204
|
+
"shift": self.shift,
|
205
|
+
"multiplier": self.multiplier,
|
206
|
+
"key": self.key,
|
207
|
+
"algorithm": self.algorithm,
|
208
|
+
"prefix": self.prefix,
|
209
|
+
"postfix": self.postfix,
|
210
|
+
}
|
211
|
+
|
212
|
+
def from_dict(self, data: dict) -> None:
|
213
|
+
"""Convert a dictionary to a Generator entity."""
|
214
|
+
for key, value in data.items():
|
215
|
+
setattr(self, key, value)
|
@@ -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=LnIMQ5xbVP59Cn96AmQ6BY358VJ-Vcx01pvhj919iJk,8732
|
3
3
|
passphera_core/exceptions.py,sha256=Tqb-FKJ1_JfX5gSC8Wc0CP84AhwouvnP2gkg83xAlUY,786
|
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
7
|
passphera_core/application/generator.py,sha256=hBSk6vktJ2KPxzKSRnH_WVnCvg7vOHVzN-TQ5GdgXEQ,2769
|
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.26.0.dist-info/METADATA,sha256=PR8YE14fjCXNrx644AfMpzpPLp28HFOAEzJz7BmRHQQ,868
|
10
|
+
passphera_core-0.26.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
passphera_core-0.26.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
12
|
+
passphera_core-0.26.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|