passphera-core 0.9.0__py3-none-any.whl → 0.10.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- passphera_core/application/__init__.py +0 -0
- passphera_core/application/generator.py +78 -0
- passphera_core/application/password.py +118 -0
- passphera_core/application/user.py +56 -0
- passphera_core/entities.py +8 -4
- passphera_core/interfaces.py +0 -12
- {passphera_core-0.9.0.dist-info → passphera_core-0.10.0.dist-info}/METADATA +11 -2
- passphera_core-0.10.0.dist-info/RECORD +12 -0
- {passphera_core-0.9.0.dist-info → passphera_core-0.10.0.dist-info}/WHEEL +1 -1
- passphera_core-0.9.0.dist-info/RECORD +0 -8
- {passphera_core-0.9.0.dist-info → passphera_core-0.10.0.dist-info}/top_level.txt +0 -0
File without changes
|
@@ -0,0 +1,78 @@
|
|
1
|
+
from datetime import datetime, timezone
|
2
|
+
from uuid import UUID
|
3
|
+
|
4
|
+
from passphera_core.entities import Generator, GeneratorConfig
|
5
|
+
from passphera_core.interfaces import GeneratorRepository, GeneratorConfigRepository
|
6
|
+
|
7
|
+
|
8
|
+
class GetGeneratorUseCase:
|
9
|
+
def __init__(self, generator_repository: GeneratorRepository):
|
10
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
11
|
+
|
12
|
+
def execute(self, user_id: UUID) -> Generator:
|
13
|
+
return self.generator_repository.find_by_user_id(user_id)
|
14
|
+
|
15
|
+
|
16
|
+
class GetGeneratorConfigPropertyUseCase:
|
17
|
+
def __init__(self, generator_repository: GeneratorRepository, generator_config_repository: GeneratorConfigRepository):
|
18
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
19
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
20
|
+
|
21
|
+
def execute(self, user_id: UUID, field: str) -> str:
|
22
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
23
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
24
|
+
return getattr(generator_config_entity, field)
|
25
|
+
|
26
|
+
|
27
|
+
class UpdateGeneratorConfigUseCase:
|
28
|
+
def __init__(
|
29
|
+
self,
|
30
|
+
generator_repository: GeneratorRepository,
|
31
|
+
generator_config_repository: GeneratorConfigRepository,
|
32
|
+
):
|
33
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
34
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
35
|
+
|
36
|
+
def execute(self, user_id: UUID, field: str, value: str) -> None:
|
37
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
38
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
39
|
+
setattr(generator_config_entity, field, value)
|
40
|
+
if field == 'algorithm':
|
41
|
+
generator_config_entity.get_algorithm()
|
42
|
+
generator_config_entity.updated_at = datetime.now(timezone.utc)
|
43
|
+
self.generator_config_repository.update(generator_config_entity)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
class AddCharacterReplacementUseCase:
|
48
|
+
def __init__(
|
49
|
+
self,
|
50
|
+
generator_repository: GeneratorRepository,
|
51
|
+
generator_config_repository: GeneratorConfigRepository,
|
52
|
+
):
|
53
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
54
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
55
|
+
|
56
|
+
def execute(self, user_id: UUID, character: str, replacement: str) -> None:
|
57
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
58
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
59
|
+
generator_config_entity.replace_character(character, replacement)
|
60
|
+
generator_config_entity.updated_at = datetime.now(timezone.utc)
|
61
|
+
self.generator_config_repository.update(generator_config_entity)
|
62
|
+
|
63
|
+
|
64
|
+
class ResetCharacterReplacementUseCase:
|
65
|
+
def __init__(
|
66
|
+
self,
|
67
|
+
generator_repository: GeneratorRepository,
|
68
|
+
generator_config_repository: GeneratorConfigRepository,
|
69
|
+
):
|
70
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
71
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
72
|
+
|
73
|
+
def execute(self, user_id: UUID, character: str) -> None:
|
74
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
75
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
76
|
+
generator_config_entity.reset_character(character)
|
77
|
+
generator_config_entity.updated_at = datetime.now(timezone.utc)
|
78
|
+
self.generator_config_repository.update(generator_config_entity)
|
@@ -0,0 +1,118 @@
|
|
1
|
+
from datetime import datetime, timezone
|
2
|
+
from uuid import UUID
|
3
|
+
|
4
|
+
from passphera_core.entities import Password, Generator, User
|
5
|
+
from passphera_core.exceptions import EntityNotFoundException
|
6
|
+
from passphera_core.interfaces import PasswordRepository, GeneratorRepository, UserRepository
|
7
|
+
|
8
|
+
|
9
|
+
class GeneratePasswordUseCase:
|
10
|
+
def __init__(
|
11
|
+
self,
|
12
|
+
password_repository: PasswordRepository,
|
13
|
+
generator_repository: GeneratorRepository,
|
14
|
+
user_repository: UserRepository
|
15
|
+
):
|
16
|
+
self.password_repository: PasswordRepository = password_repository
|
17
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
18
|
+
self.user_repository: UserRepository = user_repository
|
19
|
+
|
20
|
+
def execute(self, user_id: UUID, context: str, text: str) -> Password:
|
21
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
22
|
+
generator_entity: Generator = self.generator_repository.find_by_id(user_entity.generator_id)
|
23
|
+
password: str = generator_entity.generate_password(text)
|
24
|
+
password_entity: Password = Password(user_id=user_id, context=context, text=text, password=password)
|
25
|
+
password_entity.encrypt()
|
26
|
+
self.password_repository.save(password_entity)
|
27
|
+
user_entity.add_password(password_entity.id)
|
28
|
+
self.user_repository.update(user_entity)
|
29
|
+
return password_entity
|
30
|
+
|
31
|
+
|
32
|
+
class GetPasswordByIdUseCase:
|
33
|
+
def __init__(self, password_repository: PasswordRepository):
|
34
|
+
self.password_repository: PasswordRepository = password_repository
|
35
|
+
|
36
|
+
def execute(self, password_id: UUID) -> Password:
|
37
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
38
|
+
if not password_entity:
|
39
|
+
raise EntityNotFoundException(password_entity)
|
40
|
+
return password_entity
|
41
|
+
|
42
|
+
|
43
|
+
class GetPasswordByContextUseCase:
|
44
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
45
|
+
self.password_repository: PasswordRepository = password_repository
|
46
|
+
self.user_repository: UserRepository = user_repository
|
47
|
+
|
48
|
+
def execute(self, user_id: UUID, context: str) -> Password:
|
49
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
50
|
+
for password_id in user_entity.passwords_ids:
|
51
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
52
|
+
if password_entity.context == context:
|
53
|
+
return password_entity
|
54
|
+
raise EntityNotFoundException(Password())
|
55
|
+
|
56
|
+
|
57
|
+
class UpdatePasswordUseCase:
|
58
|
+
def __init__(
|
59
|
+
self,
|
60
|
+
password_repository: PasswordRepository,
|
61
|
+
generator_repository: GeneratorRepository,
|
62
|
+
user_repository: UserRepository
|
63
|
+
):
|
64
|
+
self.password_repository: PasswordRepository = password_repository
|
65
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
66
|
+
self.user_repository: UserRepository = user_repository
|
67
|
+
|
68
|
+
def execute(self, user_id: UUID, context: str, text: str) -> Password:
|
69
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
70
|
+
generator_entity: Generator = self.generator_repository.find_by_id(user_entity.generator_id)
|
71
|
+
for password_id in user_entity.passwords_ids:
|
72
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
73
|
+
if password_entity.context == context:
|
74
|
+
password_entity.password = generator_entity.generate_password(text)
|
75
|
+
password_entity.encrypt()
|
76
|
+
password_entity.updated_at = datetime.now(timezone.utc)
|
77
|
+
self.password_repository.update(password_entity)
|
78
|
+
return password_entity
|
79
|
+
raise EntityNotFoundException(Password())
|
80
|
+
|
81
|
+
|
82
|
+
class DeletePasswordUseCase:
|
83
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
84
|
+
self.password_repository: PasswordRepository = password_repository
|
85
|
+
self.user_repository: UserRepository = user_repository
|
86
|
+
|
87
|
+
def execute(self, user_id: UUID, password_id: UUID) -> None:
|
88
|
+
self.password_repository.delete(password_id)
|
89
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
90
|
+
user_entity.delete_password(password_id)
|
91
|
+
self.user_repository.update(user_entity)
|
92
|
+
|
93
|
+
|
94
|
+
class GetAllUserPasswordsUseCase:
|
95
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
96
|
+
self.password_repository: PasswordRepository = password_repository
|
97
|
+
self.user_repository: UserRepository = user_repository
|
98
|
+
|
99
|
+
def execute(self, user_id: UUID) -> list[Password]:
|
100
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
101
|
+
passwords: list[Password] = []
|
102
|
+
for password_id in user_entity.passwords_ids:
|
103
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
104
|
+
passwords.append(password_entity)
|
105
|
+
return passwords
|
106
|
+
|
107
|
+
|
108
|
+
class DeleteAllUserPasswordsUseCase:
|
109
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
110
|
+
self.password_repository: PasswordRepository = password_repository
|
111
|
+
self.user_repository: UserRepository = user_repository
|
112
|
+
|
113
|
+
def execute(self, user_id: UUID) -> None:
|
114
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
115
|
+
for password_id in user_entity.passwords_ids:
|
116
|
+
self.password_repository.delete(password_id)
|
117
|
+
user_entity.delete_password(password_id)
|
118
|
+
self.user_repository.update(user_entity)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
|
3
|
+
from passphera_core.entities import User, Generator
|
4
|
+
from passphera_core.exceptions import DuplicateEntityException
|
5
|
+
from passphera_core.interfaces import UserRepository, GeneratorRepository
|
6
|
+
|
7
|
+
|
8
|
+
class RegisterUserUseCase:
|
9
|
+
def __init__(self, user_repository: UserRepository, generator_repository: GeneratorRepository):
|
10
|
+
self.user_repository: UserRepository = user_repository
|
11
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
12
|
+
|
13
|
+
def execute(self, user: User) -> User:
|
14
|
+
if self.user_repository.find_by_email(user.email):
|
15
|
+
raise DuplicateEntityException(user, 'email')
|
16
|
+
if self.user_repository.find_by_username(user.username):
|
17
|
+
raise DuplicateEntityException(user, 'username')
|
18
|
+
user_entity: User = User(**user.__dict__)
|
19
|
+
generator_entity: Generator = Generator(user_id=user_entity.id)
|
20
|
+
self.generator_repository.save(generator_entity)
|
21
|
+
user_entity.generator_id = generator_entity.id
|
22
|
+
self.user_repository.save(user_entity)
|
23
|
+
return user_entity
|
24
|
+
|
25
|
+
|
26
|
+
class GetUserByIdUseCase:
|
27
|
+
def __init__(self, user_repository: UserRepository):
|
28
|
+
self.user_repository: UserRepository = user_repository
|
29
|
+
|
30
|
+
def execute(self, id: UUID) -> User:
|
31
|
+
user = self.user_repository.find_by_id(id)
|
32
|
+
if not user:
|
33
|
+
raise ValueError(f'User not found')
|
34
|
+
return user
|
35
|
+
|
36
|
+
|
37
|
+
class GetUserByUsernameUseCase:
|
38
|
+
def __init__(self, user_repository: UserRepository):
|
39
|
+
self.user_repository = user_repository
|
40
|
+
|
41
|
+
def execute(self, username: str) -> User:
|
42
|
+
user = self.user_repository.find_by_username(username)
|
43
|
+
if not user:
|
44
|
+
raise ValueError(f'User not found')
|
45
|
+
return user
|
46
|
+
|
47
|
+
|
48
|
+
class GetUserByEmailUseCase:
|
49
|
+
def __init__(self, user_repository: UserRepository):
|
50
|
+
self.user_repository = user_repository
|
51
|
+
|
52
|
+
def execute(self, email: str) -> User:
|
53
|
+
user = self.user_repository.find_by_email(email)
|
54
|
+
if not user:
|
55
|
+
raise ValueError(f'User not found')
|
56
|
+
return user
|
passphera_core/entities.py
CHANGED
@@ -84,7 +84,11 @@ class Generator:
|
|
84
84
|
user_id: UUID = field(default_factory=uuid4)
|
85
85
|
created_at: datetime = field(default_factory=datetime.now)
|
86
86
|
updated_at: datetime = field(default_factory=datetime.now)
|
87
|
+
config_id: UUID = field(default_factory=UUID)
|
87
88
|
config: GeneratorConfig = field(default_factory=GeneratorConfig)
|
89
|
+
|
90
|
+
def __post_init__(self):
|
91
|
+
self.config = GeneratorConfig(generator_id=self.id)
|
88
92
|
|
89
93
|
def apply_replacements(self, password: str) -> str:
|
90
94
|
"""
|
@@ -115,11 +119,11 @@ class User:
|
|
115
119
|
username: str = field(default_factory=str)
|
116
120
|
email: str = field(default_factory=str)
|
117
121
|
password: str = field(default_factory=str)
|
118
|
-
|
119
|
-
|
122
|
+
generator_id: UUID = field(default_factory=UUID)
|
123
|
+
passwords_ids: list[UUID] = field(default_factory=list[UUID])
|
120
124
|
|
121
125
|
def add_password(self, password_id: UUID) -> None:
|
122
|
-
self.
|
126
|
+
self.passwords_ids.append(password_id)
|
123
127
|
|
124
128
|
def delete_password(self, password_id: UUID) -> None:
|
125
|
-
self.
|
129
|
+
self.passwords_ids.remove(password_id)
|
passphera_core/interfaces.py
CHANGED
@@ -31,10 +31,6 @@ class GeneratorRepository(ABC):
|
|
31
31
|
def update(self, generator: Generator) -> None:
|
32
32
|
pass
|
33
33
|
|
34
|
-
@abstractmethod
|
35
|
-
def delete(self, generator_id: UUID) -> None:
|
36
|
-
pass
|
37
|
-
|
38
34
|
@abstractmethod
|
39
35
|
def find_by_id(self, generator_id: UUID) -> Generator:
|
40
36
|
pass
|
@@ -53,10 +49,6 @@ class GeneratorConfigRepository(ABC):
|
|
53
49
|
def update(self, generator_config: GeneratorConfig) -> None:
|
54
50
|
pass
|
55
51
|
|
56
|
-
@abstractmethod
|
57
|
-
def delete(self, generator_config_id: UUID) -> None:
|
58
|
-
pass
|
59
|
-
|
60
52
|
@abstractmethod
|
61
53
|
def find_by_id(self, generator_config_id: UUID) -> GeneratorConfig:
|
62
54
|
pass
|
@@ -75,10 +67,6 @@ class UserRepository(ABC):
|
|
75
67
|
def update(self, user: User) -> None:
|
76
68
|
pass
|
77
69
|
|
78
|
-
@abstractmethod
|
79
|
-
def delete(self, user_id: UUID) -> None:
|
80
|
-
pass
|
81
|
-
|
82
70
|
@abstractmethod
|
83
71
|
def find_by_id(self, user_id: UUID) -> User:
|
84
72
|
pass
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: passphera-core
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.10.0
|
4
4
|
Summary: The core system of passphera project
|
5
5
|
Home-page: https://github.com/passphera/core
|
6
6
|
Author: Fathi Abdelmalek
|
@@ -15,6 +15,15 @@ Classifier: Topic :: Security :: Cryptography
|
|
15
15
|
Requires-Python: >=3
|
16
16
|
Description-Content-Type: text/markdown
|
17
17
|
Requires-Dist: cipherspy
|
18
|
+
Dynamic: author
|
19
|
+
Dynamic: author-email
|
20
|
+
Dynamic: classifier
|
21
|
+
Dynamic: description
|
22
|
+
Dynamic: description-content-type
|
23
|
+
Dynamic: home-page
|
24
|
+
Dynamic: requires-dist
|
25
|
+
Dynamic: requires-python
|
26
|
+
Dynamic: summary
|
18
27
|
|
19
28
|
# passphera-core
|
20
29
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
passphera_core/__init__.py,sha256=0kEfHV5WvMWDoFn1qCeuD52WsgaX4sQ4V9P48cnFKb8,120
|
2
|
+
passphera_core/entities.py,sha256=vzD6NMA--kUI9DZ39wHCkniRI-bimxMTpE1gh5mzr3k,5180
|
3
|
+
passphera_core/exceptions.py,sha256=5NvV6LW4Pdok6gRxvM0cN3q6JEKgaCYAX8qGr2eqX2w,1890
|
4
|
+
passphera_core/interfaces.py,sha256=plI-jQ7cOKFtcL1Dh5UVfmPbJY525h57l44On9BQfac,1782
|
5
|
+
passphera_core/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
passphera_core/application/generator.py,sha256=ABUigLMtP52CHpTKIZmwNb0pgGeL4s_WgrpxLr1M9zw,3896
|
7
|
+
passphera_core/application/password.py,sha256=osy04J0MD5cZQA47RKH9KqA-P52MB3bWSEr1oirtORM,5533
|
8
|
+
passphera_core/application/user.py,sha256=yKIDxUi56I__KFhRViiTSxEsakFvssynazr3vHX7vqw,2069
|
9
|
+
passphera_core-0.10.0.dist-info/METADATA,sha256=4kQXy2_AgAVos1pEZYB_bLEYAKn8Pen68CVmF51__zM,869
|
10
|
+
passphera_core-0.10.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
11
|
+
passphera_core-0.10.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
12
|
+
passphera_core-0.10.0.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
passphera_core/__init__.py,sha256=0kEfHV5WvMWDoFn1qCeuD52WsgaX4sQ4V9P48cnFKb8,120
|
2
|
-
passphera_core/entities.py,sha256=SvzBKDx9NkaVunXBGT-PgEWbXNXivb8pGw9Q_KFtAgI,5021
|
3
|
-
passphera_core/exceptions.py,sha256=5NvV6LW4Pdok6gRxvM0cN3q6JEKgaCYAX8qGr2eqX2w,1890
|
4
|
-
passphera_core/interfaces.py,sha256=uwHjPd1uhnA02X9h39IrHuNS-_M8j_RyKMVdxi3DUak,2036
|
5
|
-
passphera_core-0.9.0.dist-info/METADATA,sha256=LoH3ACZT9O7vI15hlwhA0psp16_FnNaCU5eOfIr3CCY,671
|
6
|
-
passphera_core-0.9.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
7
|
-
passphera_core-0.9.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
8
|
-
passphera_core-0.9.0.dist-info/RECORD,,
|
File without changes
|