Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor cryptography.hazmat.* Python imports #717

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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