swc/bundler/tests/.cache/untrusted/63f07e6080a4fcc7ae3b10f853d91fef432cbba4.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

25 lines
907 B
TypeScript

// Loaded from https://raw.githubusercontent.com/aricart/tweetnacl-deno/import-type-fixes/src/check.ts
import type { ByteArray } from './array.ts';
import { SecretBoxLength } from './secretbox.ts';
import { BoxLength } from './box.ts';
export function checkLengths(k: ByteArray, n: ByteArray) {
if (k.length != SecretBoxLength.Key) throw new Error('bad key size');
if (n.length != SecretBoxLength.Nonce) throw new Error('bad nonce size');
}
export function checkBoxLengths(pk: ByteArray, sk: ByteArray) {
if (pk.length != BoxLength.PublicKey) throw new Error('bad public key size');
if (sk.length != BoxLength.SecretKey) throw new Error('bad secret key size');
}
export function checkArrayTypes(...arrays: ByteArray[]) {
for (const array of arrays) {
if (!(array instanceof Uint8Array)) {
throw new TypeError('unexpected type, use ByteArray');
}
}
}