Estructura inicial del proyecto
This commit is contained in:
46
backend/node_modules/@azure/msal-browser/src/encode/Base64Decode.ts
generated
vendored
Normal file
46
backend/node_modules/@azure/msal-browser/src/encode/Base64Decode.ts
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
BrowserAuthErrorCodes,
|
||||
createBrowserAuthError,
|
||||
} from "../error/BrowserAuthError.js";
|
||||
|
||||
/**
|
||||
* Class which exposes APIs to decode base64 strings to plaintext. See here for implementation details:
|
||||
* https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a URL-safe plaintext decoded string from b64 encoded input.
|
||||
* @param input
|
||||
*/
|
||||
export function base64Decode(input: string): string {
|
||||
return new TextDecoder().decode(base64DecToArr(input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes base64 into Uint8Array
|
||||
* @param base64String
|
||||
*/
|
||||
export function base64DecToArr(base64String: string): Uint8Array {
|
||||
let encodedString = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
||||
switch (encodedString.length % 4) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
encodedString += "==";
|
||||
break;
|
||||
case 3:
|
||||
encodedString += "=";
|
||||
break;
|
||||
default:
|
||||
throw createBrowserAuthError(
|
||||
BrowserAuthErrorCodes.invalidBase64String
|
||||
);
|
||||
}
|
||||
const binString = atob(encodedString);
|
||||
return Uint8Array.from(binString, (m) => m.codePointAt(0) || 0);
|
||||
}
|
||||
52
backend/node_modules/@azure/msal-browser/src/encode/Base64Encode.ts
generated
vendored
Normal file
52
backend/node_modules/@azure/msal-browser/src/encode/Base64Encode.ts
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class which exposes APIs to encode plaintext to base64 encoded string. See here for implementation details:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns URL Safe b64 encoded string from a plaintext string.
|
||||
* @param input
|
||||
*/
|
||||
export function urlEncode(input: string): string {
|
||||
return encodeURIComponent(
|
||||
base64Encode(input)
|
||||
.replace(/=/g, "")
|
||||
.replace(/\+/g, "-")
|
||||
.replace(/\//g, "_")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns URL Safe b64 encoded string from an int8Array.
|
||||
* @param inputArr
|
||||
*/
|
||||
export function urlEncodeArr(inputArr: Uint8Array): string {
|
||||
return base64EncArr(inputArr)
|
||||
.replace(/=/g, "")
|
||||
.replace(/\+/g, "-")
|
||||
.replace(/\//g, "_");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns b64 encoded string from plaintext string.
|
||||
* @param input
|
||||
*/
|
||||
export function base64Encode(input: string): string {
|
||||
return base64EncArr(new TextEncoder().encode(input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 encode byte array
|
||||
* @param aBytes
|
||||
*/
|
||||
function base64EncArr(aBytes: Uint8Array): string {
|
||||
const binString = Array.from(aBytes, (x) => String.fromCodePoint(x)).join(
|
||||
""
|
||||
);
|
||||
return btoa(binString);
|
||||
}
|
||||
Reference in New Issue
Block a user