Skip to content

Commit 82448cd

Browse files
committed
bpo-9216: test usedforsecurity
Signed-off-by: Christian Heimes <christian@python.org>
1 parent 378ab50 commit 82448cd

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

Lib/test/test_hashlib.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ def test_algorithms_available(self):
190190
self.assertTrue(set(hashlib.algorithms_guaranteed).
191191
issubset(hashlib.algorithms_available))
192192

193+
def test_usedforsecurity(self):
194+
for cons in self.hash_constructors:
195+
cons(usedforsecurity=True)
196+
cons(usedforsecurity=False)
197+
cons(b'', usedforsecurity=True)
198+
cons(b'', usedforsecurity=False)
199+
hashlib.new("sha256", usedforsecurity=True)
200+
hashlib.new("sha256", usedforsecurity=False)
201+
193202
def test_unknown_hash(self):
194203
self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam')
195204
self.assertRaises(TypeError, hashlib.new, 1)

Modules/clinic/md5module.c.h

Lines changed: 21 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/md5module.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,15 @@ static PyTypeObject MD5type = {
503503
_md5.md5
504504
505505
string: object(c_default="NULL") = b''
506+
*
507+
usedforsecurity: bool = True
506508
507509
Return a new MD5 hash object; optionally initialized with a string.
508510
[clinic start generated code]*/
509511

510512
static PyObject *
511-
_md5_md5_impl(PyObject *module, PyObject *string)
512-
/*[clinic end generated code: output=2cfd0f8c091b97e6 input=d12ef8f72d684f7b]*/
513+
_md5_md5_impl(PyObject *module, PyObject *string, int usedforsecurity)
514+
/*[clinic end generated code: output=587071f76254a4ac input=7a144a1905636985]*/
513515
{
514516
MD5object *new;
515517
Py_buffer buf;

0 commit comments

Comments
 (0)