summaryrefslogtreecommitdiff
path: root/cpan/MIME-Base64
diff options
context:
space:
mode:
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>2010-11-12 00:03:47 +0000
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>2010-11-12 00:03:47 +0000
commit46787c0e32a676e3fcb60d752d4858316dc1ef77 (patch)
tree9d2c703453621608212fa83c4cb086b878229730 /cpan/MIME-Base64
parent678febd75acbe46e48e9655d1e7c6345b1d04f0a (diff)
downloadperl-46787c0e32a676e3fcb60d752d4858316dc1ef77.tar.gz
Update MIME-Base64 to CPAN version 3.10
[DELTA] Release 3.10 Provide functions to calculate the length of encoded and decoded base64 strings [RT#62404]
Diffstat (limited to 'cpan/MIME-Base64')
-rw-r--r--cpan/MIME-Base64/Base64.pm27
-rw-r--r--cpan/MIME-Base64/Base64.xs58
-rw-r--r--cpan/MIME-Base64/Changes9
-rw-r--r--cpan/MIME-Base64/Makefile.PL32
-rw-r--r--cpan/MIME-Base64/QuotedPrint.pm2
-rw-r--r--cpan/MIME-Base64/t/length.t49
6 files changed, 173 insertions, 4 deletions
diff --git a/cpan/MIME-Base64/Base64.pm b/cpan/MIME-Base64/Base64.pm
index 2bcd585779..758beccf24 100644
--- a/cpan/MIME-Base64/Base64.pm
+++ b/cpan/MIME-Base64/Base64.pm
@@ -1,13 +1,14 @@
package MIME::Base64;
use strict;
-use vars qw(@ISA @EXPORT $VERSION);
+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);
-$VERSION = '3.09';
+$VERSION = '3.10';
require XSLoader;
XSLoader::load('MIME::Base64', $VERSION);
@@ -39,7 +40,7 @@ arbitrary sequences of octets in a form that need not be humanly
readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used,
enabling 6 bits to be represented per printable character.
-The following functions are provided:
+The following primary functions are provided:
=over 4
@@ -78,6 +79,26 @@ call them as:
$encoded = MIME::Base64::encode($decoded);
$decoded = MIME::Base64::decode($encoded);
+Additional functions not exported by default:
+
+=over 4
+
+=item encoded_base64_length($str)
+
+=item encoded_base64_length($str, $eol)
+
+Returns the length that the encoded string would have without actually
+encoding it. This will return the same value as C<< length(encode_base64($str)) >>,
+but should be more efficient.
+
+=item decoded_base64_length($str)
+
+Returns the length that the decoded string would have without actually
+decoding it. This will return the same value as C<< length(decode_base64($str)) >>,
+but should be more efficient.
+
+=back
+
=head1 DIAGNOSTICS
The following warnings can be generated if perl is invoked with the
diff --git a/cpan/MIME-Base64/Base64.xs b/cpan/MIME-Base64/Base64.xs
index 279aad984b..aa538980ae 100644
--- a/cpan/MIME-Base64/Base64.xs
+++ b/cpan/MIME-Base64/Base64.xs
@@ -255,6 +255,64 @@ decode_base64(sv)
OUTPUT:
RETVAL
+int
+encoded_base64_length(sv,...)
+ SV* sv
+ PROTOTYPE: $;$
+
+ PREINIT:
+ SSize_t len; /* length of the string */
+ STRLEN eollen; /* length of the EOL sequence */
+
+ CODE:
+#if PERL_REVISION == 5 && PERL_VERSION >= 6
+ sv_utf8_downgrade(sv, FALSE);
+#endif
+ len = SvCUR(sv);
+
+ if (items > 1 && SvOK(ST(1))) {
+ eollen = SvCUR(ST(1));
+ } else {
+ eollen = 1;
+ }
+
+ RETVAL = (len+2) / 3 * 4; /* encoded bytes */
+ if (RETVAL) {
+ RETVAL += ((RETVAL-1) / MAX_LINE + 1) * eollen;
+ }
+
+ OUTPUT:
+ RETVAL
+
+int
+decoded_base64_length(sv)
+ SV* sv
+ PROTOTYPE: $
+
+ PREINIT:
+ STRLEN len;
+ register unsigned char *str = (unsigned char*)SvPVbyte(sv, len);
+ unsigned char const* end = str + len;
+ int i = 0;
+
+ CODE:
+ RETVAL = 0;
+ while (str < end) {
+ unsigned char uc = index_64[NATIVE_TO_ASCII(*str++)];
+ if (uc == INVALID)
+ continue;
+ if (uc == EQ)
+ break;
+ if (i++) {
+ RETVAL++;
+ if (i == 4)
+ i = 0;
+ }
+ }
+
+ OUTPUT:
+ RETVAL
+
MODULE = MIME::Base64 PACKAGE = MIME::QuotedPrint
diff --git a/cpan/MIME-Base64/Changes b/cpan/MIME-Base64/Changes
index 595c8dc0c9..a6f85bd8fd 100644
--- a/cpan/MIME-Base64/Changes
+++ b/cpan/MIME-Base64/Changes
@@ -1,3 +1,12 @@
+2010-10-11 Gisle Aas <gisle@ActiveState.com>
+
+ Release 3.10
+
+ Provide functions to calculate the length of encoded and decoded
+ base64 strings [RT#62404]
+
+
+
2010-01-25 Gisle Aas <gisle@ActiveState.com>
Release 3.09
diff --git a/cpan/MIME-Base64/Makefile.PL b/cpan/MIME-Base64/Makefile.PL
index 7300447690..8307d2c318 100644
--- a/cpan/MIME-Base64/Makefile.PL
+++ b/cpan/MIME-Base64/Makefile.PL
@@ -10,4 +10,36 @@ WriteMakefile(
NAME => 'MIME::Base64',
VERSION_FROM => 'Base64.pm',
@makefileopts,
+
+ ABSTRACT => 'The RFC 2045 encodings; base64 and quoted-printable',
+ AUTHOR => 'Gisle Aas <gisle@activestate.com>',
+ LICENSE => 'perl',
+ MIN_PERL_VERSION => 5.006,
+ META_MERGE => {
+ resources => {
+ repository => 'http://github.com/gisle/mime-base64',
+ }
+ },
);
+
+BEGIN {
+ # compatibility with older versions of MakeMaker
+ my $developer = -d ".git";
+ my %mm_req = (
+ LICENCE => 6.31,
+ META_MERGE => 6.45,
+ META_ADD => 6.45,
+ MIN_PERL_VERSION => 6.48,
+ );
+ undef(*WriteMakefile);
+ *WriteMakefile = sub {
+ my %arg = @_;
+ for (keys %mm_req) {
+ unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) {
+ warn "$_ $@" if $developer;
+ delete $arg{$_};
+ }
+ }
+ ExtUtils::MakeMaker::WriteMakefile(%arg);
+ };
+}
diff --git a/cpan/MIME-Base64/QuotedPrint.pm b/cpan/MIME-Base64/QuotedPrint.pm
index ca3a042edb..7b03e69e12 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.09";
+$VERSION = "3.10";
use MIME::Base64; # will load XS version of {en,de}code_qp()
diff --git a/cpan/MIME-Base64/t/length.t b/cpan/MIME-Base64/t/length.t
new file mode 100644
index 0000000000..116838a7bb
--- /dev/null
+++ b/cpan/MIME-Base64/t/length.t
@@ -0,0 +1,49 @@
+#!perl -w
+
+use strict;
+use Test qw(plan ok);
+
+plan tests => 129;
+
+use MIME::Base64 qw(encode_base64 encoded_base64_length decoded_base64_length);
+*elen = *encoded_base64_length;
+*dlen = *decoded_base64_length;
+
+ok(elen(""), 0);
+ok(elen("a"), 5);
+ok(elen("aa"), 5);
+ok(elen("aaa"), 5);
+ok(elen("aaaa"), 9);
+ok(elen("aaaaa"), 9);
+
+ok(elen("", ""), 0);
+ok(elen("a", ""), 4);
+ok(elen("aa", ""), 4);
+ok(elen("aaa", ""), 4);
+ok(elen("aaaa", ""), 8);
+ok(elen("aaaaa", ""), 8);
+
+ok(dlen(""), 0);
+ok(dlen("a"), 0);
+ok(dlen("aa"), 1);
+ok(dlen("aaa"), 2);
+ok(dlen("aaaa"), 3);
+ok(dlen("aaaaa"), 3);
+ok(dlen("aaaaaa"), 4);
+ok(dlen("aaaaaaa"), 5);
+ok(dlen("aaaaaaaa"), 6);
+
+ok(dlen("=aaaa"), 0);
+ok(dlen("a=aaa"), 0);
+ok(dlen("aa=aa"), 1);
+ok(dlen("aaa=a"), 2);
+ok(dlen("aaaa="), 3);
+
+ok(dlen("a\na\na a"), 3);
+
+for my $i (50..100) {
+ my $a = "a" x $i;
+ my $a_enc = encode_base64($a);
+ ok(elen($a), length($a_enc));
+ ok(dlen($a_enc), $i);
+}