aboutsummaryrefslogtreecommitdiff
path: root/lib/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/qolmaccount.cpp16
-rw-r--r--lib/crypto/qolmaccount.h7
-rw-r--r--lib/crypto/qolmerrors.cpp1
-rw-r--r--lib/crypto/qolminboundsession.cpp8
-rw-r--r--lib/crypto/qolmoutboundsession.cpp8
-rw-r--r--lib/crypto/qolmoutboundsession.h5
-rw-r--r--lib/crypto/qolmutility.h4
7 files changed, 24 insertions, 25 deletions
diff --git a/lib/crypto/qolmaccount.cpp b/lib/crypto/qolmaccount.cpp
index 4f007e2f..8b964c9f 100644
--- a/lib/crypto/qolmaccount.cpp
+++ b/lib/crypto/qolmaccount.cpp
@@ -151,9 +151,9 @@ size_t QOlmAccount::maxNumberOfOneTimeKeys() const
size_t 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);
- const auto error = olm_account_generate_one_time_keys(m_account, numberOfKeys, randomBuffer.data(), randomLen);
+ const size_t randomLength = olm_account_generate_one_time_keys_random_length(m_account, numberOfKeys);
+ QByteArray randomBuffer = getRandom(randomLength);
+ const auto error = olm_account_generate_one_time_keys(m_account, numberOfKeys, randomBuffer.data(), randomLength);
if (error == olm_error()) {
throw lastError(m_account);
@@ -219,12 +219,12 @@ std::optional<QOlmError> QOlmAccount::removeOneTimeKeys(const std::unique_ptr<QO
return std::nullopt;
}
-OlmAccount *Quotient::QOlmAccount::data()
+OlmAccount *QOlmAccount::data()
{
return m_account;
}
-DeviceKeys QOlmAccount::getDeviceKeys() const
+DeviceKeys QOlmAccount::deviceKeys() const
{
DeviceKeys deviceKeys;
deviceKeys.userId = m_userId;
@@ -243,7 +243,7 @@ DeviceKeys QOlmAccount::getDeviceKeys() const
UploadKeysJob *QOlmAccount::createUploadKeyRequest(const OneTimeKeys &oneTimeKeys)
{
- auto deviceKeys = getDeviceKeys();
+ auto deviceKeys = deviceKeys();
if (oneTimeKeys.curve25519().isEmpty()) {
return new UploadKeysJob(deviceKeys);
@@ -253,9 +253,7 @@ UploadKeysJob *QOlmAccount::createUploadKeyRequest(const OneTimeKeys &oneTimeKey
auto temp = signOneTimeKeys(oneTimeKeys);
QHash<QString, QVariant> oneTimeKeysSigned;
for (const auto &[keyId, key] : asKeyValueRange(temp)) {
- QVariant keyVar;
- keyVar.setValue(key);
- oneTimeKeysSigned[keyId] = keyVar;
+ oneTimeKeysSigned[keyId] = QVariant::fromValue(key);
}
return new UploadKeysJob(deviceKeys, oneTimeKeysSigned);
diff --git a/lib/crypto/qolmaccount.h b/lib/crypto/qolmaccount.h
index 1e198687..c93a8354 100644
--- a/lib/crypto/qolmaccount.h
+++ b/lib/crypto/qolmaccount.h
@@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later
+
#pragma once
#include "csapi/keys.h"
@@ -37,7 +38,7 @@ public:
//! Deserialises from encrypted Base64 that was previously obtained by pickling a `QOlmAccount`.
//! This needs to be called before any other action or use createNewAccount() instead.
- void unpickle(QByteArray &picked, const PicklingMode &mode);
+ void unpickle(QByteArray &pickled, const PicklingMode &mode);
//! Serialises an OlmAccount to encrypted Base64.
std::variant<QByteArray, QOlmError> pickle(const PicklingMode &mode);
@@ -62,7 +63,7 @@ public:
//! Gets the OlmAccount's one time keys formatted as JSON.
OneTimeKeys oneTimeKeys() const;
- //! Sign all time key.
+ //! Sign all one time keys.
QMap<QString, SignedOneTimeKey> signOneTimeKeys(const OneTimeKeys &keys) const;
//! Sign one time key.
@@ -84,7 +85,7 @@ public:
//! Creates an inbound session for sending/receiving messages from a received 'prekey' message.
//!
- //! \param theirIdentityKey - The identity key of an Olm account that
+ //! \param theirIdentityKey - The identity key of the Olm account that
//! encrypted this Olm message.
std::variant<std::unique_ptr<QOlmSession>, QOlmError> createInboundSessionFrom(const QByteArray &theirIdentityKey, const QOlmMessage &preKeyMessage);
diff --git a/lib/crypto/qolmerrors.cpp b/lib/crypto/qolmerrors.cpp
index 46b2618c..2c3926de 100644
--- a/lib/crypto/qolmerrors.cpp
+++ b/lib/crypto/qolmerrors.cpp
@@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later
+
#include "qolmerrors.h"
Quotient::QOlmError Quotient::fromString(const std::string &error_raw) {
diff --git a/lib/crypto/qolminboundsession.cpp b/lib/crypto/qolminboundsession.cpp
index e1ced72b..beaf3299 100644
--- a/lib/crypto/qolminboundsession.cpp
+++ b/lib/crypto/qolminboundsession.cpp
@@ -10,7 +10,6 @@ using namespace Quotient;
QOlmError lastError(OlmInboundGroupSession *session) {
const std::string error_raw = olm_inbound_group_session_last_error(session);
- std::cout << error_raw;
return fromString(error_raw);
}
@@ -39,7 +38,6 @@ std::unique_ptr<QOlmInboundGroupSession> QOlmInboundGroupSession::create(const Q
return std::make_unique<QOlmInboundGroupSession>(olmInboundGroupSession);
}
-
std::unique_ptr<QOlmInboundGroupSession> QOlmInboundGroupSession::import(const QByteArray &key)
{
const auto olmInboundGroupSession = olm_inbound_group_session(new uint8_t[olm_inbound_group_session_size()]);
@@ -123,9 +121,9 @@ std::variant<std::pair<QString, uint32_t>, QOlmError> QOlmInboundGroupSession::d
std::variant<QByteArray, QOlmError> QOlmInboundGroupSession::exportSession(uint32_t messageIndex)
{
- const auto keyLen = olm_export_inbound_group_session_length(m_groupSession);
- QByteArray keyBuf(keyLen, '0');
- const auto error = olm_export_inbound_group_session(m_groupSession, reinterpret_cast<uint8_t *>(keyBuf.data()), keyLen, messageIndex);
+ const auto keyLength = olm_export_inbound_group_session_length(m_groupSession);
+ QByteArray keyBuf(keyLength, '0');
+ const auto error = olm_export_inbound_group_session(m_groupSession, reinterpret_cast<uint8_t *>(keyBuf.data()), keyLength, messageIndex);
if (error == olm_error()) {
return lastError(m_groupSession);
diff --git a/lib/crypto/qolmoutboundsession.cpp b/lib/crypto/qolmoutboundsession.cpp
index bf8dce61..bc572ba5 100644
--- a/lib/crypto/qolmoutboundsession.cpp
+++ b/lib/crypto/qolmoutboundsession.cpp
@@ -27,8 +27,8 @@ QOlmOutboundGroupSession::~QOlmOutboundGroupSession()
std::unique_ptr<QOlmOutboundGroupSession> QOlmOutboundGroupSession::create()
{
auto *olmOutboundGroupSession = olm_outbound_group_session(new uint8_t[olm_outbound_group_session_size()]);
- const auto randomLen = olm_init_outbound_group_session_random_length(olmOutboundGroupSession);
- QByteArray randomBuf = getRandom(randomLen);
+ const auto randomLength = olm_init_outbound_group_session_random_length(olmOutboundGroupSession);
+ QByteArray randomBuf = getRandom(randomLength);
const auto error = olm_init_outbound_group_session(olmOutboundGroupSession,
reinterpret_cast<uint8_t *>(randomBuf.data()), randomBuf.length());
@@ -86,8 +86,8 @@ std::variant<std::unique_ptr<QOlmOutboundGroupSession>, QOlmError> QOlmOutboundG
std::variant<QByteArray, QOlmError> QOlmOutboundGroupSession::encrypt(const QString &plaintext)
{
QByteArray plaintextBuf = plaintext.toUtf8();
- const auto messageMaxLen = olm_group_encrypt_message_length(m_groupSession, plaintextBuf.length());
- QByteArray messageBuf(messageMaxLen, '0');
+ const auto messageMaxLength = olm_group_encrypt_message_length(m_groupSession, plaintextBuf.length());
+ QByteArray messageBuf(messageMaxLength, '0');
const auto error = olm_group_encrypt(m_groupSession, reinterpret_cast<uint8_t *>(plaintextBuf.data()),
plaintextBuf.length(), reinterpret_cast<uint8_t *>(messageBuf.data()), messageBuf.length());
diff --git a/lib/crypto/qolmoutboundsession.h b/lib/crypto/qolmoutboundsession.h
index f1df0395..201a178a 100644
--- a/lib/crypto/qolmoutboundsession.h
+++ b/lib/crypto/qolmoutboundsession.h
@@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later
+
#pragma once
#include "olm/olm.h"
@@ -21,11 +22,11 @@ public:
//! Creates a new instance of `QOlmOutboundGroupSession`.
//! Throw OlmError on errors
static std::unique_ptr<QOlmOutboundGroupSession> create();
- //! Serialises an `QOlmOutboundGroupSession` to encrypted Base64.
+ //! Serialises a `QOlmOutboundGroupSession` to encrypted Base64.
std::variant<QByteArray, QOlmError> pickle(const PicklingMode &mode);
//! Deserialises from encrypted Base64 that was previously obtained by
//! pickling a `QOlmOutboundGroupSession`.
- static std::variant<std::unique_ptr<QOlmOutboundGroupSession>, QOlmError> unpickle(QByteArray &pickled, const PicklingMode &mode);
+ static std::variant<std::unique_ptr<QOlmOutboundGroupSession>, QOlmError> unpickle(const QByteArray &pickled, const PicklingMode &mode);
//! Encrypts a plaintext message using the session.
std::variant<QByteArray, QOlmError> encrypt(const QString &plaintext);
diff --git a/lib/crypto/qolmutility.h b/lib/crypto/qolmutility.h
index fc6569f7..5fd28dcc 100644
--- a/lib/crypto/qolmutility.h
+++ b/lib/crypto/qolmutility.h
@@ -27,11 +27,11 @@ public:
QString sha256Bytes(const QByteArray &inputBuf) const;
//! Convenience function that converts the UTF-8 message
- //! to bytes and then calls `sha256_bytes()`, returning its output.
+ //! to bytes and then calls `sha256Bytes()`, returning its output.
QString sha256Utf8Msg(const QString &message) const;
//! Verify a ed25519 signature.
- //! \param any QByteArray The public part of the ed25519 key that signed the message.
+ //! \param key QByteArray The public part of the ed25519 key that signed the message.
//! \param message QByteArray The message that was signed.
//! \param signature QByteArray The signature of the message.
std::variant<bool, QOlmError> ed25519Verify(const QByteArray &key,