-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
It would be very helpful if the finalize() method of a hash would also accept data. This would make it very easy to calculate a hash of some known data in one statement.
Currently you have to use something like:
digester = hashes.Hash(hashes.SHA256())
digester.update(data)
hash = digester.finalize()
With that small change it could be reduced to:
hash = hashes.Hash(hashes.SHA256()).finalize(data)
This will be equally simple than the standard library hashlib:
hash = hashlib.sha256(data).digest()
Possible alternatives would be:
- Adding a data parameter to the constructor like so:
hash = hashes.Hash(hashes.SHA256(), data).finalize() - Adding a classmethod to the
hashes.HashAlgorithmsubclasses like so:hash = hashes.SHA256.digest(data)
From my POV all of them are equally acceptable. I can not evaluate which is the simplest to implement.