mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-12-04 06:01:26 +09:00
* feat: add awg3.1 support * fix: add warning for big native awg qr codes * fix: show default subnet address if not exist in server config * fix: use range keep alive only with awg3 params * chore: update awg go versions in conan * chore: update awg-go version
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include "qrCodeUtils.h"
|
|
|
|
#include <cmath>
|
|
|
|
#include <QDataStream>
|
|
#include <QIODevice>
|
|
#include <QList>
|
|
|
|
QList<QString> qrCodeUtils::generateQrCodeImageSeries(const QByteArray &data)
|
|
{
|
|
double k = 850;
|
|
|
|
quint8 chunksCount = std::ceil(data.size() / k);
|
|
QList<QString> chunks;
|
|
for (int i = 0; i < data.size(); i = i + k) {
|
|
QByteArray chunk;
|
|
QDataStream s(&chunk, QIODevice::WriteOnly);
|
|
s << qrCodeUtils::qrMagicCode << chunksCount << (quint8)std::round(i / k) << data.mid(i, k);
|
|
|
|
QByteArray ba = chunk.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
|
|
|
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(ba.constData(), qrcodegen::QrCode::Ecc::LOW);
|
|
QString svg = QString::fromStdString(toSvgString(qr, 1));
|
|
chunks.append(svgToBase64(svg));
|
|
}
|
|
|
|
return chunks;
|
|
}
|
|
|
|
QString qrCodeUtils::generatePlainQrCodeImage(const QByteArray &data)
|
|
{
|
|
try {
|
|
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(data.constData(), qrcodegen::QrCode::Ecc::LOW);
|
|
QString svg = QString::fromStdString(toSvgString(qr, 1));
|
|
return svgToBase64(svg);
|
|
} catch (const qrcodegen::data_too_long &) {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
QString qrCodeUtils::svgToBase64(const QString &image)
|
|
{
|
|
return "data:image/svg;base64," + QString::fromLatin1(image.toUtf8().toBase64().data());
|
|
}
|
|
|
|
qrcodegen::QrCode qrCodeUtils::generateQrCode(const QByteArray &data)
|
|
{
|
|
return qrcodegen::QrCode::encodeText(data.constData(), qrcodegen::QrCode::Ecc::LOW);
|
|
}
|