}
-/**
- * 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
const crypto = require('crypto');
const zlib = require('zlib');
const { promisify } = require('util');
+const { base64ToBase64URL, base64URLToBase64 } = require('@squeep/base64url');
const common = require('./common');
const allVersions = require('./version-parameters');
const { performance } = require('perf_hooks');
const tag = cipher.getAuthTag();
const merged = Buffer.concat([versionBuffer, flagsBuffer, iv, salt, tag, encrypted, final]).toString('base64');
- const result = common.base64ToBase64URL(merged);
+ const result = base64ToBase64URL(merged);
timingsMs.end = timingsMs.postCrypt = performance.now();
this.logger.debug(_scope, 'statistics', { version, flags: this._prettyFlags(flags), serialized: contents.length, compressed: payload.length, encoded: result.length, ...MysteryBox._timingsLog(timingsMs) });
throw new RangeError('nothing to unpack');
}
- const raw = Buffer.from(common.base64URLToBase64(box), 'base64');
+ const raw = Buffer.from(base64URLToBase64(box), 'base64');
let offset = 0;
const version = raw.slice(offset, 1).readUInt8(0);
"integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==",
"dev": true
},
+ "@squeep/base64url": {
+ "version": "git+https://git.squeep.com/squeep-base64url#5788dd9a225eb1898d624291e50a86f9800866a7",
+ "from": "git+https://git.squeep.com/squeep-base64url#v1.0.0"
+ },
"@ungap/promise-all-settled": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz",
"dev": true
},
"caniuse-lite": {
- "version": "1.0.30001265",
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001265.tgz",
- "integrity": "sha512-YzBnspggWV5hep1m9Z6sZVLOt7vrju8xWooFAgN6BA5qvy98qPAPb7vNUzypFaoh2pb3vlfzbDO8tB57UPGbtw==",
+ "version": "1.0.30001325",
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001325.tgz",
+ "integrity": "sha512-sB1bZHjseSjDtijV1Hb7PB2Zd58Kyx+n/9EotvZ4Qcz2K3d0lWB8dB4nb8wN/TsOGFq3UuAm0zQZNQ4SoR7TrQ==",
"dev": true
},
"chalk": {
}
},
"eslint-plugin-sonarjs": {
- "version": "0.12.0",
- "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.12.0.tgz",
- "integrity": "sha512-soxjK67hoYxO8hesKqXWN50GSM+oG2r35N5WnAMehetahO6zoVpv3HZbdziP0jYWNopEe6te/BFUZOYAZI+qhg==",
+ "version": "0.13.0",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.13.0.tgz",
+ "integrity": "sha512-t3m7ta0EspzDxSOZh3cEOJIJVZgN/TlJYaBGnQlK6W/PZNbWep8q4RQskkJkA7/zwNpX0BaoEOSUUrqaADVoqA==",
"dev": true
},
"eslint-scope": {
"eslint": "^8.12.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-security": "^1.4.0",
- "eslint-plugin-sonarjs": "^0.12.0",
+ "eslint-plugin-sonarjs": "^0.13.0",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"pre-commit": "^1.2.2",
"sinon": "^13.0.1"
+ },
+ "dependencies": {
+ "@squeep/base64url": "git+https://git.squeep.com/squeep-base64url#v1.0.0"
}
}
});
}); // fileScope
- describe('base64ToBase64URL', function () {
- it('covers', function () {
- const b64 = '/+==';
- const expected = '_-';
- const result = common.base64ToBase64URL(b64);
- assert.strictEqual(result, expected);
- });
- it('covers empty', function () {
- const result = common.base64ToBase64URL(undefined);
- assert.strictEqual(result, undefined);
- });
- }); // base64ToBase64URL
-
- describe('base64URLToBase64', function () {
- it('covers', function () {
- const b64url = '_-';
- const expected = '/+==';
- const result = common.base64URLToBase64(b64url);
- assert.strictEqual(result, expected);
- });
- it('covers empty', function () {
- const result = common.base64URLToBase64(undefined);
- assert.strictEqual(result, undefined);
- });
- }); // base64URLToBase64
-
- describe('base64RePad', function () {
- it('covers', function () {
- const b64short = 'af';
- const expected = 'af==';
- const result = common.base64RePad(b64short);
- assert.strictEqual(result, expected);
- });
- it('covers padded', function () {
- const b64 = 'afd4';
- const expected = b64;
- const result = common.base64RePad(b64);
- assert.strictEqual(result, expected);
- });
- }); // base64RePad
-
}); // Common