2
0
mirror of https://github.com/gchq/CyberChef synced 2025-12-18 09:13:43 +00:00

Move parsing and generation of QR codes to lib folder.

Also rewrote QR code parsing to be more readable and actually error out properly.
This commit is contained in:
j433866
2019-03-07 13:21:26 +00:00
parent 8148c1a8a8
commit 21a8d03201
3 changed files with 96 additions and 80 deletions

View File

@@ -6,7 +6,7 @@
import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import qr from "qr-image";
import { generateQrCode } from "../lib/QRCode";
import { toBase64 } from "../lib/Base64";
import Magic from "../lib/Magic";
import Utils from "../Utils";
@@ -62,29 +62,7 @@ class GenerateQRCode extends Operation {
run(input, args) {
const [format, size, margin, errorCorrection] = args;
// Create new QR image from the input data, and convert it to a buffer
const qrImage = qr.imageSync(input, {
type: format,
size: size,
margin: margin,
"ec_level": errorCorrection.charAt(0).toUpperCase()
});
if (qrImage == null) {
throw new OperationError("Error generating QR code.");
}
switch (format) {
case "SVG":
case "EPS":
case "PDF":
return [...Buffer.from(qrImage)];
case "PNG":
// Return the QR image buffer as a byte array
return [...qrImage];
default:
throw new OperationError("Unsupported QR code format.");
}
return generateQrCode(input, format, size, margin, errorCorrection);
}
/**