mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-12 09:11:37 -04:00
Moved quotedprintable to own library, completed a little work on IMF parsing
This commit is contained in:
parent
7ae0b08b4d
commit
ed17ed2919
3 changed files with 45 additions and 24 deletions
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import {decodeQuotedPrintable} from "../lib/QuotedPrintable"
|
||||
|
||||
/**
|
||||
* From Quoted Printable operation
|
||||
|
@ -43,25 +44,7 @@ class FromQuotedPrintable extends Operation {
|
|||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
const str = input.replace(/=(?:\r?\n|$)/g, "");
|
||||
|
||||
const encodedBytesCount = (str.match(/=[\da-fA-F]{2}/g) || []).length,
|
||||
bufferLength = str.length - encodedBytesCount * 2,
|
||||
buffer = new Array(bufferLength);
|
||||
let chr, hex,
|
||||
bufferPos = 0;
|
||||
|
||||
for (let i = 0, len = str.length; i < len; i++) {
|
||||
chr = str.charAt(i);
|
||||
if (chr === "=" && (hex = str.substr(i + 1, 2)) && /[\da-fA-F]{2}/.test(hex)) {
|
||||
buffer[bufferPos++] = parseInt(hex, 16);
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
buffer[bufferPos++] = chr.charCodeAt(0);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return decodeQuotedPrintable(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue