summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-12-18 21:49:15 -0600
committerJesse Luehrs <doy@tozt.net>2010-12-18 21:49:15 -0600
commitd08b2c500cf3bee23ba5d559fd471b5bd7a14347 (patch)
treef0bd880baeb2ddcec0bb54811197cd650815a967
parentbe2f916082f7f3f2176bbc533ce03d55999fbae2 (diff)
downloadkiokudb-serializer-crypt-d08b2c500cf3bee23ba5d559fd471b5bd7a14347.tar.gz
kiokudb-serializer-crypt-d08b2c500cf3bee23ba5d559fd471b5bd7a14347.zip
initial implementation
-rw-r--r--dist.ini3
-rw-r--r--lib/KiokuDB/Serializer/Crypt.pm61
-rw-r--r--lib/KiokuDB/Serializer/JSON/Crypt.pm11
3 files changed, 75 insertions, 0 deletions
diff --git a/dist.ini b/dist.ini
index 4924b04..c628b9b 100644
--- a/dist.ini
+++ b/dist.ini
@@ -7,3 +7,6 @@ copyright_holder = Jesse Luehrs
dist = KiokuDB-Serializer-Crypt
[Prereq]
+Crypt::Util = 0
+KiokuDB = 0
+namespace::autoclean = 0
diff --git a/lib/KiokuDB/Serializer/Crypt.pm b/lib/KiokuDB/Serializer/Crypt.pm
index e69de29..b125a48 100644
--- a/lib/KiokuDB/Serializer/Crypt.pm
+++ b/lib/KiokuDB/Serializer/Crypt.pm
@@ -0,0 +1,61 @@
+package KiokuDB::Serializer::Crypt;
+use Moose::Role;
+use namespace::autoclean;
+
+use Crypt::Util;
+
+has crypt_key => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+);
+
+has crypt_cipher => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'Rijndael',
+);
+
+has crypt_mode => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+ default => 'CFB',
+);
+
+has crypt => (
+ is => 'ro',
+ isa => 'Crypt::Util',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ return Crypt::Util->new(
+ disable_fallback => 1,
+ default_cipher => $self->crypt_cipher,
+ default_mode => $self->crypt_mode,
+ default_key => $self->crypt_key,
+ );
+ },
+ handles => ['encrypt_string', 'decrypt_string'],
+);
+
+around serialize => sub {
+ my $orig = shift;
+ my $self = shift;
+ my (@args) = @_;
+
+ my $collapsed = $self->$orig(@args);
+ return $self->encrypt_string($collapsed);
+};
+
+around deserialize => sub {
+ my $orig = shift;
+ my $self = shift;
+ my ($collapsed, @args) = @_;
+
+ return $self->$orig($self->decrypt_string($collapsed), @args);
+};
+
+no Moose::Role;
+
+1;
diff --git a/lib/KiokuDB/Serializer/JSON/Crypt.pm b/lib/KiokuDB/Serializer/JSON/Crypt.pm
new file mode 100644
index 0000000..d58fd17
--- /dev/null
+++ b/lib/KiokuDB/Serializer/JSON/Crypt.pm
@@ -0,0 +1,11 @@
+package KiokuDB::Serializer::JSON::Crypt;
+use Moose;
+use namespace::autoclean;
+
+extends 'KiokuDB::Serializer::JSON';
+with 'KiokuDB::Serializer::Crypt';
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;