line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Indigest::Crypt; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
79890
|
$Acme::Indigest::Crypt::VERSION = '0.0011'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Acme::Indigest::Crypt |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
904
|
use Crypt::Passwd::XS; |
|
1
|
|
|
|
|
434
|
|
|
1
|
|
|
|
|
391
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub digest { |
13
|
17
|
|
|
17
|
0
|
73
|
my $self = shift; |
14
|
17
|
|
|
|
|
25
|
my $passphrase = shift; |
15
|
17
|
|
|
|
|
41
|
my $salt_string = shift; |
16
|
17
|
|
100
|
|
|
80
|
my $rounds = shift || 0; |
17
|
17
|
50
|
|
|
|
98
|
die "--<<>>---+__-_-_---+<>\n" unless $rounds =~ m/^\d*$/; |
18
|
17
|
|
100
|
|
|
80
|
$rounds < $_ and $rounds = $_ for 10_000_000; |
19
|
|
|
|
|
|
|
|
20
|
17
|
100
|
|
|
|
51
|
$salt_string = '' unless defined $salt_string; |
21
|
17
|
|
|
|
|
27
|
my @salt; |
22
|
17
|
|
|
|
|
43
|
push @salt, '$6$'; |
23
|
17
|
50
|
|
|
|
59
|
push @salt, "rounds=$rounds\$" if $rounds; |
24
|
17
|
|
|
|
|
35
|
push @salt, "$salt_string\$"; |
25
|
|
|
|
|
|
|
|
26
|
17
|
|
|
|
|
180738296
|
return Crypt::Passwd::XS::unix_sha512_crypt( $passphrase, join '', @salt ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub parse_salt_string_rounds { |
30
|
17
|
|
|
17
|
0
|
7910
|
my $self = shift; |
31
|
17
|
|
|
|
|
36
|
my $salt_string = shift; |
32
|
17
|
|
|
|
|
29
|
my $rounds = shift; |
33
|
|
|
|
|
|
|
|
34
|
17
|
|
50
|
|
|
147
|
defined or $_ = '' for $salt_string; |
35
|
17
|
100
|
|
|
|
90
|
if ( $salt_string eq '' ) { undef $salt_string } |
|
10
|
50
|
|
|
|
23
|
|
36
|
0
|
|
|
|
|
0
|
elsif ( $salt_string eq '$' ) { $salt_string = '' } |
37
|
17
|
|
50
|
|
|
966
|
defined and $_ = eval "$_" for $rounds; |
38
|
|
|
|
|
|
|
|
39
|
17
|
|
|
|
|
69
|
return ( $salt_string, $rounds ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub digest_multiple { |
43
|
1
|
|
|
1
|
0
|
924
|
my $self = shift; |
44
|
1
|
|
|
|
|
2
|
my $input = shift; |
45
|
1
|
|
|
|
|
2
|
my $output = ""; |
46
|
1
|
|
|
|
|
11
|
for ( split m/\n+/, $input ) { |
47
|
6
|
|
|
|
|
31
|
chomp; |
48
|
6
|
50
|
|
|
|
47
|
next if m/^\s*#/; |
49
|
6
|
50
|
|
|
|
57
|
next unless m/\S/; |
50
|
6
|
|
|
|
|
46
|
my ( $identifier, $salt_string, $rounds, $passphrase ) = split ':', $_, 4; |
51
|
6
|
|
|
|
|
56
|
( $salt_string, $rounds ) = Acme::Indigest::Crypt->parse_salt_string_rounds( $salt_string, $rounds ); |
52
|
6
|
|
|
|
|
24
|
my $ciphertext = Acme::Indigest::Crypt->digest( $passphrase, $salt_string, $rounds ); |
53
|
6
|
|
|
|
|
78
|
$output .= "$identifier => $ciphertext\n"; |
54
|
|
|
|
|
|
|
} |
55
|
1
|
|
|
|
|
19
|
return $output; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |