--- trunk/fetchcrl/base64.pm 2010/06/11 21:00:30 1775 +++ trunk/fetchcrl/base64.pm 2010/06/11 21:05:01 1776 @@ -12,19 +12,19 @@ { return &MIME::Base64::decode_base64 if $use_MIMEBase64; - local($^W) = 0; - use integer; # should be faster and more accurate + local($^W) = 0; # unpack("u",...) gives bogus warning in 5.00[123] + use integer; - ( my $str = shift ) =~ tr|A-Za-z0-9+=/||cd; - $str =~ s/=+$//; - $str =~ s/[\n\s+]//s; - $str =~ tr|A-Za-z0-9+/| -_|; # collapse base64 unto continuous set of chars - # (by convention the uuencode set, for unpack) - my $result; - $result = "" unless $str; - $result = unpack("u", join('', map( chr(32 + length($_)*3/4) . $_, - $str =~ /(.{1,60})/gs) ) ); - $result; + my $str = shift; + $str =~ tr|A-Za-z0-9+=/||cd; # remove non-base64 chars + length($str) % 4 and + die "Internal error in state: length of base64 data not a multiple of 4"; + $str =~ s/=+$//; # remove padding + $str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format + return "" unless length $str; + + unpack("u", join('', map( chr(32 + length($_)*3/4) . $_, + $str =~ /(.{1,60})/gs) ) ); } sub b64encode