aboutsummaryrefslogtreecommitdiff
path: root/lib/crypto/utils.cpp
blob: cb20abf890b7dfe6f143189658bbe91f249bd8f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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