@@ -828,18 +828,11 @@ def setUpClass(cls):
828828 cls .hashlib = import_helper .import_module ("hashlib" )
829829 cls .hmac = import_helper .import_module ("hmac" )
830830
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" )
843836
844837 def check_context (self , disabled = True ):
845838 if disabled :
@@ -886,9 +879,6 @@ def fetch_hmac_function(self, name):
886879
887880 def check_openssl_hash (self , name , * , disabled = True ):
888881 """Check that OpenSSL HASH interface is enabled/disabled."""
889- if self ._hashlib is None :
890- return
891-
892882 with self .check_context (disabled ):
893883 _ = self ._hashlib .new (name )
894884 if do_hash := self .fetch_hash_function (name , "openssl" ):
@@ -898,9 +888,6 @@ def check_openssl_hash(self, name, *, disabled=True):
898888
899889 def check_openssl_hmac (self , name , * , disabled = True ):
900890 """Check that OpenSSL HMAC interface is enabled/disabled."""
901- if self ._hashlib is None :
902- return
903-
904891 if name in hashlib_helper .NON_HMAC_DIGEST_NAMES :
905892 # HMAC-BLAKE and HMAC-SHAKE raise a ValueError as they are not
906893 # supported at all (they do not make any sense in practice).
@@ -920,9 +907,6 @@ def check_builtin_hash(self, name, *, disabled=True):
920907
921908 def check_builtin_hmac (self , name , * , disabled = True ):
922909 """Check that HACL* HMAC interface is enabled/disabled."""
923- if self ._hmac is None :
924- return
925-
926910 if name in hashlib_helper .NON_HMAC_DIGEST_NAMES :
927911 # HMAC-BLAKE and HMAC-SHAKE raise a ValueError as they are not
928912 # supported at all (they do not make any sense in practice).
0 commit comments