Replaced png library in backend
This commit is contained in:
@@ -5,14 +5,14 @@
|
||||
#include <botan/base32.h>
|
||||
#include <botan/base64.h>
|
||||
#include <qrcodegen.hpp>
|
||||
#include <png++/png.hpp>
|
||||
#include <lodepng.h>
|
||||
|
||||
#include "controllers/controllers.h"
|
||||
#include "db/db.h"
|
||||
#include "dto/dto.h"
|
||||
|
||||
std::string create_totp_qrcode(const db::User& user, const std::string& b32_secret) {
|
||||
const int qrcode_pixel_size = 4;
|
||||
constexpr int qrcode_pixel_size = 4;
|
||||
|
||||
std::stringstream code_ss;
|
||||
code_ss << "otpauth://totp/MFileserver:"
|
||||
@@ -22,6 +22,23 @@ std::string create_totp_qrcode(const db::User& user, const std::string& b32_secr
|
||||
<< "&issuer=MFileserver";
|
||||
auto code = qrcodegen::QrCode::encodeText(code_ss.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
|
||||
const int mod_count = code.getSize();
|
||||
|
||||
const int row_size = qrcode_pixel_size * mod_count;
|
||||
std::vector<uint8_t> secret, image, row;
|
||||
row.reserve(row_size);
|
||||
image.reserve(row_size * row_size);
|
||||
|
||||
for (int y = 0; y < mod_count; y++) {
|
||||
row.clear();
|
||||
for (int x = 0; x < mod_count; x++)
|
||||
row.insert(row.end(), qrcode_pixel_size, code.getModule(x, y) ? 0 : 0xff);
|
||||
for (int i = 0; i < qrcode_pixel_size; i++)
|
||||
image.insert(image.end(), row.begin(), row.end());
|
||||
}
|
||||
|
||||
lodepng::encode(secret, image, row_size, row_size, LCT_GREY, 8);
|
||||
|
||||
/*
|
||||
png::image<png::gray_pixel> image(mod_count*qrcode_pixel_size, mod_count*qrcode_pixel_size);
|
||||
for (int x = 0; x < mod_count; x++) for (int y = 0; y < mod_count; y++) {
|
||||
const bool mod = code.getModule(x, y);
|
||||
@@ -34,7 +51,7 @@ std::string create_totp_qrcode(const db::User& user, const std::string& b32_secr
|
||||
|
||||
std::string image_str = image_ss.str();
|
||||
std::vector<uint8_t> secret(image_str.data(), image_str.data()+image_str.size());
|
||||
|
||||
*/
|
||||
return "data:image/png;base64," + Botan::base64_encode(secret);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user