pts-database: Update reference file measurements as hex and not binary

This ensures consistent behavior for inserts and updates.
This commit is contained in:
Tobias Brunner
2026-07-24 08:47:37 +02:00
parent 4be1883303
commit ca4db3c512
+5 -7
View File
@@ -180,9 +180,8 @@ METHOD(pts_database_t, add_file_measurement, bool,
{
enumerator_t *e;
char *name;
uint8_t hash_buf[HASH_SIZE_SHA512];
uint8_t hex_meas_buf[2*HASH_SIZE_SHA512+1], *hex_hash_buf;
chunk_t hash, hex_hash, hex_meas;
chunk_t hex_hash, hex_meas;
int hash_id, fid;
bool success = TRUE;
@@ -253,14 +252,14 @@ METHOD(pts_database_t, add_file_measurement, bool,
if (e->enumerate(e, &hash_id, &hex_hash_buf))
{
hex_hash = chunk_from_str(hex_hash_buf);
hash = chunk_from_hex(hex_hash, hash_buf);
hex_meas = chunk_to_hex(measurement, hex_meas_buf, FALSE);
if (!chunk_equals(measurement, hash))
if (!chunk_equals(hex_hash, hex_meas))
{
/* update hash measurement value */
if (this->db->execute(this->db, &hash_id,
"UPDATE file_hashes SET hash = ? WHERE id = ?",
DB_BLOB, measurement, DB_INT, hash_id) != 1)
DB_TEXT, hex_meas_buf, DB_INT, hash_id) != 1)
{
success = FALSE;
}
@@ -268,8 +267,7 @@ METHOD(pts_database_t, add_file_measurement, bool,
}
else
{
hex_meas = chunk_to_hex(measurement, hex_meas_buf, FALSE);
hex_meas_buf[hex_meas.len] = '\0';
chunk_to_hex(measurement, hex_meas_buf, FALSE);
/* insert hash measurement value */
if (this->db->execute(this->db, &hash_id,