Skip to content

Commit 8e7174a

Browse files
hashlib: Add support for usedforsecurity keyword (#1662)
1 parent be480c6 commit 8e7174a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ What's New in astroid 2.11.7?
9898
=============================
9999
Release date: TBA
100100

101+
* Added support for ``usedforsecurity`` keyword to ``hashlib`` constructors.
102+
103+
Closes PyCQA/pylint#6017
101104

102105

103106
What's New in astroid 2.11.6?

astroid/brain/brain_hashlib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def _hashlib_transform():
11-
signature = "value=''"
11+
signature = "value='', usedforsecurity=True"
1212
template = """
1313
class %(name)s(object):
1414
def __init__(self, %(signature)s): pass
@@ -34,10 +34,10 @@ def digest_size(self):
3434
)
3535
blake2b_signature = "data=b'', *, digest_size=64, key=b'', salt=b'', \
3636
person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, \
37-
node_depth=0, inner_size=0, last_node=False"
37+
node_depth=0, inner_size=0, last_node=False, usedforsecurity=True"
3838
blake2s_signature = "data=b'', *, digest_size=32, key=b'', salt=b'', \
3939
person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, \
40-
node_depth=0, inner_size=0, last_node=False"
40+
node_depth=0, inner_size=0, last_node=False, usedforsecurity=True"
4141
new_algorithms = dict.fromkeys(
4242
["sha3_224", "sha3_256", "sha3_384", "sha3_512", "shake_128", "shake_256"],
4343
signature,

tests/unittest_brain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def _assert_hashlib_class(self, class_obj: ClassDef) -> None:
7575
self.assertIn("hexdigest", class_obj)
7676
self.assertIn("block_size", class_obj)
7777
self.assertIn("digest_size", class_obj)
78-
self.assertEqual(len(class_obj["__init__"].args.args), 2)
79-
self.assertEqual(len(class_obj["__init__"].args.defaults), 1)
78+
self.assertEqual(len(class_obj["__init__"].args.args), 3)
79+
self.assertEqual(len(class_obj["__init__"].args.defaults), 2)
8080
self.assertEqual(len(class_obj["update"].args.args), 2)
8181
self.assertEqual(len(class_obj["digest"].args.args), 1)
8282
self.assertEqual(len(class_obj["hexdigest"].args.args), 1)

0 commit comments

Comments
 (0)