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