@@ -828,18 +828,11 @@ def setUpClass(cls):
828
828
cls .hashlib = import_helper .import_module ("hashlib" )
829
829
cls .hmac = import_helper .import_module ("hmac" )
830
830
831
- try :
832
- import _hashlib
833
- except ImportError :
834
- cls ._hashlib = None
835
- else :
836
- cls ._hashlib = _hashlib
837
- try :
838
- import _hmac
839
- except ImportError :
840
- cls ._hmac = None
841
- else :
842
- cls ._hmac = _hmac
831
+ # We required the extension modules to be present since blocking
832
+ # HACL* implementations while allowing OpenSSL ones would still
833
+ # result in failures.
834
+ cls ._hashlib = import_helper .import_module ("_hashlib" )
835
+ cls ._hmac = import_helper .import_module ("_hmac" )
843
836
844
837
def check_context (self , disabled = True ):
845
838
if disabled :
@@ -886,9 +879,6 @@ def fetch_hmac_function(self, name):
886
879
887
880
def check_openssl_hash (self , name , * , disabled = True ):
888
881
"""Check that OpenSSL HASH interface is enabled/disabled."""
889
- if self ._hashlib is None :
890
- return
891
-
892
882
with self .check_context (disabled ):
893
883
_ = self ._hashlib .new (name )
894
884
if do_hash := self .fetch_hash_function (name , "openssl" ):
@@ -898,9 +888,6 @@ def check_openssl_hash(self, name, *, disabled=True):
898
888
899
889
def check_openssl_hmac (self , name , * , disabled = True ):
900
890
"""Check that OpenSSL HMAC interface is enabled/disabled."""
901
- if self ._hashlib is None :
902
- return
903
-
904
891
if name in hashlib_helper .NON_HMAC_DIGEST_NAMES :
905
892
# HMAC-BLAKE and HMAC-SHAKE raise a ValueError as they are not
906
893
# supported at all (they do not make any sense in practice).
@@ -920,9 +907,6 @@ def check_builtin_hash(self, name, *, disabled=True):
920
907
921
908
def check_builtin_hmac (self , name , * , disabled = True ):
922
909
"""Check that HACL* HMAC interface is enabled/disabled."""
923
- if self ._hmac is None :
924
- return
925
-
926
910
if name in hashlib_helper .NON_HMAC_DIGEST_NAMES :
927
911
# HMAC-BLAKE and HMAC-SHAKE raise a ValueError as they are not
928
912
# supported at all (they do not make any sense in practice).
0 commit comments