test_tart_inputs.js (972B)
1 import * as tart from "tart"; 2 3 function assert(condition, message) { 4 if (!condition) { 5 throw new Error(message); 6 } 7 } 8 9 function expectThrow(fn, message) { 10 let threw = false; 11 try { 12 fn(); 13 } catch (_) { 14 threw = true; 15 } 16 assert(threw, message); 17 } 18 19 assert(tart.decodeCrock("").byteLength === 0, 20 "empty Crockford input must decode to an empty byte array"); 21 assert(tart.randomBytes(1024 * 1024).byteLength === 1024 * 1024, 22 "randomBytes must support heap-sized outputs"); 23 24 const hashState = tart.hashStateInit(); 25 expectThrow(() => tart.hashStateUpdate(hashState, "not a buffer"), 26 "hashStateUpdate must reject non-buffer input"); 27 expectThrow(() => tart.kdf(8161, new Uint8Array(1)), 28 "HKDF output beyond the RFC limit must be rejected"); 29 expectThrow(() => tart.rsaBlind(new Uint8Array(64), new Uint8Array(32), 30 new Uint8Array(4)), 31 "malformed RSA public keys must be rejected");