/[pdpsoft]/nl.nikhef.pdp.fetchcrl/tags/fetch-crl-3.0.10-1/base64.pm
ViewVC logotype

Contents of /nl.nikhef.pdp.fetchcrl/tags/fetch-crl-3.0.10-1/base64.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1771 - (show annotations) (download) (as text)
Fri Jun 11 20:31:18 2010 UTC (11 years, 5 months ago) by davidg
Original Path: trunk/fetchcrl/base64.pm
File MIME type: application/x-perl
File size: 1343 byte(s)
UU charset has a backtick, solved now -> A

1 #
2 # Library inspired by the Perl 4 code from base64.pl by A. P. Barrett
3 # <barrett@ee.und.ac.za>, October 1993, and subsequent changes by
4 # Earl Hood <earl@earlhood.com> to use MIME::Base64 if available.
5 #
6
7 package base64;
8
9 my $use_MIMEBase64 = eval { require MIME::Base64; };
10
11 sub b64decode
12 {
13 return &MIME::Base64::decode_base64 if $use_MIMEBase64;
14
15 local($^W) = 0;
16 use integer; # should be faster and more accurate
17
18 ( my $str = shift ) =~ tr|A-Za-z0-9+=/||cd;
19 $str =~ s/=+$//;
20 $str =~ s/[\n\s+]//s;
21 $str =~ tr|A-Za-z0-9+/| -_|; # collapse base64 unto continuous set of chars
22 # (by convention the uuencode set, for unpack)
23 my $result;
24 $result = "" unless $str;
25 $result = unpack("u", join('', map( chr(32 + length($_)*3/4) . $_,
26 $str =~ /(.{1,60})/gs) ) );
27 $result;
28 }
29
30 sub b64encode
31 {
32 return &MIME::Base64::encode_base64 if $use_MIMEBase64;
33
34 local ($_) = shift;
35 local($^W) = 0;
36 use integer; # should be faster and more accurate
37
38 my $result = pack("u", $_);
39 $result =~ s/^.//mg;
40 $result =~ s/\n//g;
41
42 $result =~ tr|\` -_|AA-Za-z0-9+/|;
43 my $padding = (3 - length($_) % 3) % 3;
44
45 $result =~ s/.{$padding}$/'=' x $padding/e if $padding;
46 $result =~ s/(.{1,76})/$1\n/g;
47 $result;
48 }
49
50 1;

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28