Automatic switch to internal backend on missing PyCA module

pull/76/head
Mark Qvist 2022-06-08 21:25:46 +02:00
rodzic 60e3c7348a
commit 7916b8e7f4
2 zmienionych plików z 36 dodań i 2 usunięć

Wyświetl plik

@ -1,5 +1,38 @@
import importlib
PROVIDER_NONE = 0x00
PROVIDER_INTERNAL = 0x01 PROVIDER_INTERNAL = 0x01
PROVIDER_PYCA = 0x02 PROVIDER_PYCA = 0x02
PROVIDER = PROVIDER_PYCA PROVIDER = PROVIDER_NONE
# PROVIDER = PROVIDER_INTERNAL
pyca_v = None
use_pyca = False
try:
if importlib.util.find_spec('cryptography') != None:
import cryptography
pyca_v = cryptography.__version__
v = pyca_v.split(".")
if int(v[0]) == 2:
if int(v[1]) >= 8:
use_pyca = True
elif int(v[0]) >= 3:
use_pyca = True
except Exception as e:
pass
if use_pyca:
PROVIDER = PROVIDER_PYCA
else:
PROVIDER = PROVIDER_INTERNAL
def backend():
if PROVIDER == PROVIDER_NONE:
return "none"
elif PROVIDER == PROVIDER_INTERNAL:
return "internal"
elif PROVIDER == PROVIDER_PYCA:
return "openssl, PyCA "+str(pyca_v)

Wyświetl plik

@ -6,6 +6,7 @@ from .Hashes import sha512
from .HKDF import hkdf from .HKDF import hkdf
from .PKCS7 import PKCS7 from .PKCS7 import PKCS7
from .Fernet import Fernet from .Fernet import Fernet
from .Provider import backend
import RNS.Cryptography.Provider as cp import RNS.Cryptography.Provider as cp