Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(38892)

Delta Between Two Patch Sets: Lib/hashlib.py

Issue 16113: Add SHA-3 (Keccak) support
Left Patch Set: Created 3 years, 4 months ago
Right Patch Set: Created 3 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/hashlib.rst ('k') | Lib/test/test_hashlib.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #. Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org) 1 #. Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org)
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 # 3 #
4 4
5 __doc__ = """hashlib module - A common interface to many hash functions. 5 __doc__ = """hashlib module - A common interface to many hash functions.
6 6
7 new(name, data=b'') - returns a new hash object implementing the 7 new(name, data=b'') - returns a new hash object implementing the
8 given hash function; initializing the hash 8 given hash function; initializing the hash
9 using the given binary data. 9 using the given binary data.
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 More condensed: 48 More condensed:
49 49
50 >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest() 50 >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest()
51 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' 51 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
52 52
53 """ 53 """
54 54
55 # This tuple and __get_builtin_constructor() must be modified if a new 55 # This tuple and __get_builtin_constructor() must be modified if a new
56 # always available algorithm is added. 56 # always available algorithm is added.
57 __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') 57 __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
58 58 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
59 # Supported on most platforms 59 'shake_128', 'shake_256')
60 __often_supported = ('sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 60
61 'shake_128', 'shake_256')
62 61
63 algorithms_guaranteed = set(__always_supported) 62 algorithms_guaranteed = set(__always_supported)
64 algorithms_available = set(__always_supported) 63 algorithms_available = set(__always_supported)
65 64
66 __all__ = __always_supported + ('new', 'algorithms_guaranteed', 65 __all__ = __always_supported + ('new', 'algorithms_guaranteed',
67 'algorithms_available', 'pbkdf2_hmac') 66 'algorithms_available', 'pbkdf2_hmac')
68 67
69 68
70 __builtin_constructor_cache = {} 69 __builtin_constructor_cache = {}
71 70
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 217
219 for __func_name in __always_supported: 218 for __func_name in __always_supported:
220 # try them all, some may not work due to the OpenSSL 219 # try them all, some may not work due to the OpenSSL
221 # version not supporting that algorithm. 220 # version not supporting that algorithm.
222 try: 221 try:
223 globals()[__func_name] = __get_hash(__func_name) 222 globals()[__func_name] = __get_hash(__func_name)
224 except ValueError: 223 except ValueError:
225 import logging 224 import logging
226 logging.exception('code for hash %s was not found.', __func_name) 225 logging.exception('code for hash %s was not found.', __func_name)
227 226
228 for __func_name in __often_supported:
229 try:
230 globals()[__func_name] = __get_hash(__func_name)
231 except ValueError:
232 pass
233 else:
234 algorithms_available.add(__func_name)
235
236 227
237 # Cleanup locals() 228 # Cleanup locals()
238 del __always_supported, __often_supported, __func_name, __get_hash 229 del __always_supported, __func_name, __get_hash
239 del __py_new, __hash_new, __get_openssl_constructor 230 del __py_new, __hash_new, __get_openssl_constructor
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+