diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2010-11-25 12:48:21 +0000 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2010-11-25 12:49:13 +0000 |
commit | 2456140e9cfda88ed22ea1c7290a61234c84aea6 (patch) | |
tree | 87fa9a936bfa0ea9a8f08e263f7c451f7538d4b8 /cpan | |
parent | ec3405c82bf3efe09e36ca55c492c32c1235f449 (diff) | |
download | perl-2456140e9cfda88ed22ea1c7290a61234c84aea6.tar.gz |
Update MIME-Base64 to CPAN version 3.11
[DELTA]
2010-10-24 Gisle Aas <gisle@ActiveState.com>
Release 3.11
Provide encode_base64url and decode_base64url functions to process
the base64 scheme for "URL applications".
The decode_base64() does not issue warnings on suspect input data
any more.
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/MIME-Base64/Base64.pm | 68 | ||||
-rw-r--r-- | cpan/MIME-Base64/Base64.xs | 25 | ||||
-rw-r--r-- | cpan/MIME-Base64/Changes | 12 | ||||
-rw-r--r-- | cpan/MIME-Base64/QuotedPrint.pm | 2 | ||||
-rw-r--r-- | cpan/MIME-Base64/t/warn.t | 68 |
5 files changed, 47 insertions, 128 deletions
diff --git a/cpan/MIME-Base64/Base64.pm b/cpan/MIME-Base64/Base64.pm index 758beccf24..32d387a2f9 100644 --- a/cpan/MIME-Base64/Base64.pm +++ b/cpan/MIME-Base64/Base64.pm @@ -6,9 +6,9 @@ use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); require Exporter; @ISA = qw(Exporter); @EXPORT = qw(encode_base64 decode_base64); -@EXPORT_OK = qw(encoded_base64_length decoded_base64_length); +@EXPORT_OK = qw(encode_base64url decode_base64url encoded_base64_length decoded_base64_length); -$VERSION = '3.10'; +$VERSION = '3.11'; require XSLoader; XSLoader::load('MIME::Base64', $VERSION); @@ -16,6 +16,20 @@ XSLoader::load('MIME::Base64', $VERSION); *encode = \&encode_base64; *decode = \&decode_base64; +sub encode_base64url { + my $e = encode_base64(shift, ""); + $e =~ s/=+\z//; + $e =~ tr[+/][-_]; + return $e; +} + +sub decode_base64url { + my $s = shift; + $s =~ tr[-_][+/]; + $s .= '=' while length($s) % 4; + return decode_base64($s); +} + 1; __END__ @@ -56,6 +70,11 @@ characters each and it will end with $eol unless it is empty. Pass an empty string as second argument if you do not want the encoded string to be broken into lines. +The function will croak with "Wide character in subroutine entry" if $str +contains characters with code above 255. The base64 encoding is only defined +for single-byte characters. Use the Encode module to select the byte encoding +you want. + =item decode_base64($str) Decode a base64 string by calling the decode_base64() function. This @@ -83,6 +102,15 @@ Additional functions not exported by default: =over 4 +=item encode_base64url($str) + +=item decode_base64url($str) + +Encode and decode according to the base64 scheme for "URL applications" [1]. +This is a variant of the base64 encoding which does not use padding, does not +break the string into multiple lines and use the characters "-" and "_" instead +of "+" and "/" to avoid using reserved URL characters. + =item encoded_base64_length($str) =item encoded_base64_length($str, $eol) @@ -99,40 +127,6 @@ but should be more efficient. =back -=head1 DIAGNOSTICS - -The following warnings can be generated if perl is invoked with the -C<-w> switch: - -=over 4 - -=item Premature end of base64 data - -The number of characters to decode is not a multiple of 4. Legal -base64 data should be padded with one or two "=" characters to make -its length a multiple of 4. The decoded result will be the same -whether the padding is present or not. - -=item Premature padding of base64 data - -The '=' padding character occurs as the first or second character -in a base64 quartet. - -=back - -The following exception can be raised: - -=over 4 - -=item Wide character in subroutine entry - -The string passed to encode_base64() contains characters with code -above 255. The base64 encoding is only defined for single-byte -characters. Use the Encode module to select the byte encoding you -want. - -=back - =head1 EXAMPLES If you want to encode a large file, you should encode it in chunks @@ -193,4 +187,6 @@ Communications Research, Inc. (Bellcore) L<MIME::QuotedPrint> +[1] L<http://en.wikipedia.org/wiki/Base64#URL_applications> + =cut diff --git a/cpan/MIME-Base64/Base64.xs b/cpan/MIME-Base64/Base64.xs index aa538980ae..5bac9ec479 100644 --- a/cpan/MIME-Base64/Base64.xs +++ b/cpan/MIME-Base64/Base64.xs @@ -36,24 +36,6 @@ extern "C" { } #endif -#ifndef PATCHLEVEL -# include <patchlevel.h> -# if !(defined(PERL_VERSION) || (SUBVERSION > 0 && defined(PATCHLEVEL))) -# include <could_not_find_Perl_patchlevel.h> -# endif -#endif - -#if PATCHLEVEL <= 4 && !defined(PL_dowarn) - #define PL_dowarn dowarn -#endif - -#ifdef G_WARN_ON - #define DOWARN (PL_dowarn & G_WARN_ON) -#else - #define DOWARN PL_dowarn -#endif - - #define MAX_LINE 76 /* size of encoded lines */ static const char basis_64[] = @@ -198,7 +180,7 @@ decode_base64(sv) PREINIT: STRLEN len; - register unsigned char *str = (unsigned char*)SvPVbyte(sv, len); + register unsigned char *str = (unsigned char*)SvPV(sv, len); unsigned char const* end = str + len; char *r; unsigned char c[4]; @@ -221,8 +203,6 @@ decode_base64(sv) if (str == end) { if (i < 4) { - if (i && DOWARN) - warn("Premature end of base64 data"); if (i < 2) goto thats_it; if (i == 2) c[2] = EQ; c[3] = EQ; @@ -232,7 +212,6 @@ decode_base64(sv) } while (i < 4); if (c[0] == EQ || c[1] == EQ) { - if (DOWARN) warn("Premature padding of base64 data"); break; } /* printf("c0=%d,c1=%d,c2=%d,c3=%d\n", c[0],c[1],c[2],c[3]);*/ @@ -291,7 +270,7 @@ decoded_base64_length(sv) PREINIT: STRLEN len; - register unsigned char *str = (unsigned char*)SvPVbyte(sv, len); + register unsigned char *str = (unsigned char*)SvPV(sv, len); unsigned char const* end = str + len; int i = 0; diff --git a/cpan/MIME-Base64/Changes b/cpan/MIME-Base64/Changes index a6f85bd8fd..bc360ca0d3 100644 --- a/cpan/MIME-Base64/Changes +++ b/cpan/MIME-Base64/Changes @@ -1,3 +1,15 @@ +2010-10-24 Gisle Aas <gisle@ActiveState.com> + + Release 3.11 + + Provide encode_base64url and decode_base64url functions to process + the base64 scheme for "URL applications". + + The decode_base64() does not issue warnings on suspect input data + any more. + + + 2010-10-11 Gisle Aas <gisle@ActiveState.com> Release 3.10 diff --git a/cpan/MIME-Base64/QuotedPrint.pm b/cpan/MIME-Base64/QuotedPrint.pm index 7b03e69e12..beb9f84cf1 100644 --- a/cpan/MIME-Base64/QuotedPrint.pm +++ b/cpan/MIME-Base64/QuotedPrint.pm @@ -7,7 +7,7 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(encode_qp decode_qp); -$VERSION = "3.10"; +$VERSION = "3.11"; use MIME::Base64; # will load XS version of {en,de}code_qp() diff --git a/cpan/MIME-Base64/t/warn.t b/cpan/MIME-Base64/t/warn.t deleted file mode 100644 index 4ea57df988..0000000000 --- a/cpan/MIME-Base64/t/warn.t +++ /dev/null @@ -1,68 +0,0 @@ -#!perl -w - -BEGIN { - if ($ENV{'PERL_CORE'}){ - chdir 't' if -d 't'; - @INC = '../lib'; - } -} - -BEGIN { - eval { - require warnings; - }; - if ($@) { - print "1..0\n"; - print $@; - exit; - } -} - -use strict; -use MIME::Base64 qw(decode_base64); - -print "1..1\n"; - -use warnings; - -my @warn; -$SIG{__WARN__} = sub { push(@warn, @_) }; - -warn; -my $a; -$a = decode_base64("aa"); -$a = decode_base64("a==="); -warn; -$a = do { - no warnings; - decode_base64("aa"); -}; -$a = do { - no warnings; - decode_base64("a==="); -}; -warn; -$a = do { - local $^W; - decode_base64("aa"); -}; -$a = do { - local $^W; - decode_base64("a==="); -}; -warn; - -for (@warn) { - print "# $_"; -} - -print "not " unless join("", @warn) eq <<"EOT"; print "ok 1\n"; -Warning: something's wrong at $0 line 31. -Premature end of base64 data at $0 line 33. -Premature padding of base64 data at $0 line 34. -Warning: something's wrong at $0 line 35. -Premature end of base64 data at $0 line 38. -Premature padding of base64 data at $0 line 42. -Warning: something's wrong at $0 line 44. -Warning: something's wrong at $0 line 53. -EOT |