Add controllers and packages for security keys
This commit is contained in:
parent
f8ec8b4d5a
commit
06f692e649
29 changed files with 2398 additions and 383 deletions
12
resources/scripts/lib/base64.spec.ts
Normal file
12
resources/scripts/lib/base64.spec.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { decodeBase64 } from '@/lib/base64';
|
||||
|
||||
describe('@/lib/base64.ts', function () {
|
||||
describe('decodeBase64()', function () {
|
||||
it.each([
|
||||
['', ''],
|
||||
['', ''],
|
||||
])('should decode "%s" to "%s"', function (input, output) {
|
||||
expect(decodeBase64(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
});
|
16
resources/scripts/lib/base64.ts
Normal file
16
resources/scripts/lib/base64.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
function decodeBase64 (input: string): string {
|
||||
input = input.replace(/-/g, '+').replace(/_/g, '/');
|
||||
|
||||
const pad = input.length % 4;
|
||||
if (pad) {
|
||||
if (pad === 1) {
|
||||
throw new Error('InvalidLengthError: Input base64url string is the wrong length to determine padding');
|
||||
}
|
||||
|
||||
input += new Array(5 - pad).join('=');
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
export { decodeBase64 }
|
21
resources/scripts/lib/buffer.spec.ts
Normal file
21
resources/scripts/lib/buffer.spec.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { decodeBuffer, encodeBuffer } from '@/lib/buffer';
|
||||
|
||||
describe('@/lib/buffer.ts', function () {
|
||||
describe('decodeBuffer()', function () {
|
||||
it.each([
|
||||
['', ''],
|
||||
['', ''],
|
||||
])('should decode "%s" to "%s"', function (input, output) {
|
||||
expect(decodeBuffer(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encodeBuffer()', function () {
|
||||
it.each([
|
||||
[new Uint8Array(0), ''],
|
||||
[new Uint8Array(0), ''],
|
||||
])('should encode "%s" to "%s"', function (input, output) {
|
||||
expect(encodeBuffer(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
});
|
9
resources/scripts/lib/buffer.ts
Normal file
9
resources/scripts/lib/buffer.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
function decodeBuffer(value: string): ArrayBuffer {
|
||||
return Uint8Array.from(window.atob(value), c => c.charCodeAt(0));
|
||||
}
|
||||
|
||||
function encodeBuffer(value: ArrayBuffer): string {
|
||||
return btoa(String.fromCharCode(...new Uint8Array(value)));
|
||||
}
|
||||
|
||||
export { decodeBuffer, encodeBuffer };
|
Loading…
Add table
Add a link
Reference in a new issue