aboutsummaryrefslogtreecommitdiff
path: root/lib/crypto/utils.cpp
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-01-28 21:54:37 +0100
committerTobias Fella <fella@posteo.de>2021-12-01 21:34:52 +0100
commitdd0316ce57bd9256a093d66845e1d40cd9426ba4 (patch)
tree900996974e3bdec3a3ceda2ebdae0377dacc80e4 /lib/crypto/utils.cpp
parent5910689306149cacf3ac644d3ea42e10f889e3fe (diff)
downloadlibquotient-dd0316ce57bd9256a093d66845e1d40cd9426ba4.tar.gz
libquotient-dd0316ce57bd9256a093d66845e1d40cd9426ba4.zip
Move files
Diffstat (limited to 'lib/crypto/utils.cpp')
-rw-r--r--lib/crypto/utils.cpp26
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