mirror of
https://github.com/azure/login.git
synced 2026-06-07 06:17:08 +00:00
* Bump lodash from 4.17.15 to 4.17.19 (#52) Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amruta Kawade <65217380+AmrutaKawade@users.noreply.github.com> * Bump @actions/core from 1.1.3 to 1.2.6 (#60) Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.1.3 to 1.2.6. - [Release notes](https://github.com/actions/toolkit/releases) - [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amruta Kawade <65217380+AmrutaKawade@users.noreply.github.com> * updating node_nodules * updated package-lock Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
"use strict";
|
|
|
|
/**
|
|
* btoa() as defined by the HTML and Infra specs, which mostly just references
|
|
* RFC 4648.
|
|
*/
|
|
function btoa(s) {
|
|
let i;
|
|
// String conversion as required by Web IDL.
|
|
s = `${s}`;
|
|
// "The btoa() method must throw an "InvalidCharacterError" DOMException if
|
|
// data contains any character whose code point is greater than U+00FF."
|
|
for (i = 0; i < s.length; i++) {
|
|
if (s.charCodeAt(i) > 255) {
|
|
return null;
|
|
}
|
|
}
|
|
let out = "";
|
|
for (i = 0; i < s.length; i += 3) {
|
|
const groupsOfSix = [undefined, undefined, undefined, undefined];
|
|
groupsOfSix[0] = s.charCodeAt(i) >> 2;
|
|
groupsOfSix[1] = (s.charCodeAt(i) & 0x03) << 4;
|
|
if (s.length > i + 1) {
|
|
groupsOfSix[1] |= s.charCodeAt(i + 1) >> 4;
|
|
groupsOfSix[2] = (s.charCodeAt(i + 1) & 0x0f) << 2;
|
|
}
|
|
if (s.length > i + 2) {
|
|
groupsOfSix[2] |= s.charCodeAt(i + 2) >> 6;
|
|
groupsOfSix[3] = s.charCodeAt(i + 2) & 0x3f;
|
|
}
|
|
for (let j = 0; j < groupsOfSix.length; j++) {
|
|
if (typeof groupsOfSix[j] === "undefined") {
|
|
out += "=";
|
|
} else {
|
|
out += btoaLookup(groupsOfSix[j]);
|
|
}
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/**
|
|
* Lookup table for btoa(), which converts a six-bit number into the
|
|
* corresponding ASCII character.
|
|
*/
|
|
function btoaLookup(idx) {
|
|
if (idx < 26) {
|
|
return String.fromCharCode(idx + "A".charCodeAt(0));
|
|
}
|
|
if (idx < 52) {
|
|
return String.fromCharCode(idx - 26 + "a".charCodeAt(0));
|
|
}
|
|
if (idx < 62) {
|
|
return String.fromCharCode(idx - 52 + "0".charCodeAt(0));
|
|
}
|
|
if (idx === 62) {
|
|
return "+";
|
|
}
|
|
if (idx === 63) {
|
|
return "/";
|
|
}
|
|
// Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the tests.
|
|
return undefined;
|
|
}
|
|
|
|
module.exports = btoa;
|