Completed
Pull Request — master (#182)
by
unknown
02:56
created

CertificateHandler.__contains__()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 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