@@ -1100,6 +1100,11 @@ def HMAC(self, key, msg=None):
1100
1100
"""Create a HMAC object."""
1101
1101
raise NotImplementedError
1102
1102
1103
+ @property
1104
+ def gil_minsize (self ):
1105
+ """Get the maximal input length for the GIL to be held."""
1106
+ raise NotImplementedError
1107
+
1103
1108
def check_update (self , key , chunks ):
1104
1109
chunks = list (chunks )
1105
1110
msg = b'' .join (chunks )
@@ -1118,11 +1123,10 @@ def test_update(self):
1118
1123
self .check_update (key , [msg ])
1119
1124
1120
1125
def test_update_large (self ):
1121
- HASHLIB_GIL_MINSIZE = 2048
1122
-
1126
+ gil_minsize = self .gil_minsize
1123
1127
key = random .randbytes (16 )
1124
- top = random .randbytes (HASHLIB_GIL_MINSIZE + 1 )
1125
- bot = random .randbytes (HASHLIB_GIL_MINSIZE + 1 )
1128
+ top = random .randbytes (gil_minsize + 1 )
1129
+ bot = random .randbytes (gil_minsize + 1 )
1126
1130
self .check_update (key , [top , bot ])
1127
1131
1128
1132
def test_update_exceptions (self ):
@@ -1132,19 +1136,27 @@ def test_update_exceptions(self):
1132
1136
self .assertRaises (TypeError , h .update , msg )
1133
1137
1134
1138
1135
- @hashlib_helper . requires_hashdigest ( 'sha256' )
1139
+ @requires_builtin_sha2 ( )
1136
1140
class PyUpdateTestCase (PyModuleMixin , UpdateTestCaseMixin , unittest .TestCase ):
1137
1141
1138
1142
def HMAC (self , key , msg = None ):
1139
1143
return self .hmac .HMAC (key , msg , digestmod = 'sha256' )
1140
1144
1145
+ @property
1146
+ def gil_minsize (self ):
1147
+ return sha2 ._GIL_MINSIZE
1148
+
1141
1149
1142
1150
@hashlib_helper .requires_openssl_hashdigest ('sha256' )
1143
1151
class OpenSSLUpdateTestCase (UpdateTestCaseMixin , unittest .TestCase ):
1144
1152
1145
1153
def HMAC (self , key , msg = None ):
1146
1154
return _hashlib .hmac_new (key , msg , digestmod = 'sha256' )
1147
1155
1156
+ @property
1157
+ def gil_minsize (self ):
1158
+ return _hashlib ._GIL_MINSIZE
1159
+
1148
1160
1149
1161
class BuiltinUpdateTestCase (BuiltinModuleMixin ,
1150
1162
UpdateTestCaseMixin , unittest .TestCase ):
@@ -1154,6 +1166,10 @@ def HMAC(self, key, msg=None):
1154
1166
# are still built, making it possible to use SHA-2 hashes.
1155
1167
return self .hmac .new (key , msg , digestmod = 'sha256' )
1156
1168
1169
+ @property
1170
+ def gil_minsize (self ):
1171
+ return self .hmac ._GIL_MINSIZE
1172
+
1157
1173
1158
1174
class CopyBaseTestCase :
1159
1175
0 commit comments