r16921 - in /branches/upstream/libcrypt-simple-perl: ./ current/ current/t/

morph-guest at users.alioth.debian.org morph-guest at users.alioth.debian.org
Sat Mar 8 18:12:38 UTC 2008


Author: morph-guest
Date: Sat Mar  8 18:12:38 2008
New Revision: 16921

URL: http://svn.debian.org/wsvn/?sc=1&rev=16921
Log:
[svn-inject] Installing original source of libcrypt-simple-perl

Added:
    branches/upstream/libcrypt-simple-perl/
    branches/upstream/libcrypt-simple-perl/current/
    branches/upstream/libcrypt-simple-perl/current/MANIFEST
    branches/upstream/libcrypt-simple-perl/current/Makefile.PL
    branches/upstream/libcrypt-simple-perl/current/README
    branches/upstream/libcrypt-simple-perl/current/Simple.pm
    branches/upstream/libcrypt-simple-perl/current/t/
    branches/upstream/libcrypt-simple-perl/current/t/complex.t
    branches/upstream/libcrypt-simple-perl/current/t/file.t
    branches/upstream/libcrypt-simple-perl/current/t/multi.t
    branches/upstream/libcrypt-simple-perl/current/t/passfile.t
    branches/upstream/libcrypt-simple-perl/current/t/passphrase.t
    branches/upstream/libcrypt-simple-perl/current/t/single.t

Added: branches/upstream/libcrypt-simple-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/MANIFEST?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/MANIFEST (added)
+++ branches/upstream/libcrypt-simple-perl/current/MANIFEST Sat Mar  8 18:12:38 2008
@@ -1,0 +1,10 @@
+MANIFEST			This list of files
+Makefile.PL
+README
+Simple.pm
+t/complex.t
+t/file.t
+t/multi.t
+t/passfile.t
+t/passphrase.t
+t/single.t

Added: branches/upstream/libcrypt-simple-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/Makefile.PL?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/Makefile.PL (added)
+++ branches/upstream/libcrypt-simple-perl/current/Makefile.PL Sat Mar  8 18:12:38 2008
@@ -1,0 +1,12 @@
+use ExtUtils::MakeMaker;
+WriteMakefile(
+    'NAME'		=> 'Crypt::Simple',
+    'VERSION_FROM'	=> 'Simple.pm',
+    'PREREQ_PM'		=> {
+                         'Crypt::Blowfish' => 2.06,
+                         'Compress::Zlib' => 1.11,
+                         'MIME::Base64' => 2.11,
+                         'Digest::MD5' => 2.13,
+                         'FreezeThaw' => 0.41,
+                       },
+);

Added: branches/upstream/libcrypt-simple-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/README?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/README (added)
+++ branches/upstream/libcrypt-simple-perl/current/README Sat Mar  8 18:12:38 2008
@@ -1,0 +1,57 @@
+DESCRIPTION
+    Maybe you have a web application and you need to store some session data
+    at the client side (in a cookie or hidden form fields) but you don't
+    want the user to be able to mess with the data. Maybe you want to save
+    secret information to a text file. Maybe you have better ideas of what
+    to do with encrypted stuff!
+
+    This little module will convert all your data into nice base64 text that
+    you can save in a text file, send in an email, store in a cookie or web
+    page, or bounce around the Net. The data you encrypt can be as simple or
+    as complicated as you like.
+
+CHANGES
+    Version 0.05 had a few missing subroutine bodies, so quite a few things
+    didn't work!  I'm now practising what I preach, and have written some tests!
+
+INTERNALS
+    "Crypt::Simple" is really just a wrapper round a few other useful Perl
+    modules: you may want to read the documentation for these modules too.
+
+    We use "FreezeThaw" to squish all your data into a concise textual
+    representation. We use "Compress::Zlib" to compress this string, and
+    then use "Crypt::Blowfish" in a home-brew CBC mode to perform the
+    encryption. Somewhere in this process we also add a MD5 digest (using
+    "Digest::MD5"). Then we throw the whole thing through "MIME::Base64" to
+    produce a nice bit of text for you to play with.
+
+    Decryption, obviously, is the reverse of this process.
+
+WARNING
+    Governments throughout the world do not like encryption because it makes
+    it difficult for them to look at all your stuff. Each country has a
+    different policy designed to stop you using encryption: some governments
+    are honest enough to make it illegal; some think it is a dangerous
+    weapon; some insist that you are free to encrypt, but only evil people
+    would want to; some make confusing and contradictory laws because they
+    try to do all of the above.
+
+    Although this modules itself does not include any encryption code, it
+    does use another module that contains encryption code, and this
+    documentation mentions encryption. Downloading, using, or reading this
+    modules could be illegal where you live.
+
+AUTHOR
+    Marty Pauley <marty at kasei.com>
+
+COPYRIGHT
+      Copyright (C) 2001 Kasei Limited
+
+      This program is free software; you can redistribute it and/or modify it under
+      the terms of the GNU General Public License; either version 2 of the License,
+      or (at your option) any later version.
+
+      This program is distributed in the hope that it will be useful, but WITHOUT
+      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+      FOR A PARTICULAR PURPOSE.
+

Added: branches/upstream/libcrypt-simple-perl/current/Simple.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/Simple.pm?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/Simple.pm (added)
+++ branches/upstream/libcrypt-simple-perl/current/Simple.pm Sat Mar  8 18:12:38 2008
@@ -1,0 +1,207 @@
+package Crypt::Simple;
+$Crypt::Simple::VERSION = '0.06';
+
+=head1 NAME
+
+Crypt::Simple - encrypt stuff simply
+
+=head1 SYNOPSIS
+
+  use Crypt::Simple;
+  
+  my $data = encrypt(@stuff);
+
+  my @same_stuff = decrypt($data);
+
+=head1 DESCRIPTION
+
+Maybe you have a web application and you need to store some session data at the
+client side (in a cookie or hidden form fields) but you don't want the user to
+be able to mess with the data.  Maybe you want to save secret information to a
+text file.  Maybe you have better ideas of what to do with encrypted stuff!
+
+This little module will convert all your data into nice base64 text that you
+can save in a text file, send in an email, store in a cookie or web page, or
+bounce around the Net.  The data you encrypt can be as simple or as complicated
+as you like.
+
+=head1 KEY
+
+If you don't pass any options when using C<Crypt::Simple> we will generate a key
+for you based on the name of your module that uses this one.  In many cases this
+works fine, but you may want more control over the key.  Here's how:
+
+=over 4
+
+=item use Crypt::Simple passphrase => 'pass phrase';
+
+The MD5 hash of the text string "pass phrase" is used as the key.
+
+=item use Crypt::Simple prompt => 'Please type the magic words';
+
+The user is prompted to enter a passphrase, and the MD5 hash of the entered text
+is used as the key.
+
+=item use Crypt::Simple passfile => '/home/marty/secret';
+
+The contents of the file /home/marty/secret are used as the pass phrase: the MD5
+hash of the file is used as the key.
+
+=item use Crypt::Simple file => '/home/marty/noise';
+
+The contents of the file /home/marty/noise are directly used as the key.
+
+=back
+
+=head1 INTERNALS
+
+C<Crypt::Simple> is really just a wrapper round a few other useful Perl
+modules: you may want to read the documentation for these modules too.
+
+We use C<FreezeThaw> to squish all your data into a concise textual
+representation.  We use C<Compress::Zlib> to compress this string, and then use
+C<Crypt::Blowfish> in a home-brew CBC mode to perform the encryption.
+Somewhere in this process we also add a MD5 digest (using C<Digest::MD5>).
+Then we throw the whole thing through C<MIME::Base64> to produce a nice bit of
+text for you to play with.
+
+Decryption, obviously, is the reverse of this process.
+
+=head1 WARNING
+
+Governments throughout the world do not like encryption because it makes it
+difficult for them to look at all your stuff.  Each country has a different
+policy designed to stop you using encryption: some governments are honest enough
+to make it illegal; some think it is a dangerous weapon; some insist that you
+are free to encrypt, but only evil people would want to; some make confusing and
+contradictory laws because they try to do all of the above.
+
+Although this modules itself does not include any encryption code, it does use
+another module that contains encryption code, and this documentation mentions
+encryption.  Downloading, using, or reading this modules could be illegal where
+you live.
+
+=head1 AUTHOR
+
+Marty Pauley E<lt>marty at kasei.comE<gt>
+
+=head1 COPYRIGHT
+
+  Copyright (C) 2001 Kasei Limited
+
+  This program is free software; you can redistribute it and/or modify it under
+  the terms of the GNU General Public License; either version 2 of the License,
+  or (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+  FOR A PARTICULAR PURPOSE.
+
+=cut
+
+use strict;
+use Carp;
+use Crypt::Blowfish;
+use Compress::Zlib;
+use MIME::Base64;
+use Digest::MD5 qw(md5);
+use FreezeThaw qw(freeze thaw);
+
+sub _chunk($) { $_[0] =~ /.{1,8}/ogs }
+
+sub import {
+	my ($class, @args) = @_;
+	my $caller = caller;
+	my $key = $class->get_key_param(@args)
+		|| $class->get_key_default($caller);
+	my $cipher = Crypt::Blowfish->new($key);
+
+	no strict 'refs';
+	*{"${caller}::encrypt"} = sub {
+		my $data = freeze(@_);
+		my $sig = md5($data);
+		my $b0 = pack('NN', 0, 0);
+		my $ct = '';
+		foreach my $block (_chunk($sig.compress($data))) {
+			$ct .= $b0 = $cipher->encrypt($b0 ^ $block);
+		}
+		return encode_base64($ct, '');
+	};
+	*{"${caller}::decrypt"} = sub {
+		my $data = decode_base64($_[0]);
+		my ($sig1, $sig2, @blocks) = _chunk($data);
+		my $b0 = pack('NN', 0, 0);
+		my $sig = $b0 ^ $cipher->decrypt($sig1);
+		$b0 = $sig1;
+		$sig .= $b0 ^ $cipher->decrypt($sig2);
+		$b0 = $sig2;
+		my $pt = '';
+		foreach my $block (@blocks) {
+			$pt .= $b0 ^ $cipher->decrypt($block);
+			$b0 = $block;
+		}
+		my $result = uncompress($pt);
+		croak "message digest incorrect" unless $sig eq md5($result);
+		my @data = thaw($result);
+		return wantarray ? @data : $data[0];
+	};
+
+      1;
+}
+
+sub get_key_param {
+	my ($class, @p) = @_;
+	return md5($p[0]) if @p == 1;
+	my %p = @p;
+	my $key = '';
+	foreach my $k ($class->get_key_methods) {
+		next unless exists $p{$k};
+		if (my $m = $class->can("key_from_$k")) {
+			$key = $class->$m($p{$k});
+			last if $key;
+		}
+	}
+	return $key;
+}
+
+sub get_key_default {
+	my ($class, $c) = @_;
+	return md5("$class,$c");
+}
+
+sub get_key_methods { qw{passphrase passfile file prompt} }
+
+sub key_from_passphrase {
+	my ($class, $pass) = @_;
+	return md5($pass);
+}
+
+sub read_file_contents {
+	my ($class, $file) = @_;
+	open my $io, $file or croak "cannot open $file: $!";
+	local $/;
+	my $data = <$io>;
+	close $io;
+	return $data;
+}
+
+sub key_from_passfile {
+	my ($class, $file) = @_;
+	my $pass = $class->read_file_contents($file);
+	return $class->key_from_passphrase($pass);
+}
+
+sub key_from_file {
+	my ($class, $file) = @_;
+	return $class->read_file_contents($file);
+}
+
+sub key_from_prompt {
+	my ($class, $prompt) = @_;
+	print STDERR "$prompt: ";
+	my $pass = <STDIN>;
+	chomp $pass;
+	return $class->key_from_passphrase($pass);
+}
+
+1;

Added: branches/upstream/libcrypt-simple-perl/current/t/complex.t
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/t/complex.t?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/t/complex.t (added)
+++ branches/upstream/libcrypt-simple-perl/current/t/complex.t Sat Mar  8 18:12:38 2008
@@ -1,0 +1,13 @@
+#!/usr/bin/perl -w
+use strict;
+use Test;
+
+plan tests => 2;
+
+use Crypt::Simple;
+
+my $r = bless {foo=>'bar'}, "thingie";
+my $e = encrypt($r);
+my $r2 = decrypt($e);
+ok($r->isa("thingie"));
+ok($r->{foo} eq 'bar');

Added: branches/upstream/libcrypt-simple-perl/current/t/file.t
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/t/file.t?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/t/file.t (added)
+++ branches/upstream/libcrypt-simple-perl/current/t/file.t Sat Mar  8 18:12:38 2008
@@ -1,0 +1,57 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+file.t - test
+
+=head1 DESCRIPTION
+
+Check we can use the 'file' option.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+
+sub make_tmpfile {
+	my ($file, $data) = @_;
+	open my $io, ">$file" or return;
+	print {$io} $data;
+	close $io;
+}
+
+make_tmpfile(foo => "abcdefgh");
+make_tmpfile(bar => "zyxwvuts");
+make_tmpfile(baz => "abcdefgh");
+END { unlink qw/foo bar baz/ }
+
+require_ok('Crypt::Simple');
+
+{
+	package Foo;
+	Crypt::Simple->import(file => "foo");
+}
+
+{
+	package Bar;
+	Crypt::Simple->import(file => "bar");
+}
+
+{
+	package Baz;
+	Crypt::Simple->import(file => "baz");
+}
+
+my $plaintext = "hello world";
+my $footext = Foo::encrypt($plaintext);
+my $bartext = Bar::encrypt($plaintext);
+my $baztext = Baz::encrypt($plaintext);
+
+isnt $footext, $bartext, "Foo and Bar are different";
+is $footext, $baztext, "Foo and Baz are the same";
+is Foo::decrypt($footext), $plaintext, "Foo encryption";
+is Bar::decrypt($bartext), $plaintext, "Bar encryption";
+is Baz::decrypt($baztext), $plaintext, "Baz encryption";
+

Added: branches/upstream/libcrypt-simple-perl/current/t/multi.t
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/t/multi.t?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/t/multi.t (added)
+++ branches/upstream/libcrypt-simple-perl/current/t/multi.t Sat Mar  8 18:12:38 2008
@@ -1,0 +1,18 @@
+#!/usr/bin/perl -w
+use strict;
+use Test;
+
+plan tests => 6;
+
+use Crypt::Simple;
+
+my @plain = qw/this is a test/;
+my $ciphertext = encrypt(@plain);
+
+ok($ciphertext);
+
+my @out = decrypt($ciphertext);
+ok(scalar @plain == scalar @out);
+for (my $i=0; $i<@plain; ++$i) {
+	ok($plain[$i] eq $out[$i]);
+}

Added: branches/upstream/libcrypt-simple-perl/current/t/passfile.t
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/t/passfile.t?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/t/passfile.t (added)
+++ branches/upstream/libcrypt-simple-perl/current/t/passfile.t Sat Mar  8 18:12:38 2008
@@ -1,0 +1,57 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+passfile.t - test
+
+=head1 DESCRIPTION
+
+Check we can use the 'passfile' option.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+
+sub make_tmpfile {
+	my ($file, $data) = @_;
+	open my $io, ">$file" or return;
+	print {$io} $data;
+	close $io;
+}
+
+make_tmpfile(foo => "qwerty");
+make_tmpfile(bar => "asdfgh");
+make_tmpfile(baz => "qwerty");
+END { unlink qw/foo bar baz/ }
+
+require_ok('Crypt::Simple');
+
+{
+	package Foo;
+	Crypt::Simple->import(passfile => "foo");
+}
+
+{
+	package Bar;
+	Crypt::Simple->import(passfile => "bar");
+}
+
+{
+	package Baz;
+	Crypt::Simple->import(passfile => "baz");
+}
+
+my $plaintext = "hello world";
+my $footext = Foo::encrypt($plaintext);
+my $bartext = Bar::encrypt($plaintext);
+my $baztext = Baz::encrypt($plaintext);
+
+isnt $footext, $bartext, "Foo and Bar are different";
+is $footext, $baztext, "Foo and Baz are the same";
+is Foo::decrypt($footext), $plaintext, "Foo encryption";
+is Bar::decrypt($bartext), $plaintext, "Bar encryption";
+is Baz::decrypt($baztext), $plaintext, "Baz encryption";
+

Added: branches/upstream/libcrypt-simple-perl/current/t/passphrase.t
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/t/passphrase.t?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/t/passphrase.t (added)
+++ branches/upstream/libcrypt-simple-perl/current/t/passphrase.t Sat Mar  8 18:12:38 2008
@@ -1,0 +1,45 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+passphrase.t - test
+
+=head1 DESCRIPTION
+
+Check we can use the 'passphrase' option.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+
+require_ok('Crypt::Simple');
+
+{
+	package Foo;
+	Crypt::Simple->import(passphrase => "qwerty");
+}
+
+{
+	package Bar;
+	Crypt::Simple->import(passphrase => "asdfg");
+}
+
+{
+	package Baz;
+	Crypt::Simple->import(passphrase => "qwerty");
+}
+
+my $plaintext = "hello world";
+my $footext = Foo::encrypt($plaintext);
+my $bartext = Bar::encrypt($plaintext);
+my $baztext = Baz::encrypt($plaintext);
+
+isnt $footext, $bartext, "Foo and Bar are different";
+is $footext, $baztext, "Foo and Baz are the same";
+is Foo::decrypt($footext), $plaintext, "Foo encryption";
+is Bar::decrypt($bartext), $plaintext, "Bar encryption";
+is Baz::decrypt($baztext), $plaintext, "Baz encryption";
+

Added: branches/upstream/libcrypt-simple-perl/current/t/single.t
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-simple-perl/current/t/single.t?rev=16921&op=file
==============================================================================
--- branches/upstream/libcrypt-simple-perl/current/t/single.t (added)
+++ branches/upstream/libcrypt-simple-perl/current/t/single.t Sat Mar  8 18:12:38 2008
@@ -1,0 +1,18 @@
+#!/usr/bin/perl -w
+use strict;
+use Test;
+
+plan tests => 5;
+
+use Crypt::Simple;
+
+my $plaintext = "A message before encryption or after decryption";
+my $ciphertext = encrypt($plaintext);
+my $nonsense = "Hello World!";
+
+ok($ciphertext);
+ok($ciphertext ne encrypt($nonsense));
+ok($ciphertext eq encrypt($plaintext));
+ok($plaintext eq decrypt($ciphertext));
+eval { decrypt('VGhpcyBpcyBhIHRlc3Q=') };
+ok($@);




More information about the Pkg-perl-cvs-commits mailing list