aboutsummaryrefslogtreecommitdiff
path: root/lib/e2ee/qolmoutboundsession.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-09-21 16:11:39 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-09-26 10:46:34 +0200
commitbc1ded73bedf593acda80b00eb7da32f688c4843 (patch)
tree48867f314c028cdf4ddb17d72ef964f5f5954b89 /lib/e2ee/qolmoutboundsession.cpp
parentbcc05aa1d52cae2b6d8e70bb6cf04fa49904687a (diff)
downloadlibquotient-bc1ded73bedf593acda80b00eb7da32f688c4843.tar.gz
libquotient-bc1ded73bedf593acda80b00eb7da32f688c4843.zip
RandomBuffer
A convenient abstraction swallowing all the type casts and, more importantly, cleanup on destruction (previous code only cleaned up the buffer upon a successful call to Olm API but not upon an error).
Diffstat (limited to 'lib/e2ee/qolmoutboundsession.cpp')
-rw-r--r--lib/e2ee/qolmoutboundsession.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/e2ee/qolmoutboundsession.cpp b/lib/e2ee/qolmoutboundsession.cpp
index 22107a21..3d176274 100644
--- a/lib/e2ee/qolmoutboundsession.cpp
+++ b/lib/e2ee/qolmoutboundsession.cpp
@@ -34,11 +34,10 @@ QOlmOutboundGroupSessionPtr QOlmOutboundGroupSession::create()
{
auto *olmOutboundGroupSession = olm_outbound_group_session(new uint8_t[olm_outbound_group_session_size()]);
const auto randomLength = olm_init_outbound_group_session_random_length(olmOutboundGroupSession);
- QByteArray randomBuf = getRandom(randomLength);
- if (olm_init_outbound_group_session(
- olmOutboundGroupSession,
- reinterpret_cast<uint8_t*>(randomBuf.data()), randomBuf.length())
+ if (olm_init_outbound_group_session(olmOutboundGroupSession,
+ RandomBuffer(randomLength).bytes(),
+ randomLength)
== olm_error()) {
// FIXME: create the session object earlier and use lastError()
throw olm_outbound_group_session_last_error_code(olmOutboundGroupSession);
@@ -50,8 +49,6 @@ QOlmOutboundGroupSessionPtr QOlmOutboundGroupSession::create()
olm_outbound_group_session_key(olmOutboundGroupSession, reinterpret_cast<uint8_t *>(keyBuffer.data()),
keyMaxLength);
- randomBuf.clear();
-
return std::make_unique<QOlmOutboundGroupSession>(olmOutboundGroupSession);
}