@@ -1065,23 +1065,16 @@ def dummy(data=b'', *, usedforsecurity=True, string=b''):
10651065
10661066def _block_builtin_hmac_constructor (name ):
10671067 """Block explicit HACL* HMAC constructors."""
1068- fullname = _EXPLICIT_HMAC_CONSTRUCTORS [name ]
1069- if fullname is None :
1068+ info = _HashInfoItem (_EXPLICIT_HMAC_CONSTRUCTORS [name ])
1069+ assert info .module_name is None or info .module_name == "_hmac" , info
1070+ if (wrapped := info .import_member ()) is None :
10701071 # function shouldn't exist for this implementation
10711072 return contextlib .nullcontext ()
1072- assert fullname .count ('.' ) == 1 , fullname
1073- module_name , method = fullname .split ('.' , maxsplit = 1 )
1074- assert module_name == '_hmac' , module_name
1075- try :
1076- module = importlib .import_module (module_name )
1077- except ImportError :
1078- # module is already disabled
1079- return contextlib .nullcontext ()
1080- @functools .wraps (wrapped := getattr (module , method ))
1073+ @functools .wraps (wrapped )
10811074 def wrapper (key , obj ):
10821075 raise ValueError (f"blocked hash name: { name } " )
10831076 _ensure_wrapper_signature (wrapper , wrapped )
1084- return unittest .mock .patch (fullname , wrapper )
1077+ return unittest .mock .patch (info . fullname , wrapper )
10851078
10861079
10871080@contextlib .contextmanager
0 commit comments