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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1768 by davidg, Fri Jun 11 19:45:08 2010 UTC revision 1771 by davidg, Fri Jun 11 20:31:18 2010 UTC
# Line 10  my $use_MIMEBase64 = eval { require MIME Line 10  my $use_MIMEBase64 = eval { require MIME
10    
11  sub b64decode  sub b64decode
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;
16      use integer; # should be faster and more accurate      use integer; # should be faster and more accurate
17    
18      ( my $str = shift ) =~ tr|A-Za-z0-9+=/||cd;      ( my $str = shift ) =~ tr|A-Za-z0-9+=/||cd;
19      $str =~ s/=+$//;      $str =~ s/=+$//;
20        $str =~ s/[\n\s+]//s;
21      $str =~ tr|A-Za-z0-9+/| -_|; # collapse base64 unto continuous set of chars      $str =~ tr|A-Za-z0-9+/| -_|; # collapse base64 unto continuous set of chars
22                                   # (by convention the uuencode set, for unpack)                                   # (by convention the uuencode set, for unpack)
23        my $result;
24      return "" unless $str;      $result = "" unless $str;
25      return unpack("u", join('', map( chr(32 + length($_)*3/4) . $_,      $result = unpack("u", join('', map( chr(32 + length($_)*3/4) . $_,
26                                  $str =~ /(.{1,60})/gs) ) );                                     $str =~ /(.{1,60})/gs) ) );
27        $result;
28  }  }
29    
30  sub b64encode  sub b64encode
31  {  {
32      return &MIME::Base64::encode_base64(@_) if $use_MIMEBase64;      return &MIME::Base64::encode_base64 if $use_MIMEBase64;
33    
34      local ($_) = shift;      local ($_) = shift;
35      local($^W) = 0;      local($^W) = 0;
36      use integer; # should be faster and more accurate      use integer; # should be faster and more accurate
37            
38      my $result = pack("u", $_[0]);      my $result = pack("u", $_);
39      $result =~ s/^.//mg;      $result =~ s/^.//mg;
40      $result =~ s/\n//g;      $result =~ s/\n//g;
41    
42      $result =~ tr| -_|A-Za-z0-9+/|;      $result =~ tr|\` -_|AA-Za-z0-9+/|;
43      my $padding = (3 - length($_[0]) % 3) % 3;      my $padding = (3 - length($_) % 3) % 3;
44    
45      $result =~ s/.{$padding}$/'=' x $padding/e if $padding;      $result =~ s/.{$padding}$/'=' x $padding/e if $padding;
46      if (length $eol) {      $result =~ s/(.{1,76})/$1\n/g;
47          $result =~ s/(.{1,76})/$1$eol/g;      $result;
     }  
     return $result;  
48  }  }
49    
50  1;  1;

Legend:
Removed from v.1768  
changed lines
  Added in v.1771

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