Subject: | Error detection failure |
There's a typo in one of the error check making it fail to detect the
following error:
$ perl -MTest::More=no_plan -MConvert::Base32 -e'
is encode_base32(decode_base32($_)), $_ for @ARGV;
' aaaaaa
not ok 1
# Failed test at -e line 1.
# got: 'aaaaa'
# expected: 'aaaaaa'
1..1
# Looks like you failed 1 test of 1.
The check
my $input_check = length($str) %8;
if ($input_check == 1 || $input_check == 3 || $input_check == 8) {
Carp::croak('Length of data invalid');
}
should be
my $input_check = length($str) %8;
if ($input_check == 1 || $input_check == 3 || $input_check == 6) {
Carp::croak('Length of data invalid');
}
and would be simpler as
if (length($buffer) % 8 >= 5) {
Carp::croak('Length of data invalid');
}
if you don't mind checking after the <c>char2bits</c> loop.