From aed2f3f29165bf1695f90015118fe8dcd27f7cc2 Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 16 Sep 2024 16:44:09 +0100 Subject: [PATCH] ProfileCache: Include type in checksum calculation The goal here is to eventually be able to recompute a checksum for the whole profile to verify integrity, this requires the checksums to include type so that alteration or corruption of type can be detected. N.B. \x1e is the record separator character, used here to delimit the value and type. --- src/main/perl/Fetch/ProfileCache.pm | 2 +- src/test/perl/cli.t | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/perl/Fetch/ProfileCache.pm b/src/main/perl/Fetch/ProfileCache.pm index ca12f2e..d325c97 100644 --- a/src/main/perl/Fetch/ProfileCache.pm +++ b/src/main/perl/Fetch/ProfileCache.pm @@ -411,7 +411,7 @@ sub ComputeChecksum unless (defined $value) { return md5_hex("__"); } - return md5_hex(encode_utf8($value)); + return md5_hex(encode_utf8("$value\x1e$type")); } } diff --git a/src/test/perl/cli.t b/src/test/perl/cli.t index fe3db5d..d980dd7 100644 --- a/src/test/perl/cli.t +++ b/src/test/perl/cli.t @@ -79,10 +79,10 @@ like($txt, "dumpdb output path2eid"); # \0 separated list of subpaths like($txt, - qr{eid2data:\n0 => a\0c\0e\n10000000 => nlist\n20000000 => 1740877ebcb53b5132e75cff986cd705\n1 => b}m, + qr{eid2data:\n0 => a\0c\0e\n10000000 => nlist\n20000000 => 3ee8d50d6f70735cfd53d9ea92215a22\n1 => b}m, "dumpdb output eid2data"); like($txt, - qr{path2eid and eid2data combined:\n/ \(0\) =>\n V: a\0c\0e\n T: nlist\n C: 1740877ebcb53b5132e75cff986cd705\n/a \(1\) =>\n}, + qr{path2eid and eid2data combined:\n/ \(0\) =>\n V: a\0c\0e\n T: nlist\n C: 3ee8d50d6f70735cfd53d9ea92215a22\n/a \(1\) =>\n}, "dumpdb ouptut combined path2eid eid2data"); diag $txt;