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; |
if (length($str) % 4) { |
21 |
$str =~ tr|A-Za-z0-9+/| -_|; # collapse base64 unto continuous set of chars |
require Carp; |
22 |
# (by convention the uuencode set, for unpack) |
Carp::carp("Length of base64 data not a multiple of 4") |
23 |
my $result; |
} |
24 |
$result = "" unless $str; |
$str =~ s/=+$//; # remove padding |
25 |
$result = unpack("u", join('', map( chr(32 + length($_)*3/4) . $_, |
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format |
26 |
$str =~ /(.{1,60})/gs) ) ); |
return "" unless length $str; |
27 |
$result; |
|
28 |
|
unpack("u", join('', map( chr(32 + length($_)*3/4) . $_, |
29 |
|
$str =~ /(.{1,60})/gs) ) ); |
30 |
} |
} |
31 |
|
|
32 |
sub b64encode |
sub b64encode |