aboutsummaryrefslogtreecommitdiff
path: root/lib/crypto/qolmutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto/qolmutils.cpp')
-rw-r--r--lib/crypto/qolmutils.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/crypto/qolmutils.cpp b/lib/crypto/qolmutils.cpp
new file mode 100644
index 00000000..a486ea0f
--- /dev/null
+++ b/lib/crypto/qolmutils.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/qolmutils.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