| 1 | #pragma once |
| 2 | |
| 3 | #include <mls/common.h> |
| 4 | #include <mls/core_types.h> |
| 5 | #include <mls/credential.h> |
| 6 | #include <mls/crypto.h> |
| 7 | #include <mls/state.h> |
| 8 | |
| 9 | namespace mlspp { |
| 10 | |
| 11 | class PendingJoin; |
| 12 | class Session; |
| 13 | |
| 14 | class Client |
| 15 | { |
| 16 | public: |
| 17 | Client(CipherSuite suite_in, |
| 18 | SignaturePrivateKey sig_priv_in, |
| 19 | Credential cred_in); |
| 20 | |
| 21 | Session begin_session(const bytes& group_id) const; |
| 22 | |
| 23 | PendingJoin start_join() const; |
| 24 | |
| 25 | private: |
| 26 | const CipherSuite suite; |
| 27 | const SignaturePrivateKey sig_priv; |
| 28 | const Credential cred; |
| 29 | }; |
| 30 | |
| 31 | class PendingJoin |
| 32 | { |
| 33 | public: |
| 34 | PendingJoin(PendingJoin&& other) noexcept; |
| 35 | PendingJoin& operator=(PendingJoin&& other) noexcept; |
| 36 | ~PendingJoin(); |
| 37 | bytes key_package() const; |
| 38 | Session complete(const bytes& welcome) const; |
| 39 | |
| 40 | private: |
| 41 | struct Inner; |
| 42 | std::unique_ptr<Inner> inner; |
| 43 | |
| 44 | PendingJoin(Inner* inner); |
| 45 | friend class Client; |
| 46 | }; |
| 47 | |
| 48 | class Session |
| 49 | { |
| 50 | public: |
| 51 | Session(Session&& other) noexcept; |
| 52 | Session& operator=(Session&& other) noexcept; |
| 53 | ~Session(); |
| 54 | |
| 55 | // Settings |
| 56 | void encrypt_handshake(bool enabled); |
| 57 | |
| 58 | // Message producers |
| 59 | bytes add(const bytes& key_package_data); |
| 60 | bytes update(); |
| 61 | bytes remove(uint32_t index); |
| 62 | std::tuple<bytes, bytes> commit(const bytes& proposal); |
| 63 | std::tuple<bytes, bytes> commit(const std::vector<bytes>& proposals); |
| 64 | std::tuple<bytes, bytes> commit(); |
| 65 | |
| 66 | // Message consumers |
| 67 | bool handle(const bytes& handshake_data); |
| 68 | |
| 69 | // Information about the current state |
| 70 | epoch_t epoch() const; |
| 71 | LeafIndex index() const; |
| 72 | CipherSuite cipher_suite() const; |
| 73 | const ExtensionList& extensions() const; |
| 74 | const TreeKEMPublicKey& tree() const; |
| 75 | bytes do_export(const std::string& label, |
| 76 | const bytes& context, |
| 77 | size_t size) const; |
| 78 | GroupInfo group_info() const; |
| 79 | std::vector<LeafNode> roster() const; |
| 80 | bytes epoch_authenticator() const; |
| 81 | |
| 82 | // Application message protection |
| 83 | bytes protect(const bytes& plaintext); |
| 84 | bytes unprotect(const bytes& ciphertext); |
| 85 | |
| 86 | protected: |
| 87 | struct Inner; |
| 88 | std::unique_ptr<Inner> inner; |
| 89 | |
| 90 | Session(Inner* inner); |
| 91 | friend class Client; |
| 92 | friend class PendingJoin; |
| 93 | |
| 94 | friend bool operator==(const Session& lhs, const Session& rhs); |
| 95 | friend bool operator!=(const Session& lhs, const Session& rhs); |
| 96 | }; |
| 97 | |
| 98 | } // namespace mlspp |