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.cpp | |
parent | e2075a1f33f7987385fc61338ce1756715fdaf6a (diff) | |
download | libquotient-c8d67f737e84bbec98a54fc19a8aa56dbc39d542.tar.gz libquotient-c8d67f737e84bbec98a54fc19a8aa56dbc39d542.zip |
Implement Inboundsession
Diffstat (limited to 'lib/olm/qolmaccount.cpp')
-rw-r--r-- | lib/olm/qolmaccount.cpp | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/olm/qolmaccount.cpp b/lib/olm/qolmaccount.cpp index a6a07962..bde9b712 100644 --- a/lib/olm/qolmaccount.cpp +++ b/lib/olm/qolmaccount.cpp @@ -9,6 +9,8 @@ #include <QDebug> #include <iostream> +using namespace Quotient; + QMap<QString, QString> OneTimeKeys::curve25519() const { return keys[QStringLiteral("curve25519")]; @@ -23,7 +25,7 @@ std::optional<QMap<QString, QString>> OneTimeKeys::get(QString keyType) const } // Convert PicklingMode to key -QByteArray toKey(PicklingMode mode) +QByteArray toKey(const PicklingMode &mode) { if (std::holds_alternative<Unencrypted>(mode)) { return ""; @@ -36,25 +38,30 @@ bool operator==(const IdentityKeys& lhs, const IdentityKeys& rhs) return lhs.curve25519 == rhs.curve25519 &&& lhs.ed25519 == rhs.ed25519; } -// Conver olm error to enum -QOlmAccount::OlmAccountError lastError(OlmAccount *account) { - const std::string error_raw = olm_account_last_error(account); - +// TODO use impl from errors.cpp +OlmError fromString(const std::string &error_raw) { if (error_raw.compare("BAD_ACCOUNT_KEY")) { - return QOlmAccount::OlmAccountError::BadAccountKey; + return OlmError::BadAccountKey; } else if (error_raw.compare("BAD_MESSAGE_KEY_ID")) { - return QOlmAccount::OlmAccountError::BadMessageKeyId; + return OlmError::BadMessageKeyId; } else if (error_raw.compare("INVALID_BASE64")) { - return QOlmAccount::OlmAccountError::InvalidBase64; + return OlmError::InvalidBase64; } else if (error_raw.compare("NOT_ENOUGH_RANDOM")) { - return QOlmAccount::OlmAccountError::NotEnoughRandom; + return OlmError::NotEnoughRandom; } else if (error_raw.compare("OUTPUT_BUFFER_TOO_SMALL")) { - return QOlmAccount::OlmAccountError::OutputBufferTooSmall; + return OlmError::OutputBufferTooSmall; } else { - return QOlmAccount::OlmAccountError::Unknown; + return OlmError::Unknown; } } +// Conver olm error to enum +OlmError lastError(OlmAccount *account) { + const std::string error_raw = olm_account_last_error(account); + + return fromString(error_raw); +} + QByteArray getRandom(size_t bufferSize) { QByteArray buffer(bufferSize, '0'); @@ -83,7 +90,7 @@ std::optional<QOlmAccount> QOlmAccount::create() return std::make_optional<QOlmAccount>(account); } -std::variant<QOlmAccount, QOlmAccount::OlmAccountError> QOlmAccount::unpickle(QByteArray pickled, PicklingMode mode) +std::variant<QOlmAccount, OlmError> QOlmAccount::unpickle(QByteArray &pickled, const PicklingMode &mode) { auto account = olm_account(new uint8_t[olm_account_size()]); const QByteArray key = toKey(mode); @@ -94,7 +101,7 @@ std::variant<QOlmAccount, QOlmAccount::OlmAccountError> QOlmAccount::unpickle(QB return QOlmAccount(account); } -std::variant<QByteArray, QOlmAccount::OlmAccountError> QOlmAccount::pickle(PicklingMode mode) +std::variant<QByteArray, OlmError> QOlmAccount::pickle(const PicklingMode &mode) { const QByteArray key = toKey(mode); const size_t pickleLength = olm_pickle_account_length(m_account); @@ -107,7 +114,7 @@ std::variant<QByteArray, QOlmAccount::OlmAccountError> QOlmAccount::pickle(Pickl return pickleBuffer; } -std::variant<IdentityKeys, QOlmAccount::OlmAccountError> QOlmAccount::identityKeys() +std::variant<IdentityKeys, OlmError> QOlmAccount::identityKeys() { const size_t keyLength = olm_account_identity_keys_length(m_account); QByteArray keyBuffer(keyLength, '0'); @@ -122,7 +129,7 @@ std::variant<IdentityKeys, QOlmAccount::OlmAccountError> QOlmAccount::identityKe }; } -std::variant<QString, QOlmAccount::OlmAccountError> QOlmAccount::sign(QString message) const +std::variant<QString, OlmError> QOlmAccount::sign(const QString &message) const { const size_t signatureLength = olm_account_signature_length(m_account); QByteArray signatureBuffer(signatureLength, '0'); @@ -140,7 +147,7 @@ size_t QOlmAccount::maxNumberOfOneTimeKeys() const return olm_account_max_number_of_one_time_keys(m_account); } -std::optional<QOlmAccount::OlmAccountError> QOlmAccount::generateOneTimeKeys(size_t numberOfKeys) const +std::optional<OlmError> QOlmAccount::generateOneTimeKeys(size_t numberOfKeys) const { const size_t randomLen = olm_account_generate_one_time_keys_random_length(m_account, numberOfKeys); QByteArray randomBuffer = getRandom(randomLen); @@ -152,7 +159,7 @@ std::optional<QOlmAccount::OlmAccountError> QOlmAccount::generateOneTimeKeys(siz return std::nullopt; } -std::variant<OneTimeKeys, QOlmAccount::OlmAccountError> QOlmAccount::oneTimeKeys() const +std::variant<OneTimeKeys, OlmError> QOlmAccount::oneTimeKeys() const { const size_t oneTimeKeyLength = olm_account_one_time_keys_length(m_account); QByteArray oneTimeKeysBuffer(oneTimeKeyLength, '0'); |