| 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 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 0 | my ( $proto, %args ) = @_; | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub as_string { | ||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 0 | return $self->{'string'}; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub delegation_token { | ||||||||||||||||||||||||||
|
Subroutine
delegation_token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | 0 | return $self->{'delegation_token'}; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub refresh_token { | ||||||||||||||||||||||||||
|
Subroutine
refresh_token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 0 | return $self->{'refresh_token'}; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub session_key { | ||||||||||||||||||||||||||
|
Subroutine
session_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 0 | return $self->{'session_key'}; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub location_id { | ||||||||||||||||||||||||||
|
Subroutine
location_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 0 | return $self->{'location_id'}; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub int_location_id { | ||||||||||||||||||||||||||
|
Subroutine
int_location_id: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 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
Condition0%0/3
length $base2 == 64 and substr($base2, 0, 1) eq 1
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
| |||||||||||||||||||||||||||||
| 58 | 0 | $base2 =~ tr/01/10/; | |||||||||||||||||||||||||||
| 59 | 0 | my @chars = split //, $base2; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | for (my $i=63; $i>0; $i--) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $chars[$i] =~ tr/01/10/; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($chars[$i] eq '1') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub offers { | ||||||||||||||||||||||||||
|
Subroutine
offers: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | return wantarray ? @{ $self->{'offers'} || [] } : $self->{'offers'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'offers'} || []
MC/DC0%0/1
$self->{'offers'} || []
$self->{'offers'}
Truth table0%0/2
A
A= $self->{'offers'}
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub expires { | ||||||||||||||||||||||||||
|
Subroutine
expires: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | 0 | return $self->{'expires'}; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub _process { | ||||||||||||||||||||||||||
|
Subroutine
_process: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 84 | 0 | my ( $self, $secret_key ) = @_; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $secret_key || croak('Secret key is required'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $consent_token = $self->{'string'} || croak('Consent token is required'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'string'} || croak('Consent token is required')
MC/DC0%0/1
$self->{'string'} || croak('Consent token is required')
$self->{'string'}
Truth table0%0/2
A
A= $self->{'string'}
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( !ref $secret_key ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $self->{'delegation_token'} = $consent_token->{'delt'} || croak('Consent token contains no delegation token'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$consent_token->{'delt'} || croak('Consent token contains no delegation token')
MC/DC0%0/1
$consent_token->{'delt'} || croak('Consent token contains no delegation token')
$consent_token->{'delt'}
Truth table0%0/2
A
A= $consent_token->{'delt'}
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $self->{'refresh_token'} = $consent_token->{'reft'} || croak('Consent token contains no refresh token'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$consent_token->{'reft'} || croak('Consent token contains no refresh token')
MC/DC0%0/1
$consent_token->{'reft'} || croak('Consent token contains no refresh token')
$consent_token->{'reft'}
Truth table0%0/2
A
A= $consent_token->{'reft'}
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | $self->{'session_key'} = $consent_token->{'skey'} || croak('Consent token contains no session key'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$consent_token->{'skey'} || croak('Consent token contains no session key')
MC/DC0%0/1
$consent_token->{'skey'} || croak('Consent token contains no session key')
$consent_token->{'skey'}
Truth table0%0/2
A
A= $consent_token->{'skey'}
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $self->{'expires'} = $consent_token->{'exp'} || croak('Consent token contains no expiry time'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$consent_token->{'exp'} || croak('Consent token contains no expiry time')
MC/DC0%0/1
$consent_token->{'exp'} || croak('Consent token contains no expiry time')
$consent_token->{'exp'}
Truth table0%0/2
A
A= $consent_token->{'exp'}
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $self->{'location_id'} = $consent_token->{'lid'} || croak('Consent token contains no location ID'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$consent_token->{'lid'} || croak('Consent token contains no location ID')
MC/DC0%0/1
$consent_token->{'lid'} || croak('Consent token contains no location ID')
$consent_token->{'lid'}
Truth table0%0/2
A
A= $consent_token->{'lid'}
| |||||||||||||||||||||||||||||
| 115 | 0 | $self->{'offers'} = \@offers; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||