-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsa_signer.py
64 lines (49 loc) · 1.89 KB
/
dsa_signer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from .dsa_base import DSABase
from .dsa_hasher import DSAHasher
from .dsa_sign import DSASign, sign_data
class DSASigner(DSAHasher):
def __init__(self, sign: DSASign = None,
sign_name=""):
super().__init__()
self._sign = sign
self._sign_name = sign_name
@property
def sign_filename(self) -> str:
result = self._sign_name if len(self._sign_name) > 0 else self.filename
result += DSABase.SIGN_EXTENSION
return result
@property
def sign_path(self):
return self.dirname + '/' + self.sign_filename
def _get_sign_name(self) -> str:
return self._sign_name
def _set_sign_name(self, sign_name: str):
self._sign_name = sign_name
sign_name = property(_get_sign_name, _set_sign_name)
def sign_file(self):
if self.is_available_for_signing:
self._sign = sign_data(self.keys_container.public_key,
self.keys_container.private_key,
self.hashed_data,
self.hash_algorithm)
def write_sign(self):
self._sign.write_into_file(self.sign_path)
@property
def sign(self) -> DSASign:
return self._sign
@property
def has_sign(self) -> bool:
return self._sign is not None
@property
def has_hash_algorithm(self) -> bool:
return self.hash_algorithm is not None and len(self.hash_algorithm) > 0
@property
def has_keys_container_wih_keys(self) -> bool:
return self.has_keys_container and self.keys_container.has_keys
@property
def has_hashed_data_with_hash_algorithm(self) -> bool:
return self.has_hashed_data and self.has_hash_algorithm
@property
def is_available_for_signing(self) -> bool:
return self.has_keys_container_wih_keys \
and self.has_hashed_data_with_hash_algorithm