Task #1934
closedProvide stateful digest
Description
Digest may be calculated in two ways: 1) calculate a digest on a determined input; 2) update the digest with dynamic input.
For now, ndn-cxx only supports the first style. Given digest may be widely used in NDN applications, it might be useful to support both styles (e.g., the second style is needed by ChronoSync based applications).
The second style can be abstracted as a StatefulDigest
which can be continuously updated until a finalize
call is made. A pseudo code should look like:
StatefulDigest digest;
digest.update(input1, size1);
digest.update(input2, size2);
digest.update(input3, size3);
...
ConstBufferPtr result = digest.getDigest();
Updated by Junxiao Shi about 10 years ago
- Start date deleted (
08/25/2014)
It's better to avoid the term finalize
in this context.
The usual meaning of a finalize
method is to free resources (similar to a destructor).
I suggest following Python hashlib API:
partial class StatefulDigest
{
/** \brief append a block of input
*/
void update(const void* input, size_t size);
/** \brief compute digest on input
*
* This can be invoked after zero or more .update() calls.
* .update() is not allowed after .computeDigest() is called.
*/
ConstBufferPtr computeDigest();
/** \brief clear input and digest
*
* After this call, the object is same as a newly constructed object.
*/
void reset();
};
Updated by Yingdi Yu about 10 years ago
Actually, finalize is not necessary, it is implicitly called in getDigest(), I will hide it from public interface.
Updated by Alex Afanasyev about 10 years ago
I wouldn't call it "StatefulDigest". It is standard way how digest is calculated, so I would name it simply "Digest". It could have a static member to get digest from a single memory block.
Updated by Alex Afanasyev about 10 years ago
- Status changed from Code review to Closed