aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/crypto.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-01-06 17:04:46 +0100
committerEelco Dolstra <edolstra@gmail.com>2021-01-06 17:04:46 +0100
commit555152ffe8494190ca42dd481991c9b54759f686 (patch)
tree2f4a5615c5b704ee950c6e5f81c3b1116740d2bb /src/libstore/crypto.hh
parent146af4ee9bb03968a7322a1ac70dc60c8d5a35e2 (diff)
crypto.cc: API cleanup and add generate() / to_string() methods
Diffstat (limited to 'src/libstore/crypto.hh')
-rw-r--r--src/libstore/crypto.hh24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/libstore/crypto.hh b/src/libstore/crypto.hh
index 9110af3aa..03f85c103 100644
--- a/src/libstore/crypto.hh
+++ b/src/libstore/crypto.hh
@@ -13,32 +13,40 @@ struct Key
/* Construct Key from a string in the format
‘<name>:<key-in-base64>’. */
- Key(const std::string & s);
+ Key(std::string_view s);
+
+ std::string to_string() const;
protected:
- Key(const std::string & name, const std::string & key)
- : name(name), key(key) { }
+ Key(std::string_view name, std::string && key)
+ : name(name), key(std::move(key)) { }
};
struct PublicKey;
struct SecretKey : Key
{
- SecretKey(const std::string & s);
+ SecretKey(std::string_view s);
/* Return a detached signature of the given string. */
- std::string signDetached(const std::string & s) const;
+ std::string signDetached(std::string_view s) const;
PublicKey toPublicKey() const;
+
+ static SecretKey generate(std::string_view name);
+
+private:
+ SecretKey(std::string_view name, std::string && key)
+ : Key(name, std::move(key)) { }
};
struct PublicKey : Key
{
- PublicKey(const std::string & data);
+ PublicKey(std::string_view data);
private:
- PublicKey(const std::string & name, const std::string & key)
- : Key(name, key) { }
+ PublicKey(std::string_view name, std::string && key)
+ : Key(name, std::move(key)) { }
friend struct SecretKey;
};