12 |
{ |
{ |
13 |
return &MIME::Base64::decode_base64 if $use_MIMEBase64; |
return &MIME::Base64::decode_base64 if $use_MIMEBase64; |
14 |
|
|
15 |
local($^W) = 0; |
local($^W) = 0; # unpack("u",...) gives bogus warning in 5.00[123] |
16 |
use integer; # should be faster and more accurate |
use integer; |
17 |
|
|
18 |
( my $str = shift ) =~ tr|A-Za-z0-9+=/||cd; |
my $str = shift; |
19 |
$str =~ s/=+$//; |
$str =~ tr|A-Za-z0-9+=/||cd; # remove non-base64 chars |
20 |
$str =~ s/[\n\s+]//s; |
length($str) % 4 and |
21 |
$str =~ tr|A-Za-z0-9+/| -_|; # collapse base64 unto continuous set of chars |
die "Internal error in state: length of base64 data not a multiple of 4"; |
22 |
# (by convention the uuencode set, for unpack) |
$str =~ s/=+$//; # remove padding |
23 |
my $result; |
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format |
24 |
$result = "" unless $str; |
return "" unless length $str; |
25 |
$result = unpack("u", join('', map( chr(32 + length($_)*3/4) . $_, |
|
26 |
$str =~ /(.{1,60})/gs) ) ); |
unpack("u", join('', map( chr(32 + length($_)*3/4) . $_, |
27 |
$result; |
$str =~ /(.{1,60})/gs) ) ); |
28 |
} |
} |
29 |
|
|
30 |
sub b64encode |
sub b64encode |