Revize f62119d4
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
src/services/key_service.py | ||
---|---|---|
1 |
from src.dao.private_key_repository import PrivateKeyRepository |
|
2 |
from src.model.private_key import PrivateKey |
|
3 |
from src.services.cryptography import CryptographyService |
|
4 |
|
|
5 |
|
|
6 |
class KeyService: |
|
7 |
|
|
8 |
def __init__(self, cryptography_service: CryptographyService, private_key_repository: PrivateKeyRepository): |
|
9 |
self.cryptography_service = cryptography_service |
|
10 |
self.private_key_repository = private_key_repository |
|
11 |
|
|
12 |
def create_new_key(self, passphrase=""): |
|
13 |
# generate a new private key |
|
14 |
private_key_pem = self.cryptography_service.create_private_key(passphrase) |
|
15 |
|
|
16 |
# store generated PK and the passphrase in a wrapper |
|
17 |
private_key = PrivateKey(-1, private_key_pem, passphrase) |
|
18 |
|
|
19 |
# store the wrapper in the PK repository |
|
20 |
private_key_id = self.private_key_repository.create(private_key) |
|
21 |
|
|
22 |
# assign the generated ID to the wrapper |
|
23 |
private_key.private_key_id = private_key_id |
|
24 |
|
|
25 |
return private_key |
|
26 |
|
|
27 |
def get_key(self, unique_id): |
|
28 |
return self.private_key_repository.read(unique_id) |
|
29 |
|
|
30 |
def get_keys(self, unique_ids): |
|
31 |
return [self.private_key_repository.read(identifier) for identifier in unique_ids] |
|
32 |
|
|
33 |
def delete_key(self, unique_id): |
|
34 |
return self.private_key_repository.delete(unique_id) |
Také k dispozici: Unified diff
Re #8472 - Implemented KeyService