File Coverage

blib/lib/Blockchain/Ethereum/Keystore/Keyfile/KDF.pm
Criterion Covered Total %
statement 55 61 90.1
branch n/a
condition n/a
subroutine 20 23 86.9
pod 0 17 0.0
total 75 101 74.2


line stmt bran cond sub pod time code
1 1     1   12 use v5.26;
  1         3  
2 1     1   5 use Object::Pad;
  1         4  
  1         6  
3              
4             package Blockchain::Ethereum::Keystore::Keyfile::KDF;
5             class Blockchain::Ethereum::Keystore::Keyfile::KDF;
6              
7             our $AUTHORITY = 'cpan:REFECO'; # AUTHORITY
8             our $VERSION = '0.006'; # VERSION
9              
10 1     1   808 use Crypt::KeyDerivation qw(pbkdf2);
  1         365  
  1         69  
11 1     1   487 use Crypt::ScryptKDF qw(scrypt_raw);
  1         2998  
  1         1516  
12              
13 2     2 0 5 field $algorithm :reader :writer :param;
  2     2 0 8  
  2         15  
  2         20  
14 2     2 0 6 field $dklen :reader :writer :param;
  2     2 0 825978  
  2         10  
  2         7  
15             field $n :reader :writer :param //= undef;
16 1     1 0 3 field $p :reader :writer :param //= undef;
  1     2 0 7  
  2         6  
  2         7  
17 1     1 0 3 field $r :reader :writer :param //= undef;
  1     2 0 5  
  2         8  
  2         20  
18 1     1 0 5 field $prf :reader :writer :param //= undef;
  1     2 0 6  
  2         8  
  2         7  
19 0     0 0 0 field $c :reader :writer :param //= undef;
  0     0 0 0  
  0         0  
  0         0  
20 1     1 0 2 field $salt :reader :writer :param;
  1     2 0 6  
  2     0 0 5  
  2     2 0 19  
  0         0  
  0         0  
  2         7  
  2         9  
21              
22 2     2 0 5 method decode ($password) {
  2         4  
  2         5  
  2         3  
23              
24 2         12 my $kdf_function = '_decode_kdf_' . $self->algorithm;
25 2         10 return $self->$kdf_function($password);
26             }
27              
28 1     1   3 method _decode_kdf_pbkdf2 ($password) {
  1         2  
  1         3  
  1         2  
29              
30 1         4 my $derived_key = pbkdf2($password, pack("H*", $self->salt), $self->c, 'SHA256', $self->dklen);
31              
32 1         27 return $derived_key;
33             }
34              
35 1     1   4 method _decode_kdf_scrypt ($password) {
  1         2  
  1         4  
  1         2  
36              
37 1         5 my $derived_key = scrypt_raw(
38             $password, #
39             pack("H*", $self->salt),
40             $self->n,
41             $self->r,
42             $self->p,
43             $self->dklen
44             );
45              
46 1         1799323 return $derived_key;
47             }
48              
49             1;
50              
51             __END__
52              
53             =pod
54              
55             =encoding UTF-8
56              
57             =head1 NAME
58              
59             Blockchain::Ethereum::Keystore::Keyfile::KDF
60              
61             =head1 VERSION
62              
63             version 0.006
64              
65             =head1 AUTHOR
66              
67             Reginaldo Costa <refeco@cpan.org>
68              
69             =head1 COPYRIGHT AND LICENSE
70              
71             This software is Copyright (c) 2023 by REFECO.
72              
73             This is free software, licensed under:
74              
75             The MIT (X11) License
76              
77             =cut