(input: string)
| 709 | const BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; |
| 710 | |
| 711 | function decodeBase32(input: string): Uint8Array { |
| 712 | // Remove padding |
| 713 | input = input.replace(/=+$/, "").toUpperCase(); |
| 714 | if (input.length === 0) return new Uint8Array(0); |
| 715 | |
| 716 | const output: number[] = []; |
| 717 | let bits = 0; |
| 718 | let value = 0; |
| 719 | |
| 720 | for (const char of input) { |
| 721 | const idx = BASE32_ALPHABET.indexOf(char); |
| 722 | if (idx === -1) throw new Error(`Invalid base32 character: ${char}`); |
| 723 | value = (value << 5) | idx; |
| 724 | bits += 5; |
| 725 | if (bits >= 8) { |
| 726 | bits -= 8; |
| 727 | output.push((value >> bits) & 0xff); |
| 728 | } |
| 729 | } |
| 730 | return new Uint8Array(output); |
| 731 | } |
| 732 | |
| 733 | // Convert test suite expected value to our internal format |
| 734 | // deno-lint-ignore no-explicit-any |
no test coverage detected