fwt_software/include/fgc/Hash.h

26 lines
993 B
C++

#pragma once
#include <cstdint>
#include <string>
namespace fgc {
// FNV-1a 64-bit, for detecting that a file changed.
//
// Deliberately not a cryptographic hash: the only question asked of it is "is
// this the same settings XML the record was generated from?", which is change
// detection, not tamper resistance. A crypto dependency would be a poor trade
// for that, and this is ten lines that need no third party.
//
// Digests are rendered with an algorithm prefix ("fnv1a64:<16 hex digits>") so a
// stored digest can never be silently misread if the algorithm is ever changed.
uint64_t fnv1a64(const std::string& data);
std::string hashLabel(uint64_t digest); // -> "fnv1a64:9d3c1a77b21e4f80"
// Hash a file's bytes. Throws std::runtime_error if it cannot be read - callers
// use this to decide whether to regenerate, so silently returning 0 would make a
// missing file look like an unchanged one.
uint64_t fnv1a64File(const std::string& path);
} // namespace fgc