X-Git-Url: http://git.squeep.com/?p=squeep-mystery-box;a=blobdiff_plain;f=lib%2Fcommon.js;h=4c7e6392fe1f7e6f28a9321680d56fbf933404cb;hp=a47226f6e76fe355416380f3a77db24450481783;hb=b9782b5dfca21a6da610eebf8bd7207f10256fbf;hpb=66aef7be7b8e05e9ea0de1a904e1f66a86006e6d diff --git a/lib/common.js b/lib/common.js index a47226f..4c7e639 100644 --- a/lib/common.js +++ b/lib/common.js @@ -19,56 +19,7 @@ const fileScope = (filename) => { } -/** - * Convert Base64 to Base64URL. - * @param {String} input - * @returns {String} - */ -const base64ToBase64URL = (input) => { - if (!input) { - return input; - } - return input - .replace(/=/g, '') - .replace(/\+/g, '-') - .replace(/\//g, '_'); -}; - - -/** - * Convert Base64URL to normal Base64. - * @param {String} input - * @returns {String} - */ -const base64URLToBase64 = (input) => { - if (!input) { - return input; - } - return base64RePad(input) - .replace(/-/g, '+') - .replace(/_/, '/'); -}; - - -/** - * Add any missing trailing padding which may have been removed from Base64URL encoding. - * @param {String} input - */ -const base64RePad = (input) => { - const blockSize = 4; - const lastBlockSize = input.length % blockSize; - if (lastBlockSize) { - const missing = blockSize - lastBlockSize; - return input + '='.repeat(missing); - } - return input; -}; - - module.exports = { - base64ToBase64URL, - base64URLToBase64, - base64RePad, fileScope, randomBytesAsync, }; \ No newline at end of file