Skip to content
Myr

Merge pull request #562 from slingamn/urandom

Before adoption: this commit came in with the history the project adopted, so no landing records it.

replace utils.randombytes with os.urandom

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 355003b, f25827c · Browse files · 2 files+4 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+4 added−14 removed

  • other:+4 added−14 removed

2 files+4 added−14 removed

modified:requests/auth.py+3 added-2 removed
5 unmodified lines
67This module contains the authentication handlers for Requests.8"""910import os11import time12import hashlib1314from base64 import b64encode1516from .compat import urlparse, str16from .utils import randombytes, parse_dict_header17from .utils import parse_dict_header1819try:20 from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)21 from oauthlib.common import extract_params
170 unmodified lines
192 ncvalue = '%08x' % nonce_count193 s = str(nonce_count).encode('utf-8')194 s += nonce.encode('utf-8')195 s += time.ctime().encode('utf-8')195 s += randombytes(8)196 s += os.urandom(8)197198 cnonce = (hashlib.sha1(s).hexdigest()[:16])199 noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))200 respdig = KD(hash_utf8(A1), noncebit)
29 unmodified lines
modified:requests/utils.py+1 added-12 removed
10 unmodified lines
1112import cgi13import codecs14import os15import random15import re16import zlib17from netrc import netrc, NetrcParseError1819from .compat import parse_http_list as _parse_list_header21from .compat import quote, is_py2, urlparse22from .compat import basestring, bytes, str20from .compat import quote, urlparse, basestring, bytes, str21from .cookies import RequestsCookieJar, cookiejar_from_dict2223_hush_pyflakes = (RequestsCookieJar,)24
220 unmodified lines
245246 return ''.join(collector)247248251def randombytes(n):252 """Return n random bytes."""253 if is_py2:254 L = [chr(random.randrange(0, 256)) for i in range(n)]255 else:256 L = [chr(random.randrange(0, 256)).encode('utf-8') for i in range(n)]257 return b"".join(L)258259249def dict_from_cookiejar(cj):250 """Returns a key/value dictionary from a CookieJar.251252 :param cj: CookieJar object to extract cookies from.
201 unmodified lines