[issue39298] add BLAKE3 to hashlib
Larry Hastings
report at bugs.python.org
Tue Mar 22 08:36:05 EDT 2022
Larry Hastings <larry at hastings.org> added the comment:
Jack: I've updated the PR, improving compatibility with the "blake3" package on PyPI. I took your notes, and also looked at the C module you wrote.
The resulting commit is here:
https://github.com/python/cpython/pull/31686/commits/37ce72b0444ad63fd1989ad36be5f7790e51f4f1
Specifically:
* derive_key_context is now a string, which I internally encode into UTF-8.
* I added the AUTO member to the module, set to -1.
* max_threads may not be zero; it can be >= 1 or AUTO.
* I added the reset() method.
Some additional thoughts, both on what I did and on what you did:
* In your new() method, your error string says "keys must be 32 bytes". I went with "key must be exactly 32 bytes"; the name of the parameter is "key", and I think "exactly" makes the message clearer.
* In my new() method, I complain if the derive_key_context is zero-length. In your opinion, is that a good idea, or is that overly fussy?
* In your copy() method, you hard-code Blake3Type. It's considered good form to use type(self) here, in case the user is calling copy on a user-created subclass of Blake3Type.
* In your copy() method, if the original has a lock created, you create a lock in the copy too. I'm not sure why you bother; I leave the lock member uninitialized, and let the existing logic create the lock in the copy on demand.
* In the Blake3_methods array, you list the "update" method twice. I suspect this is totally harmless, but it's unnecessary.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39298>
_______________________________________
More information about the Python-bugs-list
mailing list