1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/17010] Clean up code and move some functions to core js

PHPBB3-17010
This commit is contained in:
Marc Alexander
2023-06-24 09:40:35 +02:00
parent 7410c3be6f
commit 3cbe14eb4a
2 changed files with 38 additions and 24 deletions

View File

@@ -1677,6 +1677,33 @@ phpbb.getFunctionByName = function (functionName) {
return context[func];
};
/**
* Convert raw key ArrayBuffer to base64 string.
*
* @param {ArrayBuffer} rawKey Raw key array buffer as exported by SubtleCrypto exportKey()
* @returns {string} Base64 encoded raw key string
*/
phpbb.rawKeyToBase64 = (rawKey) => {
const keyBuffer = new Uint8Array(rawKey);
let keyText = '';
const keyLength = keyBuffer.byteLength;
for (let i = 0; i < keyLength; i++) {
keyText += String.fromCharCode(keyBuffer[i]);
}
return window.btoa(keyText);
};
/**
* Base64URL encode base64 encoded string
*
* @param {string} base64String Base64 encoded string
* @returns {string} Base64URL encoded string
*/
phpbb.base64UrlEncode = (base64String) => {
return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
};
/**
* Register page dropdowns.
*/