passphera-core 0.9.0__tar.gz → 0.10.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: passphera-core
3
- Version: 0.9.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,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)
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:
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)
71
+ for password_id in user_entity.passwords:
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:
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:
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
@@ -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
- generator: UUID = field(default_factory=UUID)
119
- passwords: list[UUID] = field(default_factory=list[UUID])
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.passwords.append(password_id)
126
+ self.passwords_ids.append(password_id)
123
127
 
124
128
  def delete_password(self, password_id: UUID) -> None:
125
- self.passwords.remove(password_id)
129
+ self.passwords_ids.remove(password_id)
@@ -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
1
+ Metadata-Version: 2.2
2
2
  Name: passphera-core
3
- Version: 0.9.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
 
@@ -8,4 +8,8 @@ passphera_core.egg-info/PKG-INFO
8
8
  passphera_core.egg-info/SOURCES.txt
9
9
  passphera_core.egg-info/dependency_links.txt
10
10
  passphera_core.egg-info/requires.txt
11
- passphera_core.egg-info/top_level.txt
11
+ passphera_core.egg-info/top_level.txt
12
+ passphera_core/application/__init__.py
13
+ passphera_core/application/generator.py
14
+ passphera_core/application/password.py
15
+ passphera_core/application/user.py
@@ -1,18 +1,18 @@
1
- from setuptools import setup
1
+ from setuptools import setup, find_packages
2
2
 
3
3
  with open("README.md", "r") as fh:
4
4
  long_description = fh.read()
5
5
 
6
6
  setup(
7
7
  name='passphera-core',
8
- version='0.9.0',
8
+ version='0.10.0',
9
9
  author='Fathi Abdelmalek',
10
10
  author_email='abdelmalek.fathi.2001@gmail.com',
11
11
  url='https://github.com/passphera/core',
12
12
  description='The core system of passphera project',
13
13
  long_description=long_description,
14
14
  long_description_content_type="text/markdown",
15
- packages=['passphera_core'],
15
+ packages=find_packages(),
16
16
  python_requires='>=3',
17
17
  install_requires=['cipherspy'],
18
18
  classifiers=[