[Python-checkins] Docs: correct hashlib.blake2 keyed hashing example (bpo-31560)

Benjamin Peterson webhook-mailer at python.org
Sat Sep 23 13:18:43 EDT 2017


https://github.com/python/cpython/commit/aecc08ac3a14a73aa353655bb65ff8d965e935a0
commit: aecc08ac3a14a73aa353655bb65ff8d965e935a0
branch: master
author: Dmitry Chestnykh <dmitry at codingrobots.com>
committer: Benjamin Peterson <benjamin at python.org>
date: 2017-09-23T10:18:40-07:00
summary:

Docs: correct hashlib.blake2 keyed hashing example (bpo-31560)

files:
M Doc/library/hashlib.rst
M Doc/tools/susp-ignored.csv

diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst
index 725dce6fa15..3a27a5b566f 100644
--- a/Doc/library/hashlib.rst
+++ b/Doc/library/hashlib.rst
@@ -510,15 +510,19 @@ to users and later verify them to make sure they weren't tampered with::
     ...     h.update(cookie)
     ...     return h.hexdigest().encode('utf-8')
     >>>
-    >>> cookie = b'user:vatrogasac'
+    >>> def verify(cookie, sig):
+    ...     good_sig = sign(cookie)
+    ...     return compare_digest(good_sig, sig)
+    >>>
+    >>> cookie = b'user-alice'
     >>> sig = sign(cookie)
     >>> print("{0},{1}".format(cookie.decode('utf-8'), sig))
-    user:vatrogasac,349cf904533767ed2d755279a8df84d0
-    >>> compare_digest(cookie, sig)
+    user-alice,b'43b3c982cf697e0c5ab22172d1ca7421'
+    >>> verify(cookie, sig)
     True
-    >>> compare_digest(b'user:policajac', sig)
+    >>> verify(b'user-bob', sig)
     False
-    >>> compare_digest(cookie, b'0102030405060708090a0b0c0d0e0f00')
+    >>> verify(cookie, b'0102030405060708090a0b0c0d0e0f00')
     False
 
 Even though there's a native keyed hashing mode, BLAKE2 can, of course, be used
diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv
index 7f1f9ea1629..2b3ccf3ac60 100644
--- a/Doc/tools/susp-ignored.csv
+++ b/Doc/tools/susp-ignored.csv
@@ -130,9 +130,6 @@ library/exceptions,,:err,err.object[err.start:err.end]
 library/functions,,:step,a[start:stop:step]
 library/functions,,:stop,"a[start:stop, i]"
 library/functions,,:stop,a[start:stop:step]
-library/hashlib,,:vatrogasac,>>> cookie = b'user:vatrogasac'
-library/hashlib,,:vatrogasac,"user:vatrogasac,349cf904533767ed2d755279a8df84d0"
-library/hashlib,,:policajac,">>> compare_digest(b'user:policajac', sig)"
 library/hashlib,,:LEAF,"h00 = blake2b(buf[0:LEAF_SIZE], fanout=FANOUT, depth=DEPTH,"
 library/http.client,,:port,host:port
 library/http.cookies,,`,!#$%&'*+-.^_`|~:



More information about the Python-checkins mailing list