| Total Complexity | 7 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import base64 |
||
| 2 | import logging |
||
| 3 | import random |
||
| 4 | from datetime import datetime |
||
| 5 | from uuid import UUID |
||
| 6 | |||
| 7 | from satcfdi import Signer |
||
| 8 | |||
| 9 | |||
| 10 | def to_uuid(s): |
||
| 11 | try: |
||
| 12 | return UUID(s) |
||
| 13 | except ValueError: |
||
| 14 | return None |
||
| 15 | |||
| 16 | |||
| 17 | def random_string(): |
||
| 18 | hash = random.randbytes(32) |
||
| 19 | res = base64.urlsafe_b64encode(hash).decode() |
||
| 20 | return res.rstrip("=") |
||
| 21 | |||
| 22 | |||
| 23 | def add_file_handler(): |
||
| 24 | fh = logging.FileHandler( |
||
| 25 | f'.data/errors.log', |
||
| 26 | mode='a' |
||
| 27 | ) |
||
| 28 | fh.setLevel(logging.ERROR) |
||
| 29 | formatter = logging.Formatter('%(asctime)s - %(message)s') |
||
| 30 | fh.setFormatter(formatter) |
||
| 31 | logging.root.addHandler(fh) |
||
| 32 | |||
| 33 | |||
| 34 | def convert_ans1_date(ans1_date): |
||
| 35 | return datetime.strptime(ans1_date.decode('utf-8'), '%Y%m%d%H%M%SZ') |
||
| 36 | |||
| 37 | |||
| 38 | def cert_info(signer: Signer): |
||
| 39 | if signer: |
||
| 40 | return { |
||
| 41 | "NoCertificado": signer.certificate_number, |
||
| 42 | "Tipo": str(signer.type), |
||
| 43 | |||
| 44 | "organizationName": signer.certificate.get_subject().O, |
||
| 45 | "x500UniqueIdentifier": signer.certificate.get_subject().x500UniqueIdentifier, |
||
| 46 | "serialNumber": signer.certificate.get_subject().serialNumber, |
||
| 47 | "organizationUnitName": signer.certificate.get_subject().OU, |
||
| 48 | "emailAddress": signer.certificate.get_subject().emailAddress, |
||
| 49 | |||
| 50 | "notAfter": convert_ans1_date(signer.certificate.get_notAfter()), |
||
| 51 | "notBefore": convert_ans1_date(signer.certificate.get_notBefore()), |
||
| 52 | } |