File Coverage

blib/lib/CGI/Application/Plugin/Authentication/Driver/Filter/sha1.pm
Criterion Covered Total %
statement 27 27 100.0
branch 22 22 100.0
condition 2 2 100.0
subroutine 5 5 100.0
pod 2 2 100.0
total 58 58 100.0


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authentication::Driver::Filter::sha1;
2             $CGI::Application::Plugin::Authentication::Driver::Filter::sha1::VERSION = '0.21';
3 3     3   2347 use strict;
  3         5  
  3         112  
4 3     3   14 use warnings;
  3         5  
  3         109  
5              
6 3     3   387 use UNIVERSAL::require;
  3         929  
  3         28  
7              
8             sub check {
9 12     12 1 15 my $class = shift;
10 12         13 my $param = shift;
11 12         10 my $plain = shift;
12 12         10 my $filtered = shift;
13              
14 12 100       24 if ($param) {
    100          
    100          
15 6 100       11 return ( $class->filter( $param, $plain ) eq $filtered ) ? 1 : 0;
16             } elsif ( length($filtered) == 20 ) {
17 2 100       5 return ( $class->filter( 'binary', $plain ) eq $filtered ) ? 1 : 0;
18             } elsif ( length($filtered) == 27 ) {
19 2 100       4 return ( $class->filter( 'base64', $plain ) eq $filtered ) ? 1 : 0;
20             } else {
21 2 100       4 return ( $class->filter( undef, $plain ) eq $filtered ) ? 1 : 0;
22             }
23             }
24              
25             sub filter {
26 18     18 1 458 my $class = shift;
27 18   100     55 my $param = lc (shift || 'hex');
28 18         14 my $plain = shift;
29              
30 18 100       69 Digest::SHA->require || die "Digest::SHA is required to check SHA1 passwords";
31 17 100       455 if ( $param eq 'hex' ) {
    100          
    100          
32 6         44 return Digest::SHA::sha1_hex($plain);
33             } elsif ( $param eq 'base64' ) {
34 5         42 return Digest::SHA::sha1_base64($plain);
35             } elsif ( $param eq 'binary' ) {
36 5         38 return Digest::SHA::sha1($plain);
37             }
38 1         10 die "Unknown SHA1 format $param";
39             }
40              
41             1;
42             __END__