Revize c62151d4
Přidáno uživatelem Stanislav Král před téměř 4 roky(ů)
src/controllers/certificates_controller.py | ||
---|---|---|
15 | 15 |
from src.model.subject import Subject |
16 | 16 |
from src.services.certificate_service import CertificateService, RevocationReasonInvalidException, \ |
17 | 17 |
CertificateStatusInvalidException, CertificateNotFoundException, CertificateAlreadyRevokedException, \ |
18 |
CertificateCannotBeSetToValid |
|
18 |
CertificateCannotBeSetToValid, InvalidSubjectAttribute
|
|
19 | 19 |
# responsibility. |
20 | 20 |
from src.services.cryptography import CryptographyException |
21 | 21 |
from src.services.key_service import KeyService |
... | ... | |
200 | 200 |
return E_INVALID_EXTENSIONS, C_BAD_REQUEST |
201 | 201 |
else: |
202 | 202 |
raise CryptographyException(e.executable, e.args, e.message) |
203 |
except InvalidSubjectAttribute as e: |
|
204 |
return {"success": False, "data": str(e)}, C_BAD_REQUEST |
|
203 | 205 |
|
204 | 206 |
if cert is not None: |
205 | 207 |
return {"success": True, |
src/services/certificate_service.py | ||
---|---|---|
57 | 57 |
:raises InvalidCertificateAttribute: When a subject with an invalid attribute is passed |
58 | 58 |
""" |
59 | 59 |
if subject.country is not None and len(subject.country) != 2: |
60 |
raise InvalidSubjectAttribute("Country code", "Must consist of exactly 2 letters.")
|
|
60 |
raise InvalidSubjectAttribute("Country code", "Must consist of exactly 2 letters") |
|
61 | 61 |
|
62 | 62 |
# TODO usages present in method parameters but not in class diagram |
63 | 63 |
def create_root_ca(self, key: PrivateKey, subject: Subject, extensions: str = "", config: str = "", |
... | ... | |
637 | 637 |
self.reason = reason |
638 | 638 |
|
639 | 639 |
def __str__(self): |
640 |
return f"""Subject attribute "{self.attribute_name} is invalid (reason: {self.reason}).""" |
|
640 |
return f"""Subject attribute "{self.attribute_name}" is invalid (reason: {self.reason}).""" |
Také k dispozici: Unified diff
Improved InvalidSubjectAttribute string representation and added an "except" block in CertificateController that handles this error.