|
Revision 484
(checked in by miyagawa, 6 years ago)
|
oops, forgot to svk add. Refs #91
|
| Line | |
|---|
| 1 |
package Plagger::Crypt; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use Module::Pluggable::Fast |
|---|
| 4 |
search => [ qw/Plagger::Crypt/ ], |
|---|
| 5 |
require => 1; |
|---|
| 6 |
|
|---|
| 7 |
my %handlers = map { $_->id => $_ } __PACKAGE__->plugins; |
|---|
| 8 |
my $re = "^(" . join("|", map $_->id, __PACKAGE__->plugins) . ")::"; |
|---|
| 9 |
|
|---|
| 10 |
sub decrypt { |
|---|
| 11 |
my($class, $ciphertext, @args) = @_; |
|---|
| 12 |
|
|---|
| 13 |
if ($ciphertext =~ s!$re!!) { |
|---|
| 14 |
my $handler = $handlers{$1}; |
|---|
| 15 |
my @param = split /::/, $ciphertext; |
|---|
| 16 |
return $handler->decrypt(@param, @args); |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
return $ciphertext; |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
sub encrypt { |
|---|
| 23 |
my($class, $plaintext, $driver, @param) = @_; |
|---|
| 24 |
my $handler = $handlers{$driver} |
|---|
| 25 |
or Plagger->context->error("No crypt handler for $driver"); |
|---|
| 26 |
join '::', $driver, $handler->encrypt($plaintext, @param); |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
1; |
|---|