Validate the full Windows Update plan through its fixed script revision
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export const hashPattern = /^[0-9a-f]{64}$/;
|
||||
export function parseStrictJson(source: string): unknown {
|
||||
if (new TextEncoder().encode(source).length > 1048576) throw new Error('JSON über 1 MiB');
|
||||
let i = 0;
|
||||
const space = () => { while (/\s/.test(source[i] ?? '') && i < source.length) i++; };
|
||||
const string = (): string => { const start = i++; while (i < source.length) { if (source[i] === '\\') i += 2; else if (source[i++] === '"') return JSON.parse(source.slice(start, i)); } throw new Error('Ungültiger JSON-String'); };
|
||||
const value = (depth: number): void => {
|
||||
if (depth > 64) throw new Error('JSON zu tief verschachtelt'); space();
|
||||
if (source[i] === '{') { i++; space(); const keys = new Set<string>(); if (source[i] === '}') { i++; return; }
|
||||
while (i < source.length) { space(); if (source[i] !== '"') throw new Error('JSON-Objektschlüssel erwartet'); const key = string(); if (keys.has(key)) throw new Error(`Doppeltes JSON-Feld: ${key}`); keys.add(key); space(); if (source[i++] !== ':') throw new Error('JSON-Doppelpunkt erwartet'); value(depth + 1); space(); const end = source[i++]; if (end === '}') return; if (end !== ',') throw new Error('Ungültiges JSON-Objekt'); } throw new Error('Unvollständiges JSON-Objekt'); }
|
||||
if (source[i] === '[') { i++; space(); if (source[i] === ']') { i++; return; } while (i < source.length) { value(depth + 1); space(); const end = source[i++]; if (end === ']') return; if (end !== ',') throw new Error('Ungültiges JSON-Array'); } throw new Error('Unvollständiges JSON-Array'); }
|
||||
if (source[i] === '"') { string(); return; }
|
||||
const token = /^(?:true|false|null|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)/.exec(source.slice(i)); if (!token) throw new Error('Ungültiger JSON-Wert'); i += token[0].length;
|
||||
};
|
||||
value(0); space(); if (i !== source.length) throw new Error('Zusätzliche JSON-Daten'); return JSON.parse(source);
|
||||
}
|
||||
export function bytes(value: unknown): Uint8Array<ArrayBuffer> { if (!Array.isArray(value) || !value.length || value.length > 1048576 || value.some(n => !Number.isInteger(n) || n < 0 || n > 255)) throw new Error('Exakte Bytefolge fehlt'); return new Uint8Array(value); }
|
||||
export async function sha256(value: Uint8Array<ArrayBuffer>): Promise<string> { return Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', value)), n => n.toString(16).padStart(2, '0')).join(''); }
|
||||
Reference in New Issue
Block a user