Subject: | Uppercase letters are rejected by decode_base32 |
Uppercase letters are rejected by decode_base32
The following code should address that and should be faster. However, I
neither tested it nor benchmarked it.
sub decode_base32($) {
my $str = shift;
my $init_len = length($str);
$str =~ tr/a-z2-7A-Z/\x00-\x1F\x00-\x19/d;
Carp::croak('Data contains non-base32 characters')
if length($str) != $init_len;
$str = unpack('B*', $str);
$str =~ s/.{3}(.{5})/$1/sg;
pos($str) = int(length($str) / 8);
Carp::croak('Data incorrectly padded (too much or non-zero)')
if $str !~ s/\G0{0,4}\z//gs;
return pack('B*', $str);
}