diff options
| author | Stanislav Boboň | 2020-12-07 23:09:06 +0100 |
|---|---|---|
| committer | Stanislav Boboň | 2020-12-07 23:09:06 +0100 |
| commit | 2c9f1f74965a720f09f54d613fed925116f53b60 (patch) | |
| tree | e66e8e1acc517bb978e77a4839b841c68401aa9a | |
| parent | 89d97fd6240d38332ad332dcd134f396cb396d7b (diff) | |
| download | sec-certs-2c9f1f74965a720f09f54d613fed925116f53b60.tar.gz sec-certs-2c9f1f74965a720f09f54d613fed925116f53b60.tar.zst sec-certs-2c9f1f74965a720f09f54d613fed925116f53b60.zip | |
fixed fixes
| -rw-r--r-- | sec_certs/certificate.py | 53 | ||||
| -rw-r--r-- | sec_certs/dataset.py | 5 |
2 files changed, 31 insertions, 27 deletions
diff --git a/sec_certs/certificate.py b/sec_certs/certificate.py index 7da5451e..0ec3f16d 100644 --- a/sec_certs/certificate.py +++ b/sec_certs/certificate.py @@ -61,6 +61,35 @@ class FIPSCertificate(Certificate, ComplexSerializableType): FIPS_MODULE_URL: ClassVar[ str] = 'https://csrc.nist.gov/projects/cryptographic-module-validation-program/certificate/' + @dataclass(eq=True, frozen=True) + class Algorithm(ComplexSerializableType): + cert_id: str + vendor: str + implementation: str + type: str + date: str + + + @property + def dgst(self): + # certs in dataset are in format { id: [FIPSAlgorithm] }, there is only one type of algorithm + # for each id + return self.type + + def __repr__(self): + return self.type + ' algorithm #' + self.cert_id + ' created by ' + self.vendor + + def __str__(self): + return str(self.type + ' algorithm #' + self.cert_id + ' created by ' + self.vendor) + + def to_dict(self): + return copy.deepcopy(self.__dict__) + + @classmethod + def from_dict(cls, dct: dict) -> 'FIPSAlgorithm': + return cls(dct['cert_id'], dct['vendor'], dct['implementation'], dct['type'], + dct['date']) + def __init__(self, cert_id: str, module_name: Optional[str], standard: Optional[str], @@ -675,28 +704,4 @@ class CommonCriteriaCert(Certificate, ComplexSerializableType): cert.state.st_convert_ok = False return cert -class FIPSAlgorithm(Certificate, ComplexSerializableType): - @property - def dgst(self): - # certs in dataset are in format { id: [FIPSAlgorithm] }, there is only one type of algorithm - # for each id - return self.type - - def __init__(self, cert_id, vendor, implementation, alg_type, validation_date): - super().__init__() - self.cert_id = cert_id - self.vendor = vendor - self.implementation = implementation - self.type = alg_type - self.date = validation_date - - def __repr__(self): - return self.type + ' algorithm #' + self.cert_id + ' created by ' + self.vendor - def __str__(self): - return str(self.type + ' algorithm #' + self.cert_id + ' created by ' + self.vendor) - - @classmethod - def from_dict(cls, dct: dict) -> 'FIPSAlgorithm': - return FIPSAlgorithm(dct['cert_id'], dct['vendor'], dct['implementation'], dct['type'], - dct['date']) diff --git a/sec_certs/dataset.py b/sec_certs/dataset.py index 9a9d4d68..32469907 100644 --- a/sec_certs/dataset.py +++ b/sec_certs/dataset.py @@ -22,7 +22,7 @@ import sec_certs.constants as constants import sec_certs.cert_processing as cert_processing import sec_certs.files as files -from sec_certs.certificate import CommonCriteriaCert, Certificate, FIPSCertificate, FIPSAlgorithm +from sec_certs.certificate import CommonCriteriaCert, Certificate, FIPSCertificate from sec_certs.serialization import ComplexSerializableType, CustomJSONDecoder, CustomJSONEncoder from sec_certs.extract_certificates import extract_certificates_keywords @@ -742,7 +742,6 @@ class FIPSDataset(Dataset, ComplexSerializableType): for cert_alg in processed_cert.algorithms: for certificate in cert_alg['Certificate']: - print(certificate) curr_id = ''.join(filter(str.isdigit, certificate)) if curr_id == cert_candidate: return False @@ -900,7 +899,7 @@ class FIPSAlgorithmDataset(Dataset, ComplexSerializableType): for i in range(0, len(elements_sliced), 2): alg_type, alg_id = split_alg(elements_sliced[i].text.strip()) validation_date = elements_sliced[i + 1].text.strip() - fips_alg = FIPSAlgorithm(alg_id, vendor, implementation, alg_type, validation_date) + fips_alg = FIPSCertificate.Algorithm(alg_id, vendor, implementation, alg_type, validation_date) if alg_id not in self.certs: self.certs[alg_id] = [] self.certs[alg_id].append(fips_alg) |
