Auth/ConsentToken.pm

filter: Statementstmt 22.2% 16 / 72 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 28.5% 4 / 14 Podpod 0.0% 0 / 9 totaltotal 13.0% 20 / 153 SCAR 54.1
CC
18
Cov
14%
_process
132.0
int_location_id
30.0
offers
12.0
CRAP 223.8
« Auth.pm ↑ Summary Auth/Utils.pm »
1 package WWW::Live::Auth::ConsentToken;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use WWW::Live::Auth::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require WWW::Live::Auth::SecretKey;
10 1 require WWW::Live::Auth::Offer;
11 1 require Math::BigInt;
12  
13 sub new {
14 0 ▶ my ( $proto, %args ) = @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
15 0 ▶ my $class = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
16
17 my $self = bless {
18 0 'string' => $args{'consent_token'},
19 }, $class;
20
21 0 $self->_process( $args{'secret_key'} );
22
23 0 return $self;
24 }
25  
26 sub as_string {
27 0 ▶ my $self = shift;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
28 0 return $self->{'string'};
29 }
30  
31 sub delegation_token {
32 0 ▶ my $self = shift;
Subroutine delegation_token: not called CC=1 SCAR=6.9
Pod undocumented
33 0 return $self->{'delegation_token'};
34 }
35  
36 sub refresh_token {
37 0 ▶ my $self = shift;
Subroutine refresh_token: not called CC=1 SCAR=6.9
Pod undocumented
38 0 return $self->{'refresh_token'};
39 }
40  
41 sub session_key {
42 0 ▶ my $self = shift;
Subroutine session_key: not called CC=1 SCAR=6.9
Pod undocumented
43 0 return $self->{'session_key'};
44 }
45  
46 sub location_id {
47 0 ▶ my $self = shift;
Subroutine location_id: not called CC=1 SCAR=6.9
Pod undocumented
48 0 return $self->{'location_id'};
49 }
50  
51 sub int_location_id {
52 0 ▶ my $self = shift;
Subroutine int_location_id: not called CC=5 SCAR=34.0
Pod undocumented
53 0 my $num = Math::BigInt->new('0x'.$self->{'location_id'});
54 0 my ($base2) = $num->as_bin() =~ /^0b(\d+)/;
55 0 warn "BASE2: $base2";
56
57 0 ▶ if ( length($base2) == 64 && substr($base2, 0, 1) eq '1' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $base2 == 64 and substr($base2, 0, 1) eq '1') { } 0 0 0
Condition0%0/3
length $base2 == 64 and substr($base2, 0, 1) eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
length $base2 == 64 and substr($base2, 0, 1) eq 1
length $base2 == 64 substr($base2, 0, 1) eq 1
Truth table0%0/3
A and B
A= length $base2 == 64B= substr($base2, 0, 1) eq 1
ABresult
0X0
100
111
58 0 $base2 =~ tr/01/10/;
59 0 my @chars = split //, $base2;
60 0 ▶ for (my $i=63; $i>0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
61 0 $chars[$i] =~ tr/01/10/;
62 0 ▶ if ($chars[$i] eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($chars[$i] eq 1) 0 0 0
63 0 last;
64 }
65 }
66 0 $base2 = join '', @chars;
67 0 return '-' . Math::BigInt->new("0b$base2")->bstr;
68 } else {
69 0 return $num->bstr;
70 }
71 }
72  
73 sub offers {
74 0 ▶ my $self = shift;
Subroutine offers: not called CC=3 SCAR=24.8
Pod undocumented
75 0 ▶ return wantarray ? @{ $self->{'offers'} || [] } : $self->{'offers'};
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
$self->{"offers"} or [] 0 0 0
76 }
77  
78 sub expires {
79 0 ▶ my $self = shift;
Subroutine expires: not called CC=1 SCAR=6.9
Pod undocumented
80 0 return $self->{'expires'};
81 }
82  
83 sub _process {
84 0 ▶ my ( $self, $secret_key ) = @_;
Subroutine _process: not called CC=11 SCAR=48.8
85
86 0 ▶ $secret_key || croak('Secret key is required');
Branch: 1 branch
BranchTrueFalseTotal
$secret_key or croak("Secret key is required") 0 0 0
87 0 ▶ my $consent_token = $self->{'string'} || croak('Consent token is required');
Condition0%0/3
$self->{'string'} || croak('Consent token is required')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'string'} || croak('Consent token is required')
$self->{'string'} croak('Consent token is required')
Truth table0%0/3
A || B
A= $self->{'string'}B= croak('Consent token is required')
ABresult
1X1
011
000
88
89 0 ▶ if ( !ref $secret_key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $secret_key) 0 0 0
90 0 $secret_key = WWW::Live::Auth::SecretKey->new( $secret_key );
91 }
92
93 0 $consent_token = _unescape( $consent_token );
94 0 $consent_token = _split( $consent_token );
95
96 0 ▶ if ( $consent_token->{'eact'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($consent_token->{"eact"}) 0 0 0
97 0 $consent_token = _unescape( $consent_token->{'eact'} );
98 0 $consent_token = _decode ( $consent_token );
99 0 $consent_token = _decrypt ( $consent_token, $secret_key->encryption_key );
100 0 $consent_token = _validate( $consent_token, $secret_key->signature_key );
101 0 $consent_token = _split ( $consent_token );
102 }
103
104 my @offers = map {
105 0 WWW::Live::Auth::Offer->new( 'offer' => $_ )
106 0 } split /;/, $consent_token->{'offer'};
107
108 0 ▶ scalar @offers || croak('Consent token contains no offers');
Branch: 1 branch
BranchTrueFalseTotal
scalar @offers or croak("Consent token contains no offers") 0 0 0
109
110 0 ▶ $self->{'delegation_token'} = $consent_token->{'delt'} || croak('Consent token contains no delegation token');
Condition0%0/3
$consent_token->{'delt'} || croak('Consent token contains no delegation token')
l!l&&r!l&&!r
000
MC/DC0%0/2
$consent_token->{'delt'} || croak('Consent token contains no delegation token')
$consent_token->{'delt'} croak('Consent token contains no delegation token')
Truth table0%0/3
A || B
A= $consent_token->{'delt'}B= croak('Consent token contains no delegation token')
ABresult
1X1
011
000
111 0 ▶ $self->{'refresh_token'} = $consent_token->{'reft'} || croak('Consent token contains no refresh token');
Condition0%0/3
$consent_token->{'reft'} || croak('Consent token contains no refresh token')
l!l&&r!l&&!r
000
MC/DC0%0/2
$consent_token->{'reft'} || croak('Consent token contains no refresh token')
$consent_token->{'reft'} croak('Consent token contains no refresh token')
Truth table0%0/3
A || B
A= $consent_token->{'reft'}B= croak('Consent token contains no refresh token')
ABresult
1X1
011
000
112 0 ▶ $self->{'session_key'} = $consent_token->{'skey'} || croak('Consent token contains no session key');
Condition0%0/3
$consent_token->{'skey'} || croak('Consent token contains no session key')
l!l&&r!l&&!r
000
MC/DC0%0/2
$consent_token->{'skey'} || croak('Consent token contains no session key')
$consent_token->{'skey'} croak('Consent token contains no session key')
Truth table0%0/3
A || B
A= $consent_token->{'skey'}B= croak('Consent token contains no session key')
ABresult
1X1
011
000
113 0 ▶ $self->{'expires'} = $consent_token->{'exp'} || croak('Consent token contains no expiry time');
Condition0%0/3
$consent_token->{'exp'} || croak('Consent token contains no expiry time')
l!l&&r!l&&!r
000
MC/DC0%0/2
$consent_token->{'exp'} || croak('Consent token contains no expiry time')
$consent_token->{'exp'} croak('Consent token contains no expiry time')
Truth table0%0/3
A || B
A= $consent_token->{'exp'}B= croak('Consent token contains no expiry time')
ABresult
1X1
011
000
114 0 ▶ $self->{'location_id'} = $consent_token->{'lid'} || croak('Consent token contains no location ID');
Condition0%0/3
$consent_token->{'lid'} || croak('Consent token contains no location ID')
l!l&&r!l&&!r
000
MC/DC0%0/2
$consent_token->{'lid'} || croak('Consent token contains no location ID')
$consent_token->{'lid'} croak('Consent token contains no location ID')
Truth table0%0/3
A || B
A= $consent_token->{'lid'}B= croak('Consent token contains no location ID')
ABresult
1X1
011
000
115 0 $self->{'offers'} = \@offers;
116 }
117  
118 1 1;
119 __END__
« Auth.pm ↑ Summary Auth/Utils.pm »