File Coverage

lib/Crypt/CBC/PBKDF/pbkdf2.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition 8 8 100.0
subroutine 5 5 100.0
pod 0 2 0.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Crypt::CBC::PBKDF::pbkdf2;
2 5     5   34 use strict;
  5         10  
  5         226  
3              
4 5     5   127 use base 'Crypt::CBC::PBKDF';
  5         11  
  5         845  
5 5     5   3010 use Crypt::PBKDF2;
  5         1239220  
  5         4938  
6              
7             our $VERSION = '3.07';
8             # options:
9             # key_len => 32 default
10             # iv_len => 16 default
11             # iterations => 10000 default
12             # hash_class => 'HMACSHA2' default
13              
14             sub create {
15 123     123 0 283 my $class = shift;
16 123         616 my %options = @_;
17 123   100     503 $options{key_len} ||= 32;
18 123   100     506 $options{iv_len} ||= 16;
19 123   100     507 $options{iterations} ||= 10_000;
20 123   100     972 $options{hash_class} ||= 'HMACSHA2';
21 123         1268 return bless \%options,$class;
22             }
23              
24             sub generate_hash {
25 122     122 0 200 my $self = shift;
26 122         447 my ($salt,$passphrase) = @_;
27             my $pbkdf2 = Crypt::PBKDF2->new(%$self,
28 122         5784 output_len => $self->{key_len} + $self->{iv_len});
29 122         332711 return $pbkdf2->PBKDF2($salt,$passphrase);
30             }
31              
32             1;