fingerprint.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #ifndef REALM_ENCRYPT_FINGERPRINT_HPP
  2. #define REALM_ENCRYPT_FINGERPRINT_HPP
  3. #include <string>
  4. #include <array>
  5. #include <realm/util/optional.hpp>
  6. namespace realm {
  7. namespace encrypt {
  8. // calculate_fingerprint() calculates, and returns, a fingerprint of an
  9. // encryption key. The input key can be util::none in order to calculate a
  10. // fingerprint even in the case of unencrypted Realms.
  11. //
  12. // An intruder cannot recover an unknown encryption_key from the fingerprint,
  13. // and it is safe to save the fingerprint in a file together with the encrypted
  14. // Realms.
  15. //
  16. // calculate_fingerprint() can be considered opaque, but currently the
  17. // fingerprint is a colon separated hex representation of the SHA-256 hash of
  18. // the encryption key.
  19. std::string calculate_fingerprint(const util::Optional<std::array<char, 64>> encryption_key);
  20. // verify_fingerprint() returns true if `fingerprint` was obtained previously
  21. // from calculate_fingerprint() with `encryption_key` as argument. Otherwise,
  22. // verify_fingerprint() returns false with extremely high probability.
  23. bool verify_fingerprint(const std::string& fingerprint, const util::Optional<std::array<char, 64>> encryption_key);
  24. } // namespace encrypt
  25. } // namespace realm
  26. #endif // REALM_ENCRYPT_FINGERPRINT_HPP