Skip to content

Commit

Permalink
chore: Refactor cryptography.hazmat.* Python imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrobles-cdd committed Oct 1, 2024
1 parent 318d19c commit bae3f61
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cl_sii/libs/crypto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
import base64
from typing import Union

import cryptography.hazmat.backends.openssl.backend as _crypto_x509_backend
import cryptography.x509
import signxml.util
from cryptography.hazmat.backends.openssl import backend as _crypto_x509_backend
from cryptography.x509 import Certificate as X509Cert
from OpenSSL.crypto import X509 as _X509CertOpenSsl

Expand Down
6 changes: 3 additions & 3 deletions src/cl_sii/rut/crypto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from typing import Optional

import cryptography
import cryptography.hazmat.backends.openssl.backend as crypto_x509_backend
import cryptography.hazmat.primitives.serialization.pkcs12
import cryptography.x509
from cryptography.hazmat.backends.openssl import backend as crypto_x509_backend
from cryptography.hazmat.primitives.serialization import pkcs12

from . import Rut, constants

Expand All @@ -22,7 +22,7 @@ def get_subject_rut_from_certificate_pfx(pfx_file_bytes: bytes, password: Option
private_key,
x509_cert,
additional_certs,
) = pkcs12.load_key_and_certificates(
) = cryptography.hazmat.primitives.serialization.pkcs12.load_key_and_certificates(
data=pfx_file_bytes,
password=password.encode() if password is not None else None,
backend=crypto_x509_backend,
Expand Down
8 changes: 4 additions & 4 deletions src/tests/test_rut_crypto_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest
from unittest.mock import Mock, patch

import cryptography.hazmat.primitives.serialization.pkcs12
import cryptography.x509
from cryptography.hazmat.primitives.serialization import pkcs12

from cl_sii import rut
from cl_sii.libs.crypto_utils import load_der_x509_cert
Expand All @@ -19,7 +19,7 @@ def test_get_subject_rut_from_certificate_pfx_ok(self) -> None:
x509_cert = load_der_x509_cert(cert_der_bytes)

with patch.object(
pkcs12,
cryptography.hazmat.primitives.serialization.pkcs12,
'load_key_and_certificates',
Mock(return_value=(None, x509_cert, None)),
):
Expand All @@ -40,7 +40,7 @@ def test_get_subject_rut_from_certificate_pfx_fails_if_rut_info_is_missing(self)
x509_cert = load_der_x509_cert(cert_der_bytes)

with patch.object(
pkcs12,
cryptography.hazmat.primitives.serialization.pkcs12,
'load_key_and_certificates',
Mock(return_value=(None, x509_cert, None)),
):
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_get_subject_rut_from_certificate_pfx_does_not_throw_attribute_error_if_
)

with patch.object(
pkcs12,
cryptography.hazmat.primitives.serialization.pkcs12,
'load_key_and_certificates',
Mock(return_value=(None, x509_cert, None)),
), patch.object(
Expand Down

0 comments on commit bae3f61

Please sign in to comment.