2021-01-18 22:57:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <stdint.h>
|
2021-01-19 22:52:02 +00:00
|
|
|
#include <string>
|
2021-01-18 22:57:33 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "expiring_signature.h"
|
|
|
|
#include "time_helpers.h"
|
|
|
|
|
|
|
|
namespace BareMinimumCrypto {
|
|
|
|
using namespace std;
|
|
|
|
|
2021-01-19 23:01:17 +00:00
|
|
|
struct SigningKeyFile {
|
|
|
|
vector <uint8_t> salt;
|
|
|
|
Instant time_created;
|
|
|
|
vector <uint8_t> pubkey;
|
|
|
|
|
|
|
|
vector <uint8_t> to_msgpack () const;
|
|
|
|
static optional <SigningKeyFile> try_from_msgpack (const vector <uint8_t> & msg);
|
|
|
|
};
|
|
|
|
|
2021-01-19 22:52:02 +00:00
|
|
|
struct SigningKey {
|
2021-01-18 22:57:33 +00:00
|
|
|
vector <uint8_t> pk;
|
|
|
|
vector <uint8_t> sk;
|
|
|
|
|
|
|
|
SigningKey ();
|
|
|
|
|
2021-01-19 22:52:02 +00:00
|
|
|
// 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 <SigningKey> generate_to_file (const string & file_path, const string & passphrase);
|
|
|
|
|
|
|
|
static optional <SigningKey> load_from_file (const string & file_path, const string & passphrase);
|
2021-01-19 02:41:05 +00:00
|
|
|
|
2021-01-19 23:01:17 +00:00
|
|
|
static optional <SigningKeyFile> check_file (const string & file_path);
|
|
|
|
|
2021-01-18 22:57:33 +00:00
|
|
|
vector <uint8_t> pubkey () const;
|
|
|
|
vector <uint8_t> pub_to_msgpack () const;
|
|
|
|
|
|
|
|
optional <ExpiringSignature> sign (
|
|
|
|
const vector <uint8_t> & payload,
|
|
|
|
TimeRange tr
|
|
|
|
) const;
|
|
|
|
|
|
|
|
optional <ExpiringSignature> sign_key (const SigningKey & k, Instant now) const;
|
|
|
|
optional <ExpiringSignature> sign_data (const vector <uint8_t> & v, Instant now) const;
|
|
|
|
};
|
|
|
|
}
|