tweetnacl-ts
Version:
Port of TweetNaCl cryptographic library to TypeScript (and ES6)
12 lines (10 loc) • 338 B
text/typescript
export function validateBase64(s: string) {
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s)) {
throw new TypeError('invalid base64 string');
}
}
export function validateHex(s: string) {
if (!/^(?:[A-Fa-f0-9]{2})+$/.test(s)) {
throw new TypeError('invalid hex string');
}
}