diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-01-23 21:46:26 +0100 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:34:52 +0100 |
commit | c8d67f737e84bbec98a54fc19a8aa56dbc39d542 (patch) | |
tree | 094704820b91f7f31bbb0562e2e01f3f1fd2a311 /lib/olm/qolmaccount.h | |
parent | e2075a1f33f7987385fc61338ce1756715fdaf6a (diff) | |
download | libquotient-c8d67f737e84bbec98a54fc19a8aa56dbc39d542.tar.gz libquotient-c8d67f737e84bbec98a54fc19a8aa56dbc39d542.zip |
Implement Inboundsession
Diffstat (limited to 'lib/olm/qolmaccount.h')
-rw-r--r-- | lib/olm/qolmaccount.h | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/lib/olm/qolmaccount.h b/lib/olm/qolmaccount.h index 268cd5d5..3ce1fb9a 100644 --- a/lib/olm/qolmaccount.h +++ b/lib/olm/qolmaccount.h @@ -3,44 +3,14 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #pragma once -#include <QObject> -#include <QMap> -#include <optional> -#include <string> -#include <variant> +#include "olm/e2ee.h" +#include "olm/errors.h" #include "olm/olm.h" +#include <QObject> struct OlmAccount; -struct Unencrypted {}; -struct Encrypted { - QByteArray key; -}; - -using PicklingMode = std::variant<Unencrypted, Encrypted>; - -template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; }; -template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>; - -struct IdentityKeys -{ - QByteArray curve25519; - QByteArray ed25519; -}; - -//! Struct representing the the one-time keys. -struct OneTimeKeys -{ - QMap<QString, QMap<QString, QString>> keys; - - //! Get the HashMap containing the curve25519 one-time keys. - QMap<QString, QString> curve25519() const; - - //! Get a reference to the hashmap corresponding to given key type. - std::optional<QMap<QString, QString>> get(QString keyType) const; -}; - -bool operator==(const IdentityKeys& lhs, const IdentityKeys& rhs); +namespace Quotient { //! An olm account manages all cryptographic keys used on a device. //! \code{.cpp} @@ -51,41 +21,34 @@ class QOlmAccount public: ~QOlmAccount(); - enum OlmAccountError { - BadAccountKey, - BadMessageKeyId, - InvalidBase64, - NotEnoughRandom, - OutputBufferTooSmall, - Unknown, - }; - //! Creates a new instance of OlmAccount. During the instantiation //! the Ed25519 fingerprint key pair and the Curve25519 identity key //! pair are generated. For more information see <a //! href="https://matrix.org/docs/guides/e2e_implementation.html#keys-used-in-end-to-end-encryption">here</a>. static std::optional<QOlmAccount> create(); - static std::variant<QOlmAccount, OlmAccountError> unpickle(QByteArray picked, PicklingMode mode); + static std::variant<QOlmAccount, OlmError> unpickle(QByteArray &picked, const PicklingMode &mode); //! Serialises an OlmAccount to encrypted Base64. - std::variant<QByteArray, OlmAccountError> pickle(PicklingMode mode); - std::variant<IdentityKeys, OlmAccountError> identityKeys(); + std::variant<QByteArray, OlmError> pickle(const PicklingMode &mode); + std::variant<IdentityKeys, OlmError> identityKeys(); //! Returns the signature of the supplied message. - std::variant<QString, OlmAccountError> sign(QString message) const; + std::variant<QString, OlmError> sign(const QString &message) const; //! Maximum number of one time keys that this OlmAccount can //! currently hold. size_t maxNumberOfOneTimeKeys() const; //! Generates the supplied number of one time keys. - std::optional<OlmAccountError> generateOneTimeKeys(size_t numberOfKeys) const; + std::optional<OlmError> generateOneTimeKeys(size_t numberOfKeys) const; //! Gets the OlmAccount's one time keys formatted as JSON. - std::variant<OneTimeKeys, OlmAccountError> oneTimeKeys() const; + std::variant<OneTimeKeys, OlmError> oneTimeKeys() const; // HACK do not use directly QOlmAccount(OlmAccount *account); private: OlmAccount *m_account; }; + +} // namespace Quotient |