#pragma once #include #include #include #include #include "json.hpp" #include "expiring_signature.h" #include "time_helpers.h" namespace BareMinimumCrypto { using namespace std; using nlohmann::json; string get_machine_id (); struct HumanKeyFile { vector salt; Instant time_created; vector pubkey; string machine_id; vector to_msgpack () const; static optional try_from_msgpack (const json & msg); }; struct MachineKeyFile { vector secretkey; Instant time_created; string machine_id; vector to_msgpack () const; static optional try_from_msgpack (const json & msg); vector pubkey () const; }; struct SigningKey { vector pk; vector sk; SigningKey (); // This doesn't fsync, so it's possible to lose the key due to a power outage // or filesystem nonsense right after this function returns. // It also doesn't do the rename trick. The caller may do that. static optional generate_human_key_file (const string & file_path, const string & passphrase); static optional generate_machine_key_file (const string & file_path); static optional load_human_key_file (const string & file_path, const string & passphrase); vector pubkey () const; vector pub_to_msgpack () const; optional sign ( const vector & payload, TimeRange tr ) const; optional sign_key (const SigningKey & k, Instant now) const; optional sign_data (const vector & v, Instant now) const; }; }