summaryrefslogtreecommitdiffstats
path: root/Doc/library/hashlib.rst
diff options
context:
space:
mode:
authorDmitry Chestnykh <dmitry@codingrobots.com>2017-09-23 17:18:40 (GMT)
committerBenjamin Peterson <benjamin@python.org>2017-09-23 17:18:40 (GMT)
commitaecc08ac3a14a73aa353655bb65ff8d965e935a0 (patch)
treeac2b996898bd59c06657347c90541f73713a0f4e /Doc/library/hashlib.rst
parentc8a6e5b18d3c3df04c17ed7761e34487971c82ff (diff)
downloadcpython-aecc08ac3a14a73aa353655bb65ff8d965e935a0.zip
cpython-aecc08ac3a14a73aa353655bb65ff8d965e935a0.tar.gz
cpython-aecc08ac3a14a73aa353655bb65ff8d965e935a0.tar.bz2
Docs: correct hashlib.blake2 keyed hashing example (bpo-31560)
Diffstat (limited to 'Doc/library/hashlib.rst')
-rw-r--r--Doc/library/hashlib.rst14
1 files changed, 9 insertions, 5 deletions
diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst
index 725dce6..3a27a5b 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