3
3
import logging
4
4
5
5
from cryptography import x509
6
- from cryptography .hazmat .backends import default_backend
7
6
from cryptography .hazmat .primitives import serialization
8
7
from cryptography .hazmat .primitives .asymmetric import ec
9
8
from cryptography .hazmat .primitives .asymmetric import rsa
@@ -22,7 +21,7 @@ def import_public_key_from_pem_file(filename):
22
21
:return: A public key instance
23
22
"""
24
23
with open (filename , "rb" ) as key_file :
25
- public_key = serialization .load_pem_public_key (key_file .read (), backend = default_backend () )
24
+ public_key = serialization .load_pem_public_key (key_file .read ())
26
25
return public_key
27
26
28
27
@@ -35,9 +34,7 @@ def import_private_key_from_pem_file(filename, passphrase=None):
35
34
:return: A private key instance
36
35
"""
37
36
with open (filename , "rb" ) as key_file :
38
- private_key = serialization .load_pem_private_key (
39
- key_file .read (), password = passphrase , backend = default_backend ()
40
- )
37
+ private_key = serialization .load_pem_private_key (key_file .read (), password = passphrase )
41
38
return private_key
42
39
43
40
@@ -56,7 +53,7 @@ def import_public_key_from_pem_data(pem_data):
56
53
pem_data = bytes ("{}\n {}\n {}" .format (PREFIX , pem_data , POSTFIX ), "utf-8" )
57
54
else :
58
55
pem_data = bytes (pem_data , "utf-8" )
59
- cert = x509 .load_pem_x509_certificate (pem_data , default_backend () )
56
+ cert = x509 .load_pem_x509_certificate (pem_data )
60
57
return cert .public_key ()
61
58
62
59
@@ -68,7 +65,7 @@ def import_public_key_from_cert_file(filename):
68
65
:return: A public key instance
69
66
"""
70
67
with open (filename , "rb" ) as key_file :
71
- cert = x509 .load_pem_x509_certificate (key_file .read (), backend = default_backend () )
68
+ cert = x509 .load_pem_x509_certificate (key_file .read ())
72
69
return cert .public_key ()
73
70
74
71
@@ -81,7 +78,7 @@ def der_cert(der_data):
81
78
"""
82
79
if isinstance (der_data , str ):
83
80
der_data = bytes (der_data , "utf-8" )
84
- return x509 .load_der_x509_certificate (der_data , default_backend () )
81
+ return x509 .load_der_x509_certificate (der_data )
85
82
86
83
87
84
def load_x509_cert (url , httpc , spec2key , ** get_args ):
0 commit comments