a47226f6e76fe355416380f3a77db24450481783
3 const path
= require('path');
4 const { randomBytes
} = require('crypto');
5 const { promisify
} = require('util');
6 const randomBytesAsync
= promisify(randomBytes
);
10 * Return a function which combines a part of the filename with a scope, for use in logging.
11 * @param {string} filename
13 const fileScope
= (filename
) => {
14 let fScope
= path
.basename(filename
, '.js');
15 if (fScope
=== 'index') {
16 fScope
= path
.basename(path
.dirname(filename
));
18 return (scope
) => `${fScope}:${scope}`;
23 * Convert Base64 to Base64URL.
24 * @param {String} input
27 const base64ToBase64URL
= (input
) => {
39 * Convert Base64URL to normal Base64.
40 * @param {String} input
43 const base64URLToBase64
= (input
) => {
47 return base64RePad(input
)
54 * Add any missing trailing padding which may have been removed from Base64URL encoding.
55 * @param {String} input
57 const base64RePad
= (input
) => {
59 const lastBlockSize
= input
.length
% blockSize
;
61 const missing
= blockSize
- lastBlockSize
;
62 return input
+ '='.repeat(missing
);