decodeBase32 function
Decodes a Crockford base32 token to bytes (most significant bit first),
the inverse of encodeBase32. Case-insensitive; trailing bits that do not
fill a byte are dropped. Throws a FormatException on an invalid
character.
Implementation
Uint8List decodeBase32(String token) {
final out = <int>[];
var buffer = 0;
var bits = 0;
for (final code in token.codeUnits) {
buffer = (buffer << 5) | _base32Value(code);
bits += 5;
if (bits >= 8) {
bits -= 8;
out.add((buffer >> bits) & 0xFF);
buffer &= (1 << bits) - 1;
}
}
return Uint8List.fromList(out);
}