Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: MIME::Base64 is broken in 5.8.2?

by MADuran (Beadle)
on Jan 19, 2004 at 20:50 UTC ( #322429=note: print w/replies, xml ) Need Help??

in reply to MIME::Base64 is broken in 5.8.2?

I duplcated the behavior on AS Perl 5.8.2 Win 2K. And a quick (very quick) look over of RFC 3548 seems to say it is broken. But I did this:

use IO::Socket; use MIME::Base64; use strict; use warnings; my $encode = encode_base64("peip:930612"); print "$encode \n"; chomp $encode; inspect($encode); my $decode = decode_base64($encode); print "\n $decode \n"; sub inspect { (my $copy = shift) =~ s/([^[:print:]])/sprintf " (0x%02x) ", ord $ + 1/ge; print $copy; }

I got this back:
cGVpcDo5MzA2MTI= cGVpcDo5MzA2MTI= peip:930612
and so worked around it.
I wonder if it is in the *NIX version of 5.8.2/5.8.3??

Update: The MIME spec allows CRLF characters in Base64:

As quoted in Above RFC: "Implementations MUST reject the encoding if it contains characters outside the base alphabet when interpreting base encoded data, unless the specification referring to this document explicitly states otherwise. Such specifications may, as MIME does, instead state that characters outside the base encoding alphabet should simply be ignored when interpreting data ("be liberal in what you accept").

Note that this means that any CRLF constitute "non alphabet characters" and are ignored. Furthermore, such specifications may consider the pad character, "=", as not part of the base alphabet until the end of the string. If more than the allowed number of pad characters are found at the end of the string, e.g., a base 64 string terminated with "===", the excess pad characters could be ignored."

Who is in need of a spiffy sig

Replies are listed 'Best First'.
Re: Re: MIME::Base64 is broken in 5.8.2?
by pg (Canon) on Jan 19, 2004 at 20:57 UTC

    Thanks MADuran and graff, for your help.

    I think what the module supposed to do is to have a \n inserted after every 76 characters, so that each line is no longer than 76.

    But for an encoded string that is less than 76 character long, no line-breaker should be inserted. But... fine, I think I just chomp it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://322429]
[marto]: meh, the admins are lazy, I just piped null to some old large log files, problem solved
[Corion]: marto: Heh ;) You're just further enabling their lazyness :-D

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-01-24 10:02 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (203 votes). Check out past polls.