2016-02-16 15:38:44 +00:00
|
|
|
|
#pragma once
|
2023-04-01 03:18:41 +00:00
|
|
|
|
///@file
|
2016-02-16 15:38:44 +00:00
|
|
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
struct Key
|
|
|
|
|
{
|
|
|
|
|
std::string name;
|
|
|
|
|
std::string key;
|
|
|
|
|
|
2023-04-07 13:55:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* Construct Key from a string in the format
|
|
|
|
|
* ‘<name>:<key-in-base64>’.
|
|
|
|
|
*/
|
2021-01-06 16:04:46 +00:00
|
|
|
|
Key(std::string_view s);
|
|
|
|
|
|
|
|
|
|
std::string to_string() const;
|
2016-02-16 15:38:44 +00:00
|
|
|
|
|
2016-03-04 16:08:30 +00:00
|
|
|
|
protected:
|
2021-01-06 16:04:46 +00:00
|
|
|
|
Key(std::string_view name, std::string && key)
|
|
|
|
|
: name(name), key(std::move(key)) { }
|
2016-02-16 15:38:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-03-04 16:08:30 +00:00
|
|
|
|
struct PublicKey;
|
|
|
|
|
|
2016-02-16 15:38:44 +00:00
|
|
|
|
struct SecretKey : Key
|
|
|
|
|
{
|
2021-01-06 16:04:46 +00:00
|
|
|
|
SecretKey(std::string_view s);
|
2016-02-16 15:38:44 +00:00
|
|
|
|
|
2023-04-07 13:55:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return a detached signature of the given string.
|
|
|
|
|
*/
|
2021-01-06 16:04:46 +00:00
|
|
|
|
std::string signDetached(std::string_view s) const;
|
2016-03-04 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
PublicKey toPublicKey() const;
|
2021-01-06 16:04:46 +00:00
|
|
|
|
|
|
|
|
|
static SecretKey generate(std::string_view name);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SecretKey(std::string_view name, std::string && key)
|
|
|
|
|
: Key(name, std::move(key)) { }
|
2016-02-16 15:38:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PublicKey : Key
|
|
|
|
|
{
|
2021-01-06 16:04:46 +00:00
|
|
|
|
PublicKey(std::string_view data);
|
2016-03-04 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2021-01-06 16:04:46 +00:00
|
|
|
|
PublicKey(std::string_view name, std::string && key)
|
|
|
|
|
: Key(name, std::move(key)) { }
|
2016-03-15 11:11:27 +00:00
|
|
|
|
friend struct SecretKey;
|
2016-02-16 15:38:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string, PublicKey> PublicKeys;
|
|
|
|
|
|
2023-04-07 13:55:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return true iff ‘sig’ is a correct signature over ‘data’ using one
|
|
|
|
|
* of the given public keys.
|
|
|
|
|
*/
|
2016-02-16 15:38:44 +00:00
|
|
|
|
bool verifyDetached(const std::string & data, const std::string & sig,
|
|
|
|
|
const PublicKeys & publicKeys);
|
|
|
|
|
|
2016-03-29 12:29:50 +00:00
|
|
|
|
PublicKeys getDefaultPublicKeys();
|
|
|
|
|
|
2016-02-16 15:38:44 +00:00
|
|
|
|
}
|