2016-02-16 17:38:44 +02:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
struct Key
|
|
|
|
|
{
|
|
|
|
|
std::string name;
|
|
|
|
|
std::string key;
|
|
|
|
|
|
|
|
|
|
/* Construct Key from a string in the format
|
2016-11-26 01:37:43 +02:00
|
|
|
|
‘<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
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
2016-11-26 01:37:43 +02:00
|
|
|
|
/* Return true iff ‘sig’ is a correct signature over ‘data’ using one
|
2016-02-16 17:38:44 +02:00
|
|
|
|
of the given public keys. */
|
|
|
|
|
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
|
|
|
|
}
|