| 1 | package App::OATH::Crypt; | ||||||||||||||||||||||||||||
| 2 | 1 | our $VERSION = '1.20260324'; # VERSION | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use App::OATH::Crypt::Rijndael; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use App::OATH::Crypt::CBC; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use String::Random qw{ random_string }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 0 | my ( $class, $password ) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | my $self = { | |||||||||||||||||||||||||||
| 15 | 'workers' => { | ||||||||||||||||||||||||||||
| 16 | 'rijndael' => App::OATH::Crypt::Rijndael->new({ 'password' => $password }), | ||||||||||||||||||||||||||||
| 17 | 'cbcrijndael' => App::OATH::Crypt::CBC->new({ 'password' => $password, 'type' => 'Rijndael', }), | ||||||||||||||||||||||||||||
| 18 | 'cbcblowfish' => App::OATH::Crypt::CBC->new({ 'password' => $password, 'type' => 'Blowfish', }), | ||||||||||||||||||||||||||||
| 19 | }, | ||||||||||||||||||||||||||||
| 20 | 'type' => q{}, | ||||||||||||||||||||||||||||
| 21 | 'check' => 'oath', | ||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 24 | 0 | return $self; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub get_workers_list { | ||||||||||||||||||||||||||
|
Subroutine
get_workers_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 29 | 0 | my @list = sort keys %{ $self->{'workers'} }; | |||||||||||||||||||||||||||
| 30 | 0 | return \@list; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub set_worker { | ||||||||||||||||||||||||||
|
Subroutine
set_worker: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 0 | my ( $self, $type ) = @_; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( $type ne q{} and not exists( $self->{'workers'}->{$type} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type ne "" and not exists $self->{"workers"}{$type}
MC/DC0%0/2
$type ne "" and not exists $self->{"workers"}{$type}
$type ne ""
not exists $self->{"workers"}{$type}
Truth table0%0/3
A and not(B)
A= $type ne ""B= not exists $self->{"workers"}{$type}
| |||||||||||||||||||||||||||||
| 36 | 0 | die "Unknown encryption type $type"; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | $self->{'type'} = $type; | |||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub encrypt { | ||||||||||||||||||||||||||
|
Subroutine
encrypt: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | my ( $self, $data ) = @_; | |||||||||||||||||||||||||||
| 44 | 0 | my $type = $self->{'type'}; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | $type = 'cbcrijndael' if $type eq q{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | my $worker = $self->{'workers'}->{$type}; | |||||||||||||||||||||||||||
| 47 | 0 | my $u = random_string( '..........' ) . ' ' . $self->{'check'} . ' ' . $data; | |||||||||||||||||||||||||||
| 48 | 0 | return $type . ':' . $worker->encrypt( $u ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub decrypt { | ||||||||||||||||||||||||||
|
Subroutine
decrypt: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 0 | my ( $self, $data ) = @_; | |||||||||||||||||||||||||||
| 53 | 0 | my $type = $self->{'type'}; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | $type = 'rijndael' if $type eq q{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( $data =~ /:/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | ( $type, $data ) = split ':', $data; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 0 | my $worker = $self->{'workers'}->{$type}; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | die "Unknown encryption type $type" if ! $worker; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | my $u = $worker->decrypt( $data ); | |||||||||||||||||||||||||||
| 61 | 0 | my ( $salt, $check, $payload ) = split( ' ', $u ); | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | $check = q{} if ! $check; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( $check ne $self->{'check'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | return; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | return $payload; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||