From 1dbaddd75e04365a822cf4bcf05f332a5f845ed6 Mon Sep 17 00:00:00 2001 From: David Poole Date: Wed, 8 Nov 2017 18:32:59 -0700 Subject: [PATCH] for RFC-7616 add SHA-256 and SHA-512 --- requests/auth.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/requests/auth.py b/requests/auth.py index 1a182dff..4ae45947 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -153,6 +153,18 @@ class HTTPDigestAuth(AuthBase): x = x.encode('utf-8') return hashlib.sha1(x).hexdigest() hash_utf8 = sha_utf8 + elif _algorithm == 'SHA-256': + def sha256_utf8(x): + if isinstance(x, str): + x = x.encode('utf-8') + return hashlib.sha256(x).hexdigest() + hash_utf8 = sha256_utf8 + elif _algorithm == 'SHA-512': + def sha512_utf8(x): + if isinstance(x, str): + x = x.encode('utf-8') + return hashlib.sha512(x).hexdigest() + hash_utf8 = sha512_utf8 KD = lambda s, d: hash_utf8("%s:%s" % (s, d))