| 1 | use strict; | ||
| 2 | |||
| 3 | use CGI::EncryptForm; | ||
| 4 | |||
| 5 | package HTML::EP::CGIEncryptForm; | ||
| 6 | $HTML::EP::CGIEncryptForm::VERSION = '1.00'; | ||
| 7 | @HTML::EP::CGIEncryptForm::ISA = 'HTML::EP'; | ||
| 8 | |||
| 9 | sub _handle { | ||
| 10 | my $self = shift; my $attr = shift; | ||
| 11 | return $self->{'_ep_cgiencryptform_handle'} if exists | ||
| 12 | $self->{'_ep_cgiencryptform_handle'}; | ||
| 13 | my $cfo = $self->{'_ep_cgiencryptform_handle'} = | ||
| 14 | CGI::EncryptForm->new(); | ||
| 15 | $cfo->secret_key($attr->{'secret_key'}) if exists $attr->{'secret_key'}; | ||
| 16 | $cfo->usecharset($attr->{'usecharset'}) if exists $attr->{'usecharset'}; | ||
| 17 | $cfo->charset($attr->{'charset'}) if exists $attr->{'charset'}; | ||
| 18 | $cfo; | ||
| 19 | } | ||
| 20 | |||
| 21 | sub _ep_cef_encrypt { | ||
| 22 | my($self, $attr) = @_; | ||
| 23 | |||
| 24 | my $dest = $attr->{'dest'}; | ||
| 25 | my $source = $attr->{'source'}; | ||
| 26 | die "Missing attribute 'source' (Source Hash Reference Variable)" | ||
| 27 | unless defined $source; | ||
| 28 | $source = ref($source) ? $source : | ||
| 29 | ($source =~ /^(\w+)((?:\-\>\w+)+)$/) ? | ||
| 30 | $self->FindVar($1, $2) : $self->{$source}; | ||
| 31 | |||
| 32 | my $cfo = $self->_handle($attr); | ||
| 33 | my $output = $cfo->encrypt($source) || die $cfo->error(); | ||
| 34 | if ($dest) { | ||
| 35 | $self->{$dest} = $output; | ||
| 36 | ''; | ||
| 37 | } else { | ||
| 38 | $output; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | sub _ep_cef_decrypt { | ||
| 43 | my($self, $attr) = @_; | ||
| 44 | |||
| 45 | my $dest = $attr->{'dest'}; | ||
| 46 | my $source = $attr->{'source'}; | ||
| 47 | die "Missing attribute 'source' (Source String Variable)" | ||
| 48 | unless defined $source; | ||
| 49 | $source = ref($source) ? $source : | ||
| 50 | ($source =~ /^(\w+)((?:\-\>\w+)+)$/) ? | ||
| 51 | $self->FindVar($1, $2) : $self->{$source}; | ||
| 52 | |||
| 53 | my $debug = $self->{'debug'}; | ||
| 54 | my $cfo = $self->_handle($attr); | ||
| 55 | |||
| 56 | my $output = $cfo->decrypt($source) || die $cfo->error(); | ||
| 57 | if ($dest) { | ||
| 58 | $self->{$dest} = $output; | ||
| 59 | ''; | ||
| 60 | } else { | ||
| 61 | $output; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | __END__ |