diff options
author | Jay Berkenbilt <ejb@ql.org> | 2015-10-25 16:09:25 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2015-10-31 23:56:42 +0100 |
commit | b8bdef0ad12883d72ced5eb443e6e34a93bbbb91 (patch) | |
tree | 473250ef5919bba535743c2381b86c64ebe810a8 /libtests/md5.cc | |
parent | 607c39211224e0d3bc2ab7066f16ff4952851ee9 (diff) | |
download | qpdf-b8bdef0ad12883d72ced5eb443e6e34a93bbbb91.tar.zst |
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.
Diffstat (limited to 'libtests/md5.cc')
-rw-r--r-- | libtests/md5.cc | 18 |
1 files changed, 18 insertions, 0 deletions
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; } |