diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-01-28 21:54:37 +0100 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:34:52 +0100 |
commit | dd0316ce57bd9256a093d66845e1d40cd9426ba4 (patch) | |
tree | 900996974e3bdec3a3ceda2ebdae0377dacc80e4 /lib/crypto/utils.cpp | |
parent | 5910689306149cacf3ac644d3ea42e10f889e3fe (diff) | |
download | libquotient-dd0316ce57bd9256a093d66845e1d40cd9426ba4.tar.gz libquotient-dd0316ce57bd9256a093d66845e1d40cd9426ba4.zip |
Move files
Diffstat (limited to 'lib/crypto/utils.cpp')
-rw-r--r-- | lib/crypto/utils.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/crypto/utils.cpp b/lib/crypto/utils.cpp new file mode 100644 index 00000000..cb20abf8 --- /dev/null +++ b/lib/crypto/utils.cpp @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifdef Quotient_E2EE_ENABLED +#include "crypto/utils.h" +#include <QDebug> +#include <openssl/rand.h> + +using namespace Quotient; + +QByteArray Quotient::toKey(const Quotient::PicklingMode &mode) +{ + if (std::holds_alternative<Quotient::Unencrypted>(mode)) { + return ""; + } + return std::get<Quotient::Encrypted>(mode).key; +} + +QByteArray Quotient::getRandom(size_t bufferSize) +{ + QByteArray buffer(bufferSize, '0'); + RAND_bytes(reinterpret_cast<uint8_t *>(buffer.data()), buffer.size()); + return buffer; +} +#endif |