Skip to content

Commit 4c6a5c6

Browse files
committed
Import OpenSSL Cryptography backend directly.
1 parent 387c46c commit 4c6a5c6

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

flask_fastspring.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import requests
33

44
from base64 import b64encode
5-
from cryptography.hazmat.backends import _available_backends
65
from cryptography.hazmat.primitives.ciphers import Cipher
76
from cryptography.hazmat.primitives.ciphers.algorithms import AES
87
from cryptography.hazmat.primitives.ciphers.modes import ECB
@@ -56,7 +55,8 @@ def init_app(self, app):
5655
return
5756
private_key = app.config.get('FASTSPRING_PRIVATE_KEY')
5857
if private_key is not None:
59-
self.openssl = openssl_backend()
58+
from cryptography.hazmat.backends.openssl.backend import backend
59+
self.openssl = backend
6060
with open(private_key, 'rb') as fp:
6161
self.private_key = load_pem_private_key(
6262
fp.read(), password=None, backend=self.openssl)
@@ -219,14 +219,6 @@ def __str__(self):
219219
self.response.text)
220220

221221

222-
def openssl_backend():
223-
"""Return OpenSSL cryptography backend or fail."""
224-
for backend in _available_backends():
225-
if backend.name == 'openssl':
226-
return backend
227-
raise Exception('Could not find OpenSSL cryptography backend')
228-
229-
230222
def openssl_private_encrypt(key, data, backend):
231223
"""Encrypt data with RSA private key.
232224

0 commit comments

Comments
 (0)