From b8bdef0ad12883d72ced5eb443e6e34a93bbbb91 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 25 Oct 2015 11:09:25 -0400 Subject: Implement deterministic ID For non-encrypted files, determinstic ID generation uses file contents instead of timestamp and file name. At a small runtime cost, this enables generation of the same /ID if the same inputs are converted in the same way multiple times. --- libtests/md5.cc | 18 ++++++++++++++++++ libtests/qtest/md5/md5.out | 8 ++++++++ 2 files changed, 26 insertions(+) (limited to 'libtests') diff --git a/libtests/md5.cc b/libtests/md5.cc index 9c9c8cf1..e88c1d66 100644 --- a/libtests/md5.cc +++ b/libtests/md5.cc @@ -45,6 +45,13 @@ int main(int, char*[]) Pl_Discard d; Pl_MD5 p("MD5", &d); + // Create a second pipeline, protect against finish, and call + // getHexDigest only once at the end of both passes. Make sure the + // checksum is that of the input file concatenated to itself. This + // will require changes to Pl_MD5.cc to prevent finish from + // calling finalize. + Pl_MD5 p2("MD5", &d); + p2.persistAcrossFinish(true); for (int i = 0; i < 2; ++i) { FILE* f = QUtil::safe_fopen("md5.in", "rb"); @@ -61,12 +68,23 @@ int main(int, char*[]) else { p.write(buf, len); + p2.write(buf, len); + if (i == 1) + { + // Partial digest -- resets after each call to write + std::cout << p.getHexDigest() << std::endl; + } } } fclose(f); p.finish(); + p2.finish(); + // Make sure calling getHexDigest twice with no intervening + // writes results in the same result each time. + std::cout << p.getHexDigest() << std::endl; std::cout << p.getHexDigest() << std::endl; } + std::cout << p2.getHexDigest() << std::endl; return 0; } diff --git a/libtests/qtest/md5/md5.out b/libtests/qtest/md5/md5.out index 148b4e66..dec491af 100644 --- a/libtests/qtest/md5/md5.out +++ b/libtests/qtest/md5/md5.out @@ -14,3 +14,11 @@ d174ab98d277d9f5a5611c2c9f419d9f 0 5f4b4321873433daae578f85c72f9e74 5f4b4321873433daae578f85c72f9e74 +41f977636f79cf1bad1b439caa7d627c +c30e03b5536e37306df25489622e13e3 +9dabbd135cc47bb603a94989df37c926 +ce80591b269b749f65c53b71d0be5212 +db5448be0a1e931cbd84654e82063483 +db5448be0a1e931cbd84654e82063483 +db5448be0a1e931cbd84654e82063483 +9833b12b21147bebb2f33d35807049af -- cgit v1.2.3-54-g00ecf