libfilezilla
Loading...
Searching...
No Matches
signature.hpp
Go to the documentation of this file.
1#ifndef LIBFILEZILLA_SIGNATURE_HEADER
2#define LIBFILEZILLA_SIGNATURE_HEADER
3
10#include "libfilezilla.hpp"
11
12#include <vector>
13#include <string>
14
15namespace fz {
16
22{
23public:
24 enum {
25 key_size = 32
26 };
27
28 explicit operator bool() const {
29 return key_.size() == key_size;
30 }
31
32 bool operator==(public_verification_key const& rhs) const {
33 return key_ == rhs.key_;
34 }
35
36 bool operator!=(public_verification_key const& rhs) const {
37 return !(*this == rhs);
38 }
39
40 bool operator<(public_verification_key const& rhs) const {
41 return key_ < rhs.key_;
42 }
43
44 std::string to_base64() const;
45 static public_verification_key from_base64(std::string_view const& base64);
46
47 std::vector<uint8_t> key_;
48};
49
55{
56public:
57 enum {
58 key_size = 32
59 };
60
63
64 explicit operator bool() const {
65 return key_.size() == key_size;
66 }
67
70
71 std::vector<uint8_t> const& data() const {
72 return key_;
73 }
74
75 std::string to_base64() const; // Keep secret!
76 static private_signing_key from_base64(std::string_view const& base64);
77
78private:
79 std::vector<uint8_t> key_;
80};
81
82enum {
83 signature_size = 64
84};
85
87std::vector<uint8_t> FZ_PUBLIC_SYMBOL sign(std::vector<uint8_t> const& message, private_signing_key const& priv, bool include_message = true);
88std::vector<uint8_t> FZ_PUBLIC_SYMBOL sign(std::string_view const& message, private_signing_key const& priv, bool include_message = true);
89std::vector<uint8_t> FZ_PUBLIC_SYMBOL sign(uint8_t const* message, size_t const size, private_signing_key const& priv, bool include_message = true);
90
92bool FZ_PUBLIC_SYMBOL verify(std::vector<uint8_t> const& message, public_verification_key const& pub);
93bool FZ_PUBLIC_SYMBOL verify(std::string_view const& message, public_verification_key const& pub);
94bool FZ_PUBLIC_SYMBOL verify(uint8_t const* message, size_t const size, public_verification_key const& pub);
95
97bool FZ_PUBLIC_SYMBOL verify(std::vector<uint8_t> const& message, std::vector<uint8_t> const& signature, public_verification_key const& pub);
98bool FZ_PUBLIC_SYMBOL verify(std::string_view const& message, std::string_view const& signature, public_verification_key const& pub);
99bool FZ_PUBLIC_SYMBOL verify(uint8_t const* message, size_t const message_size, uint8_t const* signature, size_t const sig_size, public_verification_key const& pub);
100
101}
102
103#endif
Represents a private key to sign message with using Ed25519.
Definition signature.hpp:55
static private_signing_key generate()
Generates a random private key.
public_verification_key pubkey() const
Gets the public key corresponding to the private key.
Represents a public key to verify messages signed using Ed25519.
Definition signature.hpp:22
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition apply.hpp:17
bool verify(std::vector< uint8_t > const &message, public_verification_key const &pub)
Verify a message with attached signature. Returns true iff it has been signed by the private key corr...
std::vector< uint8_t > sign(std::vector< uint8_t > const &message, private_signing_key const &priv, bool include_message=true)
Returns the message with the signature appended, created using the passed private key.
bool dispatch(event_base const &ev, F &&f)
Dispatch for simple_event<> based events to simple functors.
Definition event_handler.hpp:199
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.