2016-02-16 16:38:44 +01:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <map>
|
2020-05-19 16:54:39 +02:00
|
|
|
|
|
2020-05-27 22:56:34 +02:00
|
|
|
|
#include "libutil/types.hh"
|
2016-02-16 16:38:44 +01:00
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
struct Key {
|
|
|
|
|
std::string name;
|
|
|
|
|
std::string key;
|
|
|
|
|
|
|
|
|
|
/* Construct Key from a string in the format
|
2016-11-26 00:37:43 +01:00
|
|
|
|
‘<name>:<key-in-base64>’. */
|
2016-02-16 16:38:44 +01:00
|
|
|
|
Key(const std::string& s);
|
|
|
|
|
|
2016-03-04 17:08:30 +01:00
|
|
|
|
protected:
|
|
|
|
|
Key(const std::string& name, const std::string& key) : name(name), key(key) {}
|
2016-02-16 16:38:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
2016-03-04 17:08:30 +01:00
|
|
|
|
struct PublicKey;
|
|
|
|
|
|
2016-02-16 16:38:44 +01:00
|
|
|
|
struct SecretKey : Key {
|
|
|
|
|
SecretKey(const std::string& s);
|
|
|
|
|
|
|
|
|
|
/* Return a detached signature of the given string. */
|
2020-05-20 23:27:37 +02:00
|
|
|
|
std::string signDetached(const std::string& data) const;
|
2016-03-04 17:08:30 +01:00
|
|
|
|
|
|
|
|
|
PublicKey toPublicKey() const;
|
2016-02-16 16:38:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PublicKey : Key {
|
2020-05-20 23:27:37 +02:00
|
|
|
|
PublicKey(const std::string& s);
|
2016-03-04 17:08:30 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PublicKey(const std::string& name, const std::string& key) : Key(name, key) {}
|
2016-03-15 12:11:27 +01:00
|
|
|
|
friend struct SecretKey;
|
2016-02-16 16:38:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string, PublicKey> PublicKeys;
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
/* Return true iff ‘sig’ is a correct signature over ‘data’ using one
|
2016-02-16 16:38:44 +01:00
|
|
|
|
of the given public keys. */
|
|
|
|
|
bool verifyDetached(const std::string& data, const std::string& sig,
|
|
|
|
|
const PublicKeys& publicKeys);
|
|
|
|
|
|
2016-03-29 14:29:50 +02:00
|
|
|
|
PublicKeys getDefaultPublicKeys();
|
|
|
|
|
|
2016-02-16 16:38:44 +01:00
|
|
|
|
} // namespace nix
|