Skip to content

Commit a044b02

Browse files
authored
Move DigestAuth hash algorithms to use usedforsecurity=False (#7310)
1 parent 16df2a0 commit a044b02

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/requests/auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,31 @@ def build_digest_header(self, method, url):
145145
def md5_utf8(x):
146146
if isinstance(x, str):
147147
x = x.encode("utf-8")
148-
return hashlib.md5(x).hexdigest()
148+
return hashlib.md5(x, usedforsecurity=False).hexdigest()
149149

150150
hash_utf8 = md5_utf8
151151
elif _algorithm == "SHA":
152152

153153
def sha_utf8(x):
154154
if isinstance(x, str):
155155
x = x.encode("utf-8")
156-
return hashlib.sha1(x).hexdigest()
156+
return hashlib.sha1(x, usedforsecurity=False).hexdigest()
157157

158158
hash_utf8 = sha_utf8
159159
elif _algorithm == "SHA-256":
160160

161161
def sha256_utf8(x):
162162
if isinstance(x, str):
163163
x = x.encode("utf-8")
164-
return hashlib.sha256(x).hexdigest()
164+
return hashlib.sha256(x, usedforsecurity=False).hexdigest()
165165

166166
hash_utf8 = sha256_utf8
167167
elif _algorithm == "SHA-512":
168168

169169
def sha512_utf8(x):
170170
if isinstance(x, str):
171171
x = x.encode("utf-8")
172-
return hashlib.sha512(x).hexdigest()
172+
return hashlib.sha512(x, usedforsecurity=False).hexdigest()
173173

174174
hash_utf8 = sha512_utf8
175175

@@ -202,7 +202,7 @@ def sha512_utf8(x):
202202
s += time.ctime().encode("utf-8")
203203
s += os.urandom(8)
204204

205-
cnonce = hashlib.sha1(s).hexdigest()[:16]
205+
cnonce = hashlib.sha1(s, usedforsecurity=False).hexdigest()[:16]
206206
if _algorithm == "MD5-SESS":
207207
HA1 = hash_utf8(f"{HA1}:{nonce}:{cnonce}")
208208

0 commit comments

Comments
 (0)