| 1 | package UID2::Client::KeyContainer; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use List::MoreUtils qw(upper_bound); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use UID2::Client::Timestamp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub new { | ||||||||||||||||||||||||||||
| 9 | 56 | ▶ | my ($class, @keys) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 56 | my $latest_expires = 0; | |||||||||||||||||||||||||||
| 11 | 56 | my (%keys, %keys_by_site); | |||||||||||||||||||||||||||
| 12 | 56 | for my $key (@keys) { | |||||||||||||||||||||||||||
| 13 | 135 | $keys{$key->id} = $key; | |||||||||||||||||||||||||||
| 14 | 135 | ▶ | if ($key->site_id > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 109 | ▶ | push @{$keys_by_site{$key->site_id} //= []}, $key; | ||||||||||||||||||||||||||
|
Condition100%2/2
$keys_by_site{$key->site_id} //= []
MC/DC100%1/1
$keys_by_site{$key->site_id} //= []
$keys_by_site{$key->site_id}
Truth table100%2/2
A
A= $keys_by_site{$key->site_id}
| |||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 135 | ▶ | if (!$latest_expires or $key->expires > $latest_expires) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $latest_expires or $key->expires > $latest_expires
MC/DC100%2/2
not $latest_expires or $key->expires > $latest_expires
not $latest_expires
$key->expires > $latest_expires
Truth table100%3/3
not(A) or B
A= not $latest_expiresB= $key->expires > $latest_expires
| |||||||||||||||||||||||||||||
| 18 | 57 | $latest_expires = $key->expires; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 56 | ▶ | while (my ($site_id, $keys) = each %keys_by_site) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 54 | $keys_by_site{$site_id} = [sort { $a->activates <=> $b->activates } @$keys]; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | bless { | ||||||||||||||||||||||||||||
| 25 | 56 | keys => \%keys, | |||||||||||||||||||||||||||
| 26 | keys_by_site => \%keys_by_site, | ||||||||||||||||||||||||||||
| 27 | latest_expires => $latest_expires, | ||||||||||||||||||||||||||||
| 28 | }, $class; | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub get { | ||||||||||||||||||||||||||||
| 32 | 50 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 50 | $self->{keys}->{$id}; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub is_valid { | ||||||||||||||||||||||||||||
| 37 | 40 | ▶ | my ($self, $now) = @_; | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 40 | ▶ | $now //= UID2::Client::Timestamp->now; | ||||||||||||||||||||||||||
|
Condition66%2/3
$now //= "UID2::Client::Timestamp"->now
MC/DC0%0/2
$now //= "UID2::Client::Timestamp"->now
$now
"UID2::Client::Timestamp"->now
Truth table66%2/3
A //= B
A= $nowB= "UID2::Client::Timestamp"->now
| |||||||||||||||||||||||||||||
| 39 | 40 | $self->{latest_expires} > $now->get_epoch_second; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub get_active_site_key { | ||||||||||||||||||||||||||||
| 43 | 19 | ▶ | my ($self, $site_id, $now) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_active_site_key: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 19 | ▶ | my $keys = $self->{keys_by_site}->{$site_id} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 18 | ▶ | $now //= UID2::Client::Timestamp->now; | ||||||||||||||||||||||||||
|
Condition66%2/3
$now //= "UID2::Client::Timestamp"->now
MC/DC0%0/2
$now //= "UID2::Client::Timestamp"->now
$now
"UID2::Client::Timestamp"->now
Truth table66%2/3
A //= B
A= $nowB= "UID2::Client::Timestamp"->now
| |||||||||||||||||||||||||||||
| 46 | 18 | my $second = $now->get_epoch_second; | |||||||||||||||||||||||||||
| 47 | 18 | ▶ | my $i = upper_bound { $_->activates <=> $second } @$keys; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 18 | ▶ | while ($i > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 18 | $i--; | |||||||||||||||||||||||||||
| 50 | 18 | ▶ | return $keys->[$i] if $keys->[$i]->is_active($now); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 4 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 4 | 1; | |||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||