|
@@ -992,49 +992,6 @@ window.PrivateBin = (function () {
|
|
|
*/
|
|
*/
|
|
|
const base58 = new baseX('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
|
|
const base58 = new baseX('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * convert UTF-8 string stored in a DOMString to a standard UTF-16 DOMString
|
|
|
|
|
- *
|
|
|
|
|
- * Iterates over the bytes of the message, converting them all hexadecimal
|
|
|
|
|
- * percent encoded representations, then URI decodes them all
|
|
|
|
|
- *
|
|
|
|
|
- * @name CryptTool.utf8To16
|
|
|
|
|
- * @function
|
|
|
|
|
- * @private
|
|
|
|
|
- * @param {string} message UTF-8 string
|
|
|
|
|
- * @return {string} UTF-16 string
|
|
|
|
|
- */
|
|
|
|
|
- function utf8To16(message) {
|
|
|
|
|
- return decodeURIComponent(
|
|
|
|
|
- message.split('').map(
|
|
|
|
|
- function (character) {
|
|
|
|
|
- return '%' + ('00' + character.charCodeAt(0).toString(16)).slice(-2);
|
|
|
|
|
- }
|
|
|
|
|
- ).join('')
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * convert DOMString (UTF-16) to a UTF-8 string stored in a DOMString
|
|
|
|
|
- *
|
|
|
|
|
- * URI encodes the message, then finds the percent encoded characters
|
|
|
|
|
- * and transforms these hexadecimal representation back into bytes
|
|
|
|
|
- *
|
|
|
|
|
- * @name CryptTool.utf16To8
|
|
|
|
|
- * @function
|
|
|
|
|
- * @private
|
|
|
|
|
- * @param {string} message UTF-16 string
|
|
|
|
|
- * @return {string} UTF-8 string
|
|
|
|
|
- */
|
|
|
|
|
- function utf16To8(message) {
|
|
|
|
|
- return encodeURIComponent(message).replace(
|
|
|
|
|
- /%([0-9A-F]{2})/g,
|
|
|
|
|
- function (match, hexCharacter) {
|
|
|
|
|
- return String.fromCharCode('0x' + hexCharacter);
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* convert ArrayBuffer into a UTF-8 string
|
|
* convert ArrayBuffer into a UTF-8 string
|
|
|
*
|
|
*
|
|
@@ -1086,9 +1043,7 @@ window.PrivateBin = (function () {
|
|
|
* @return {ArrayBuffer} data
|
|
* @return {ArrayBuffer} data
|
|
|
*/
|
|
*/
|
|
|
async function compress(message, mode, zlib) {
|
|
async function compress(message, mode, zlib) {
|
|
|
- message = stringToArraybuffer(
|
|
|
|
|
- utf16To8(message)
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ message = new TextEncoder().encode(message);
|
|
|
if (mode === 'zlib') {
|
|
if (mode === 'zlib') {
|
|
|
if (typeof zlib === 'undefined') {
|
|
if (typeof zlib === 'undefined') {
|
|
|
throw new Error('Error compressing document, due to missing WebAssembly support.');
|
|
throw new Error('Error compressing document, due to missing WebAssembly support.');
|
|
@@ -1120,9 +1075,7 @@ window.PrivateBin = (function () {
|
|
|
new Uint8Array(data)
|
|
new Uint8Array(data)
|
|
|
).buffer;
|
|
).buffer;
|
|
|
}
|
|
}
|
|
|
- return utf8To16(
|
|
|
|
|
- arraybufferToString(data)
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ return new TextDecoder('utf-8', {fatal: true}).decode(data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|