(text: string)
| 56 | // that don't fill a byte are discarded, matching the encoder's |
| 57 | // zero-padding of the final group. |
| 58 | export function decodeBase32(text: string): Uint8Array { |
| 59 | const out: number[] = []; |
| 60 | let bits = 0; |
| 61 | let value = 0; |
| 62 | for (const char of text) { |
| 63 | const digit = DECODE.get(char); |
| 64 | if (digit === undefined) { |
| 65 | throw new Error(`decodeBase32: invalid character ${JSON.stringify(char)}`); |
| 66 | } |
| 67 | value = (value << 5) | digit; |
| 68 | bits += 5; |
| 69 | if (bits >= 8) { |
| 70 | bits -= 8; |
| 71 | out.push((value >>> bits) & 0xff); |
| 72 | } |
| 73 | } |
| 74 | return new Uint8Array(out); |
| 75 | } |
| 76 | |
| 77 | // Generate a short random id: 16 random bytes (a UUID's worth of |
| 78 | // entropy) Crockford base32-encoded into 26 lowercase characters. |
no test coverage detected