aboutsummaryrefslogtreecommitdiff
path: root/lib/e2ee/qolmutils.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/qolmutils.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/qolmutils.cpp')
-rw-r--r--lib/e2ee/qolmutils.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/e2ee/qolmutils.cpp b/lib/e2ee/qolmutils.cpp
index 6f7937e8..c6e51bcd 100644
--- a/lib/e2ee/qolmutils.cpp
+++ b/lib/e2ee/qolmutils.cpp
@@ -15,9 +15,8 @@ QByteArray Quotient::toKey(const Quotient::PicklingMode &mode)
return std::get<Quotient::Encrypted>(mode).key;
}
-QByteArray Quotient::getRandom(size_t bufferSize)
+RandomBuffer::RandomBuffer(size_t size)
+ : QByteArray(static_cast<int>(size), '\0')
{
- QByteArray buffer(bufferSize, '0');
- QRandomGenerator::system()->generate(buffer.begin(), buffer.end());
- return buffer;
+ QRandomGenerator::system()->generate(begin(), end());
}