2016-02-16 16:38:44 +01: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
|
|
|
|
|
‘<name>:<key-in-base64>’. */
|
|
|
|
|
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. */
|
|
|
|
|
std::string signDetached(const std::string & s) const;
|
2016-03-04 17:08:30 +01:00
|
|
|
|
|
|
|
|
|
PublicKey toPublicKey() const;
|
2016-02-16 16:38:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PublicKey : Key
|
|
|
|
|
{
|
|
|
|
|
PublicKey(const std::string & data);
|
2016-03-04 17:08:30 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PublicKey(const std::string & name, const std::string & key)
|
|
|
|
|
: Key(name, key) { }
|
|
|
|
|
friend class SecretKey;
|
2016-02-16 16:38:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string, PublicKey> PublicKeys;
|
|
|
|
|
|
|
|
|
|
/* Return true iff ‘sig’ is a correct signature over ‘data’ using one
|
|
|
|
|
of the given public keys. */
|
|
|
|
|
bool verifyDetached(const std::string & data, const std::string & sig,
|
|
|
|
|
const PublicKeys & publicKeys);
|
|
|
|
|
|
|
|
|
|
}
|