aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2015-10-25 16:09:25 +0100
committerJay Berkenbilt <ejb@ql.org>2015-10-31 23:56:42 +0100
commitb8bdef0ad12883d72ced5eb443e6e34a93bbbb91 (patch)
tree473250ef5919bba535743c2381b86c64ebe810a8 /libtests
parent607c39211224e0d3bc2ab7066f16ff4952851ee9 (diff)
downloadqpdf-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')
-rw-r--r--libtests/md5.cc18
-rw-r--r--libtests/qtest/md5/md5.out8
2 files changed, 26 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;
}
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