add frontend AES-GCM and base64 helpers with Vitest coverage.

This commit is contained in:
2026-10-19 03:00:03 +02:00
parent f2987da2fe
commit 0238858c8b
29 changed files with 2021 additions and 2 deletions
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest';
import { base64ToBytes } from '@/utils/encoding/base64ToBytes';
describe('base64ToBytes', () => {
it('decodes RFC 4648 examples', () => {
expect(base64ToBytes('Zg==')).toEqual(new Uint8Array([102]));
expect(base64ToBytes('Zm8=')).toEqual(new Uint8Array([102, 111]));
expect(base64ToBytes('Zm9v')).toEqual(new Uint8Array([102, 111, 111]));
expect(base64ToBytes('Zm9vYg==')).toEqual(new Uint8Array([102, 111, 111, 98]));
});
it('decodes empty input', () => {
expect(base64ToBytes('')).toEqual(new Uint8Array([]));
});
it('decodes every byte value via roundtrip with btoa', () => {
const bytes = new Uint8Array(256);
for (let i = 0; i < 256; i++) {
bytes[i] = i;
}
const binary = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
const base64 = btoa(binary);
expect(base64ToBytes(base64)).toEqual(bytes);
});
it('rejects invalid base64', () => {
expect(() => base64ToBytes('not!!!valid')).toThrow();
});
});