Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7a30da1b

Přidáno uživatelem Stanislav Král před téměř 4 roky(ů)

Added a new exception that is thrown when a subject with an invalid attribute is passed while creating a new certificate via CertificateService.

Zobrazit rozdíly:

src/services/certificate_service.py
49 49
        self.certificate_repository = certificate_repository
50 50
        self.configuration = configuration
51 51

  
52
    @staticmethod
53
    def __check_subject_is_valid(subject: Subject):
54
        if subject.country is not None and len(subject.country) != 2:
55
            raise InvalidSubjectAttribute("Country code", "Must consist of exactly 2 letters.")
56

  
52 57
    # TODO usages present in method parameters but not in class diagram
53 58
    def create_root_ca(self, key: PrivateKey, subject: Subject, extensions: str = "", config: str = "",
54 59
                       usages=None, days=30):
......
65 70

  
66 71
        Logger.debug("Function launched.")
67 72

  
73
        # check whether the given subject is valid
74
        self.__check_subject_is_valid(subject)
75

  
68 76
        if usages is None:
69 77
            usages = {}
70 78

  
......
137 145

  
138 146
        Logger.debug("Function launched.")
139 147

  
148
        # check whether the given subject is valid
149
        self.__check_subject_is_valid(subject)
150

  
140 151
        if usages is None:
141 152
            usages = {}
142 153

  
......
188 199

  
189 200
        Logger.debug("Function launched.")
190 201

  
202
        # check whether the given subject is valid
203
        self.__check_subject_is_valid(subject)
204

  
191 205
        if usages is None:
192 206
            usages = {}
193 207

  
......
601 615
        return "Cannot set revoked certificate back to valid when the certificate revocation reason is not " \
602 616
               "certificateHold. " \
603 617
               f"The revocation reason of the certificate is {self.old_state}"
618

  
619

  
620
class InvalidSubjectAttribute(Exception):
621
    """
622
    Exception that denotes that the caller was trying to
623
    create a certificate while passing a subject with an invalid
624
    attribute.
625
    """
626

  
627
    def __init__(self, attribute_name, reason):
628
        self.attribute_name = attribute_name
629
        self.reason = reason
630

  
631
    def __str__(self):
632
        return f"""Subject attribute "{self.attribute_name} is invalid (reason: {self.reason})."""

Také k dispozici: Unified diff