Merge pull request #562 from slingamn/urandom

replace utils.randombytes with os.urandom
This commit is contained in:
Kenneth Reitz
2012-05-15 22:49:27 -07:00
2 changed files with 4 additions and 14 deletions
+3 -2
View File
@@ -7,13 +7,14 @@ requests.auth
This module contains the authentication handlers for Requests.
"""
import os
import time
import hashlib
from base64 import b64encode
from .compat import urlparse, str
from .utils import randombytes, parse_dict_header
from .utils import parse_dict_header
try:
from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)
@@ -192,7 +193,7 @@ class HTTPDigestAuth(AuthBase):
s = str(nonce_count).encode('utf-8')
s += nonce.encode('utf-8')
s += time.ctime().encode('utf-8')
s += randombytes(8)
s += os.urandom(8)
cnonce = (hashlib.sha1(s).hexdigest()[:16])
noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))
+1 -12
View File
@@ -12,14 +12,12 @@ that are also useful for external consumption.
import cgi
import codecs
import os
import random
import re
import zlib
from netrc import netrc, NetrcParseError
from .compat import parse_http_list as _parse_list_header
from .compat import quote, is_py2, urlparse
from .compat import basestring, bytes, str
from .compat import quote, urlparse, basestring, bytes, str
from .cookies import RequestsCookieJar, cookiejar_from_dict
_hush_pyflakes = (RequestsCookieJar,)
@@ -248,15 +246,6 @@ def header_expand(headers):
return ''.join(collector)
def randombytes(n):
"""Return n random bytes."""
if is_py2:
L = [chr(random.randrange(0, 256)) for i in range(n)]
else:
L = [chr(random.randrange(0, 256)).encode('utf-8') for i in range(n)]
return b"".join(L)
def dict_from_cookiejar(cj):
"""Returns a key/value dictionary from a CookieJar.