Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Open
Description
Feature or enhancement
hashlib describes a Protocol for hash objects without implementing it.
The proposal is simply to create a concreateHash
orHashObject
protocol that makes it explicit.
Pitch
Using theBuffer Protocol (PEP 688) this should look something like
@runtime_checkableclassHash(Protocol):name:strdefdigest_size(self)->int:"""Return the size of the hash in bytes."""defblock_size(self)->int:"""Return the internal block size of the hash in bytes."""defupdate(self,data:Buffer)->None:"""Update this hash object's state with the provided string."""defdigest(self)->bytes:"""Return the digest value as a string of binary data."""defhexdigest(self)->str:"""Return the digest value as a string of hexadecimal digits."""defcopy(self)->Self:"""Return a copy ("clone") of the hash object."""
Having aProtocol
class instead of prose makes it clear how exactly a hash-function needs to look like.
A second suggestion would be to changehashlib.algorithms_guaranteed
and hashlib.algorithms_available
fromset[str]
todict[str, type[Hash]]
objects.