line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Plugin::SecureStateID; |
2
|
|
|
|
|
|
|
$Starch::Plugin::SecureStateID::VERSION = '0.001'; |
3
|
|
|
|
|
|
|
# ABSTRACT: use cryptographically secure random when making state IDs |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
30320
|
use Math::Random::Secure (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
4
|
use Digest::SHA (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
7
|
1
|
|
|
1
|
|
3
|
use Scalar::Util qw( refaddr ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
8
|
1
|
|
|
1
|
|
4
|
use Types::Standard -types; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
2504
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
11
|
1
|
|
|
1
|
|
350
|
use strictures 2; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
43
|
|
12
|
1
|
|
|
1
|
|
172
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with qw( |
15
|
|
|
|
|
|
|
Starch::Plugin::ForManager |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has secure_state_id_sha => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => Enum[1, 224, 256, 384, 512, 512224, 512256], |
21
|
|
|
|
|
|
|
default => 256, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _secure_state_id_sha { |
25
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
26
|
2
|
|
|
|
|
35
|
Digest::SHA->new($self->secure_state_id_sha); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $counter = 0; |
30
|
|
|
|
|
|
|
around state_id_seed => sub { |
31
|
|
|
|
|
|
|
shift; # we never call the original |
32
|
|
|
|
|
|
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
return join( '', ++$counter, time, Math::Random::Secure::rand(), $$, {}, refaddr($self) ) |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
around generate_state_id => sub { |
37
|
|
|
|
|
|
|
shift; # we never call the original |
38
|
|
|
|
|
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
my $sha = $self->_secure_state_id_sha; |
40
|
|
|
|
|
|
|
$sha->add( $self->state_id_seed() ); |
41
|
|
|
|
|
|
|
return $sha->hexdigest(); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |