Skip to content

Commit

Permalink
Clarify digest hash method names
Browse files Browse the repository at this point in the history
  • Loading branch information
idan committed Apr 11, 2012
1 parent 365c64f commit c89a3e2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions requests/auth.py
Expand Up @@ -74,21 +74,21 @@ def handle_401(self, r):
algorithm = algorithm.upper()
# lambdas assume digest modules are imported at the top level
if algorithm == 'MD5':
def h(x):
def md5_utf8(x):
if isinstance(x, str):
x = x.encode('utf-8')
return hashlib.md5(x).hexdigest()
H = h
hash_utf8 = md5_utf8
elif algorithm == 'SHA':
def h(x):
def sha_utf8(x):
if isinstance(x, str):
x = x.encode('utf-8')
return hashlib.sha1(x).hexdigest()
H = h
hash_utf8 = sha_utf8
# XXX MD5-sess
KD = lambda s, d: H("%s:%s" % (s, d))
KD = lambda s, d: hash_utf8("%s:%s" % (s, d))

if H is None:
if hash_utf8 is None:
return None

# XXX not implemented yet
Expand All @@ -115,10 +115,10 @@ def h(x):
s += randombytes(8)

cnonce = (hashlib.sha1(s).hexdigest()[:16])
noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, H(A2))
respdig = KD(H(A1), noncebit)
noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))
respdig = KD(hash_utf8(A1), noncebit)
elif qop is None:
respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
respdig = KD(hash_utf8(A1), "%s:%s" % (nonce, hash_utf8(A2)))
else:
# XXX handle auth-int.
return None
Expand Down

0 comments on commit c89a3e2

Please sign in to comment.