Access and serizalize inner state for Digest
ikrivosheev opened this issue · 2 comments
Hello! Thank you for the great library. I'll to describe what my issue.
Pipeline of work with file is:
- Create file with state
- Upload chunk of bytes <-- it can call multiple time.
- Finalize
State's shared between different process and different requests. I need to store hash inner state into database and then restore it in another process.
I can use this API: decompose. But don't have API to get Sha256VarCore from CtVariableCoreWrapper and Sha256VarCore cannot serialize into bytes.
Simple code:
let mut sha = Sha256::new();
sha2.update(bytes);
let (core, buffer) = sha.decompose();
// Store core and buffer into database
In other process after some time:
// load core and buffer from database
let mut sha = Sha256::from_core(core);
sha.update(buffer.get_data());
sha.update(data);
If we come to a solution, I will be happy to make PR.
Dup of #1369.
This is already supported in the latest sha2
master via the SerializableState
trait: https://github.com/RustCrypto/hashes/blob/0b79171da599c1bd1b9d4bd45f537f217a2375df/sha2/src/core_api.rs#L104-L132
There's not a whole lot in the way of documentation around it though, and I'm not sure it's actually made it into a crate release yet.