summaryrefslogtreecommitdiff
path: root/src/channel.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-01-27 21:25:39 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-02-05 21:02:08 +0100
commitab86a1f0c3b86050e65fc5b7ac1e88a00f0d228c (patch)
tree24f1b79bc9a90846bca31203b306eb4c60a055c1 /src/channel.h
parentec402bfaa90cdb52276f5ccc2525e799cb4419d7 (diff)
Encrypted channels
Diffstat (limited to 'src/channel.h')
-rw-r--r--src/channel.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/channel.h b/src/channel.h
new file mode 100644
index 0000000..100003c
--- /dev/null
+++ b/src/channel.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <erebos/storage.h>
+
+#include "identity.h"
+
+namespace erebos {
+
+struct ChannelRequestData
+{
+ Ref store(const Storage & st) const;
+ static optional<ChannelRequestData> load(const Ref &);
+
+ const vector<Stored<Signed<IdentityData>>> peers;
+ const Stored<PublicKexKey> key;
+};
+
+typedef Signed<ChannelRequestData> ChannelRequest;
+
+struct ChannelAcceptData
+{
+ Ref store(const Storage & st) const;
+ static optional<ChannelAcceptData> load(const Ref &);
+
+ Stored<class Channel> channel() const;
+
+ const Stored<ChannelRequest> request;
+ const Stored<PublicKexKey> key;
+};
+
+typedef Signed<ChannelAcceptData> ChannelAccept;
+
+class Channel
+{
+public:
+ Channel(const vector<Stored<Signed<IdentityData>>> & peers,
+ vector<uint8_t> && key):
+ peers(peers),
+ key(std::move(key))
+ {}
+
+ Ref store(const Storage & st) const;
+ static optional<Channel> load(const Ref &);
+
+ static Stored<ChannelRequest> generateRequest(const Storage &,
+ const Identity & self, const Identity & peer);
+ static optional<Stored<ChannelAccept>> acceptRequest(const Identity & self,
+ const Identity & peer, const Stored<ChannelRequest> & request);
+
+ vector<uint8_t> encrypt(const vector<uint8_t> &) const;
+ optional<vector<uint8_t>> decrypt(const vector<uint8_t> &) const;
+
+private:
+ const vector<Stored<Signed<IdentityData>>> peers;
+ const vector<uint8_t> key;
+};
+
+}