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/events | |
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/events')
-rw-r--r-- | lib/events/filesourceinfo.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/events/filesourceinfo.cpp b/lib/events/filesourceinfo.cpp index 6abe6a08..a60d86d2 100644 --- a/lib/events/filesourceinfo.cpp +++ b/lib/events/filesourceinfo.cpp @@ -59,19 +59,17 @@ std::pair<EncryptedFileMetadata, QByteArray> Quotient::encryptFile( const QByteArray& plainText) { #ifdef Quotient_E2EE_ENABLED - auto k = getRandom(32); + auto k = RandomBuffer(32); auto kBase64 = k.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); - auto iv = getRandom(16); + auto iv = RandomBuffer(16); JWK key = { "oct"_ls, { "encrypt"_ls, "decrypt"_ls }, "A256CTR"_ls, kBase64, true }; int length = -1; auto* ctx = EVP_CIPHER_CTX_new(); - EVP_EncryptInit_ex(ctx, EVP_aes_256_ctr(), nullptr, - reinterpret_cast<const unsigned char*>(k.data()), - reinterpret_cast<const unsigned char*>(iv.data())); + EVP_EncryptInit_ex(ctx, EVP_aes_256_ctr(), nullptr, k.bytes(), iv.bytes()); const auto blockSize = EVP_CIPHER_CTX_block_size(ctx); QByteArray cipherText(plainText.size() + blockSize - 1, '\0'); EVP_EncryptUpdate(ctx, reinterpret_cast<unsigned char*>(cipherText.data()), |