Total Complexity | 3 |
Total Lines | 22 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from asyncua.crypto import uacrypto |
||
2 | from uuid import uuid4 |
||
3 | from cryptography.hazmat.primitives import serialization |
||
4 | import sys |
||
5 | from pprint import pprint as pp |
||
6 | sys.path.append('..') |
||
7 | |||
8 | |||
9 | class CertificateHandler: |
||
10 | def __init__(self): |
||
11 | self._trusted_certificates = {} |
||
12 | |||
13 | async def trust_certificate(self, certificate_path: str, format: str = None): |
||
14 | certificate = await uacrypto.load_certificate(certificate_path, format) |
||
15 | |||
16 | self._trusted_certificates[certificate_path] = uacrypto.der_from_x509(certificate) |
||
17 | |||
18 | def __contains__(self, certificate): |
||
19 | return any(certificate == prospective_cert |
||
20 | for prospective_cert |
||
21 | in self._trusted_certificates.values()) |
||
22 |