diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-09-21 16:11:39 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-09-26 10:46:34 +0200 |
commit | bc1ded73bedf593acda80b00eb7da32f688c4843 (patch) | |
tree | 48867f314c028cdf4ddb17d72ef964f5f5954b89 /lib/e2ee/qolmutils.cpp | |
parent | bcc05aa1d52cae2b6d8e70bb6cf04fa49904687a (diff) | |
download | libquotient-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.cpp | 7 |
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()); } |