♻️ refactor: splitting into in-mem and on-disk formats, for 'check key' cmd
parent
7b11633015
commit
ce3342d961
|
@ -9,6 +9,15 @@
|
||||||
namespace BareMinimumCrypto {
|
namespace BareMinimumCrypto {
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
vector <uint8_t> SigningKeyFile::to_msgpack () const {
|
||||||
|
const auto j = json {
|
||||||
|
{"salt", json::binary (salt)},
|
||||||
|
{"time_created", time_created.x},
|
||||||
|
{"pubkey", json::binary (pubkey)},
|
||||||
|
};
|
||||||
|
return json::to_msgpack (j);
|
||||||
|
}
|
||||||
|
|
||||||
// The whole process for a passphrased key is like this:
|
// The whole process for a passphrased key is like this:
|
||||||
// Passphrase + random salt -->
|
// Passphrase + random salt -->
|
||||||
// Seed -->
|
// Seed -->
|
||||||
|
@ -46,12 +55,12 @@ namespace BareMinimumCrypto {
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto j = json {
|
SigningKeyFile key_on_disk {
|
||||||
{"salt", json::binary (salt)},
|
salt,
|
||||||
{"time_created", Instant::now ().x},
|
Instant::now (),
|
||||||
{"pubkey", json::binary (key.pk)},
|
key.pk
|
||||||
};
|
};
|
||||||
const auto msg = json::to_msgpack (j);
|
const auto msg = key_on_disk.to_msgpack ();
|
||||||
|
|
||||||
ofstream f;
|
ofstream f;
|
||||||
f.open (file_path, ofstream::binary);
|
f.open (file_path, ofstream::binary);
|
||||||
|
|
|
@ -11,6 +11,15 @@
|
||||||
namespace BareMinimumCrypto {
|
namespace BareMinimumCrypto {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
struct SigningKey {
|
struct SigningKey {
|
||||||
vector <uint8_t> pk;
|
vector <uint8_t> pk;
|
||||||
vector <uint8_t> sk;
|
vector <uint8_t> sk;
|
||||||
|
@ -25,6 +34,8 @@ namespace BareMinimumCrypto {
|
||||||
|
|
||||||
static optional <SigningKey> load_from_file (const string & file_path, const string & passphrase);
|
static optional <SigningKey> load_from_file (const string & file_path, const string & passphrase);
|
||||||
|
|
||||||
|
static optional <SigningKeyFile> check_file (const string & file_path);
|
||||||
|
|
||||||
vector <uint8_t> pubkey () const;
|
vector <uint8_t> pubkey () const;
|
||||||
vector <uint8_t> pub_to_msgpack () const;
|
vector <uint8_t> pub_to_msgpack () const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue