File Coverage

lib/Digest/PBKDF2.pm
Criterion Covered Total %
statement 40 40 100.0
branch 3 4 75.0
condition 4 6 66.6
subroutine 10 10 100.0
pod 5 5 100.0
total 62 65 95.3


line stmt bran cond sub pod time code
1             package Digest::PBKDF2;
2              
3 1     1   785 use strict;
  1         2  
  1         30  
4 1     1   6 use warnings;
  1         2  
  1         34  
5 1     1   466 use parent "Digest::base";
  1         315  
  1         5  
6 1     1   609 use Crypt::PBKDF2 0.161520;
  1         156675  
  1         58  
7              
8             BEGIN {
9 1     1   392 our $VERSION = '0.013'; # VERSION
10             }
11              
12             #ABSTRACT: This module is a subclass of Digest using the Crypt::PBKDF2 algorithm.
13              
14             sub new {
15 2     2 1 75590 my ( $class, %params ) = @_;
16 2   50     21 my $encoding = $params{encoding} || 'crypt';
17 2         19 return bless { _entries => [], _data => undef, encoding => $encoding }, $class;
18             }
19              
20             sub clone {
21 2     2 1 820 my $self = shift;
22             my $clone = {
23             _data => $self->{_data},
24             _entries => $self->{_entries},
25             encoding => $self->{encoding},
26 2         19 };
27 2         17 return bless $clone, ref $self;
28             }
29              
30             sub add {
31 4     4 1 5247 my $self = shift;
32 4 50       15 if (@_) {
33 4         8 push @{ $self->{_entries} }, join '', @_;
  4         20  
34 4         15 $self->{_data} .= join '', @_;
35             }
36 4         16 $self;
37             }
38              
39             sub reset {
40 4     4 1 9 my $self = shift;
41 4         11 delete $self->{_data};
42 4         11 delete $self->{_entries};
43 4         7 delete $self->{encoding};
44 4         7 $self;
45             }
46              
47             sub digest {
48 4     4 1 1180 my $self = shift;
49 4         22 my @string = split '', $self->{_data};
50              
51 4         7 my $salt;
52              
53             $salt = join( '', splice( @string, 0, length( $self->{_entries}->[0] ) ) )
54 4 100       9 if @{ $self->{_entries} } > 1;
  4         23  
55 4         12 my $data = join( '', @string );
56              
57 4   50     127 my $crypt = Crypt::PBKDF2->new( encoding => ($self->{encoding}||'ldap'), salt_len => length($salt||'') );
      100        
58 4         2023 my $return = $crypt->generate( $data, $salt );
59 4         36155 $self->reset;
60 4         36 $return;
61             }
62              
63             1;
64              
65             __END__