Persisting hashlib state
Posted
by anthony
on Stack Overflow
See other posts from Stack Overflow
or by anthony
Published on 2010-01-25T07:54:24Z
Indexed on
2010/04/05
15:03 UTC
Read the original article
Hit count: 330
I'd like to create a hashlib instance, update() it, then persist its state in some way. Later, I'd like to recreate the object using this state data, and continue to update() it. Finally, I'd like to get the hexdigest() o the total cumulative run of data. State persistence has to survive across multiple runs.
Example:
import hashlib
m = hashlib.sha1()
m.update('one')
m.update('two')
# somehow, persist the state of m here
#later, possibly in another process
# recreate m from the persisted state
m.update('three')
m.update('four')
print m.hexdigest()
# at this point, m.hexdigest() should be equal to hashlib.sha1().update('onetwothreefour').hextdigets()
© Stack Overflow or respective owner