/usr/share/perl5/XML/Smart/Base64.pm is in libxml-smart-perl 1.78-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | #############################################################################
## Name: Base64.pm
## Purpose: XML::Smart::Base64
## Author: Graciliano M. P.
## Modified by:
## Created: 25/5/2003
## RCS-ID:
## Copyright: (c) 2003 Graciliano M. P.
## Licence: This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
#############################################################################
##
## Modified by Harish to fix bugs in xml creation and to errors more readable.
## Tue Nov 1 21:18:43 IST 2011
############################################################################
package XML::Smart::Base64 ;
use strict ;
use warnings ;
use Carp ;
use XML::Smart::Shared qw( _unset_sig_warn _reset_sig_warn ) ;
our $VERSION = '1.3' ;
my ($BASE64_PM) ;
eval("use MIME::Base64 ()") ;
if ( defined &MIME::Base64::encode_base64 ) { $BASE64_PM = 1 ;}
#################
# ENCODE_BASE64 #
#################
sub encode_base64 {
my $value = $_[0] ;
if( $BASE64_PM ) {
eval {
_unset_sig_warn() ;
my $encoded = MIME::Base64::encode_base64( $value ) ;
my $decoded = MIME::Base64::decode_base64( $encoded) ;
_reset_sig_warn() ;
my $tmp_decoded = $decoded ;
$tmp_decoded =~ s/\n//g ;
my $tmp_value = $value ;
$tmp_value =~ s/\n//g ;
return $encoded if( $tmp_decoded eq $tmp_value ) ;
};
}
{
my $encoded ;
my $decoded ;
my $tmp_value ;
my $tmp_decoded ;
eval {
_unset_sig_warn() ;
$encoded = _encode_base64_pure_perl( $value ) ;
$decoded = _decode_base64_pure_perl( $encoded ) ;
_reset_sig_warn() ;
$tmp_decoded = $decoded ;
$tmp_decoded =~ s/\n//g ;
$tmp_value = $value ;
$tmp_value =~ s/\n//g ;
} ; unless( $@ ) {
return $encoded if( $tmp_decoded eq $tmp_value ) ;
}
}
{
_unset_sig_warn() ;
my $encoded = _encode_ord_special( $value ) ;
my $decoded = _decode_ord_special( $encoded ) ;
_reset_sig_warn() ;
my $tmp_decoded = $decoded ;
$tmp_decoded =~ s/\n//g ;
my $tmp_value = $value ;
$tmp_value =~ s/\n//g ;
return $encoded if( $tmp_decoded eq $tmp_value ) ;
}
croak( "Error Encoding\n" ) ;
}
############################
# _ENCODE_BASE64_PURE_PERL #
############################
sub _encode_base64_pure_perl {
my $res = "";
my $eol = $_[1];
$eol = "\n" unless defined $eol;
pos($_[0]) = 0; # ensure start at the beginning
while ($_[0] =~ /(.{1,45})/gs) {
my $text = $1 ;
$res .= substr( pack('u', $text ), 1 ) ;
chop($res);
}
$res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
# fix padding at the end
my $padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;
# break encoded string into lines of no more than 76 characters each
if (length $eol) {
$res =~ s/(.{1,76})/$1$eol/g;
}
$res;
}
############################
# _ENCODE_ORD_SPECIAL #
############################
sub _encode_ord_special {
my $value = shift ;
my @chars = split( //, $value ) ;
my @ords ;
foreach my $char ( @chars ) {
push @ords, ord( $char ) ;
}
return join( "|", @ords ) ;
}
############################
# _DECODE_ORD_SPECIAL #
############################
sub _decode_ord_special {
my $value = shift ;
my @ords = split( /\|/, $value ) ;
my @chars ;
foreach my $ord ( @ords ) {
push @chars, chr( $ord ) ;
}
return join( "", @chars ) ;
}
#################
# DECODE_BASE64 #
#################
sub decode_base64 {
my $value = $_[0] ;
if( $BASE64_PM ) {
eval {
_unset_sig_warn() ;
my $decoded = MIME::Base64::decode_base64( $value ) ;
my $encoded = MIME::Base64::encode_base64( $decoded ) ;
_reset_sig_warn() ;
my $tmp_value = $value ;
$tmp_value =~ s/\n//g ;
my $tmp_encoded = $encoded ;
$tmp_encoded =~ s/\n//g ;
return $decoded if( $tmp_encoded eq $tmp_value ) ;
};
}
{
my $decoded ;
my $encoded ;
my $tmp_value ;
my $tmp_encoded ;
eval {
$decoded = _decode_base64_pure_perl( $value ) ;
$encoded = _encode_base64_pure_perl( $decoded ) ;
$tmp_value = $value ;
$tmp_value =~ s/\n//g ;
$tmp_encoded = $encoded ;
$tmp_encoded =~ s/\n//g ;
} ; unless( $@ ) {
return $decoded if( $tmp_encoded eq $tmp_value ) ;
}
}
{
my $decoded = _decode_ord_special( $value ) ;
my $encoded = _encode_ord_special( $decoded ) ;
my $tmp_value = $value ;
$tmp_value =~ s/\n//g ;
my $tmp_encoded = $encoded ;
$tmp_encoded =~ s/\n//g ;
return $decoded if( $tmp_encoded eq $tmp_value ) ;
}
croak "Error Decoding $value\n" ;
}
############################
# _DECODE_BASE64_PURE_PERL #
############################
sub _decode_base64_pure_perl {
local($^W) = 0 ;
my $str = shift ;
my $res = "";
$str =~ tr|A-Za-z0-9+=/||cd; # remove non-base64 chars
if (length($str) % 4) {
#require Carp;
#Carp::carp("Length of base64 data not a multiple of 4")
}
$str =~ s/=+$//; # remove padding
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format
while ($str =~ /(.{1,60})/gs) {
my $len = chr(32 + length($1)*3/4); # compute length byte
$res .= unpack("u", $len . $1 ); # uudecode
}
$res;
}
#######
# END #
#######
1;
|