Skip to content

Commit 0ed8d66

Browse files
authored
use _get_backend everywhere (#5408)
* use _get_backend everywhere * black
1 parent 42ad3b0 commit 0ed8d66

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/cryptography/fernet.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from cryptography import utils
1616
from cryptography.exceptions import InvalidSignature
17-
from cryptography.hazmat.backends import default_backend
17+
from cryptography.hazmat.backends import _get_backend
1818
from cryptography.hazmat.primitives import hashes, padding
1919
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
2020
from cryptography.hazmat.primitives.hmac import HMAC
@@ -29,8 +29,7 @@ class InvalidToken(Exception):
2929

3030
class Fernet(object):
3131
def __init__(self, key, backend=None):
32-
if backend is None:
33-
backend = default_backend()
32+
backend = _get_backend(backend)
3433

3534
key = base64.urlsafe_b64decode(key)
3635
if len(key) != 32:

src/cryptography/hazmat/primitives/serialization/pkcs12.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import, division, print_function
66

77
from cryptography import x509
8-
from cryptography.hazmat.backends import _get_backend, default_backend
8+
from cryptography.hazmat.backends import _get_backend
99
from cryptography.hazmat.primitives import serialization
1010
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa
1111

@@ -44,6 +44,7 @@ def serialize_key_and_certificates(name, key, cert, cas, encryption_algorithm):
4444
if key is None and cert is None and not cas:
4545
raise ValueError("You must supply at least one of key, cert, or cas")
4646

47-
return default_backend().serialize_key_and_certificates_to_pkcs12(
47+
backend = _get_backend(None)
48+
return backend.serialize_key_and_certificates_to_pkcs12(
4849
name, key, cert, cas, encryption_algorithm
4950
)

src/cryptography/hazmat/primitives/serialization/pkcs7.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
from __future__ import absolute_import, division, print_function
66

7-
from cryptography.hazmat.backends import default_backend
7+
from cryptography.hazmat.backends import _get_backend
88

99

1010
def load_pem_pkcs7_certificates(data):
11-
return default_backend().load_pem_pkcs7_certificates(data)
11+
backend = _get_backend(None)
12+
return backend.load_pem_pkcs7_certificates(data)
1213

1314

1415
def load_der_pkcs7_certificates(data):
15-
return default_backend().load_der_pkcs7_certificates(data)
16+
backend = _get_backend(None)
17+
return backend.load_der_pkcs7_certificates(data)

src/cryptography/hazmat/primitives/serialization/ssh.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from cryptography import utils
1515
from cryptography.exceptions import UnsupportedAlgorithm
16-
from cryptography.hazmat.backends import _get_backend, default_backend
16+
from cryptography.hazmat.backends import _get_backend
1717
from cryptography.hazmat.primitives.asymmetric import dsa, ec, ed25519, rsa
1818
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
1919
from cryptography.hazmat.primitives.serialization import (
@@ -579,9 +579,8 @@ def serialize_ssh_private_key(private_key, password=None):
579579
salt = os.urandom(16)
580580
f_kdfoptions.put_sshstr(salt)
581581
f_kdfoptions.put_u32(rounds)
582-
ciph = _init_cipher(
583-
ciphername, password, salt, rounds, default_backend()
584-
)
582+
backend = _get_backend(None)
583+
ciph = _init_cipher(ciphername, password, salt, rounds, backend)
585584
else:
586585
ciphername = kdfname = _NONE
587586
blklen = 8

0 commit comments

Comments
 (0)