File Coverage

blib/lib/Crypt/Passphrase/Pepper/Simple.pm
Criterion Covered Total %
statement 30 31 96.7
branch 3 8 37.5
condition 2 5 40.0
subroutine 9 9 100.0
pod 2 3 66.6
total 46 56 82.1


line stmt bran cond sub pod time code
1             package Crypt::Passphrase::Pepper::Simple;
2             $Crypt::Passphrase::Pepper::Simple::VERSION = '0.021';
3 2     2   138213 use strict;
  2         4  
  2         73  
4 2     2   9 use warnings;
  2         3  
  2         105  
5              
6 2     2   13 use parent 'Crypt::Passphrase::Pepper::Base';
  2         2  
  2         12  
7              
8 2     2   109 use Carp 'croak';
  2         5  
  2         125  
9 2     2   1073 use Digest::SHA;
  2         6952  
  2         316  
10              
11             my %algorithms = (
12             'sha1-hmac' => \&Digest::SHA::hmac_sha1,
13             'sha224-hmac' => \&Digest::SHA::hmac_sha224,
14             'sha256-hmac' => \&Digest::SHA::hmac_sha256,
15             'sha384-hmac' => \&Digest::SHA::hmac_sha384,
16             'sha512-hmac' => \&Digest::SHA::hmac_sha512,
17             );
18              
19             sub new {
20 1     1 0 4 my ($class, %args) = @_;
21              
22 1 50       6 my $peppers = $args{peppers} or croak('No peppers given');
23 2 0 33 2   17 $args{active} //= (sort {; no warnings 'numeric'; $b <=> $a || $b cmp $a } keys %{ $peppers })[0];
  2         30  
  2         632  
  1         8  
  0         0  
  1         6  
24 1   50     6 $args{algorithm} //= 'sha512-hmac';
25              
26 1         11 return $class->SUPER::new(%args);
27             }
28              
29             sub prehash_password {
30 2     2 1 8 my ($self, $password, $algorithm, $id) = @_;
31 2 50       9 my $secret = $self->{peppers}{$id} or croak "No such pepper $id";
32 2 50       6 my $func = $algorithms{$algorithm} or croak "No such algorithm $algorithm";
33 2         35 return $func->($password, $secret);
34             }
35              
36             sub supported_hashes {
37 1     1 1 2 my $self = shift;
38 1         8 return keys %algorithms;
39             }
40              
41             1;
42              
43             #ABSTRACT: A pepper-wrapper for Crypt::Passphrase
44              
45             __END__