Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aecc08a

Browse files
dchestbenjaminp
authored andcommitted
Docs: correct hashlib.blake2 keyed hashing example (bpo-31560)
1 parent c8a6e5b commit aecc08a

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Doc/library/hashlib.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,19 @@ to users and later verify them to make sure they weren't tampered with::
510510
... h.update(cookie)
511511
... return h.hexdigest().encode('utf-8')
512512
>>>
513-
>>> cookie = b'user:vatrogasac'
513+
>>> def verify(cookie, sig):
514+
... good_sig = sign(cookie)
515+
... return compare_digest(good_sig, sig)
516+
>>>
517+
>>> cookie = b'user-alice'
514518
>>> sig = sign(cookie)
515519
>>> print("{0},{1}".format(cookie.decode('utf-8'), sig))
516-
user:vatrogasac,349cf904533767ed2d755279a8df84d0
517-
>>> compare_digest(cookie, sig)
520+
user-alice,b'43b3c982cf697e0c5ab22172d1ca7421'
521+
>>> verify(cookie, sig)
518522
True
519-
>>> compare_digest(b'user:policajac', sig)
523+
>>> verify(b'user-bob', sig)
520524
False
521-
>>> compare_digest(cookie, b'0102030405060708090a0b0c0d0e0f00')
525+
>>> verify(cookie, b'0102030405060708090a0b0c0d0e0f00')
522526
False
523527

524528
Even though there's a native keyed hashing mode, BLAKE2 can, of course, be used

Doc/tools/susp-ignored.csv

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ library/exceptions,,:err,err.object[err.start:err.end]
130130
library/functions,,:step,a[start:stop:step]
131131
library/functions,,:stop,"a[start:stop, i]"
132132
library/functions,,:stop,a[start:stop:step]
133-
library/hashlib,,:vatrogasac,>>> cookie = b'user:vatrogasac'
134-
library/hashlib,,:vatrogasac,"user:vatrogasac,349cf904533767ed2d755279a8df84d0"
135-
library/hashlib,,:policajac,">>> compare_digest(b'user:policajac', sig)"
136133
library/hashlib,,:LEAF,"h00 = blake2b(buf[0:LEAF_SIZE], fanout=FANOUT, depth=DEPTH,"
137134
library/http.client,,:port,host:port
138135
library/http.cookies,,`,!#$%&'*+-.^_`|~:

0 commit comments

Comments
 (0)