summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorsww <sww@users.noreply.github.com>2017-09-14 06:24:36 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2017-09-14 06:24:36 (GMT)
commit312ffead1eb272535e021e248b5d74ab04b2e72e (patch)
treeaa426347465b2ccaac22d3e0d5f19ffe271337d4 /Doc
parentc3e97d9d984130d1c2aceedc4dfcd603b3162688 (diff)
downloadcpython-312ffead1eb272535e021e248b5d74ab04b2e72e.zip
cpython-312ffead1eb272535e021e248b5d74ab04b2e72e.tar.gz
cpython-312ffead1eb272535e021e248b5d74ab04b2e72e.tar.bz2
Improve code examples in hashlib cookie signing (GH-3562)
The `blake2b` function does not take the `data` keyword argument. The hex digest returned by sign was a string, whereas compare_digest expects bytes-like objects. Typo fix: compare_digesty -> compare_digest
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/hashlib.rst7
1 files changed, 4 insertions, 3 deletions
diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst
index 9d56356..725dce6 100644
--- a/Doc/library/hashlib.rst
+++ b/Doc/library/hashlib.rst
@@ -506,8 +506,9 @@ to users and later verify them to make sure they weren't tampered with::
>>> AUTH_SIZE = 16
>>>
>>> def sign(cookie):
- ... h = blake2b(data=cookie, digest_size=AUTH_SIZE, key=SECRET_KEY)
- ... return h.hexdigest()
+ ... h = blake2b(digest_size=AUTH_SIZE, key=SECRET_KEY)
+ ... h.update(cookie)
+ ... return h.hexdigest().encode('utf-8')
>>>
>>> cookie = b'user:vatrogasac'
>>> sig = sign(cookie)
@@ -517,7 +518,7 @@ to users and later verify them to make sure they weren't tampered with::
True
>>> compare_digest(b'user:policajac', sig)
False
- >>> compare_digesty(cookie, '0102030405060708090a0b0c0d0e0f00')
+ >>> compare_digest(cookie, b'0102030405060708090a0b0c0d0e0f00')
False
Even though there's a native keyed hashing mode, BLAKE2 can, of course, be used