| 1 | package URI::otpauth; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use MIME::Base32(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use URI::Split(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use URI::Escape(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use parent qw( URI URI::_query ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '5.40'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 5 | my ($class, @parameters) = @_; | |||||||||||||||||||||||||||
| 15 | 5 | my %fields = $class->_set(@parameters); | |||||||||||||||||||||||||||
| 16 | my $uri = URI::Split::uri_join( | ||||||||||||||||||||||||||||
| 17 | 'otpauth', $fields{type}, | ||||||||||||||||||||||||||||
| 18 | 5 | $class->_path(%fields), | |||||||||||||||||||||||||||
| 19 | $class->_query(%fields), | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | 4 | return bless \$uri, $class; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 68 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 25 | 68 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | 68 | my ($scheme, $type, $path, $query, $frag) = URI::Split::uri_split(${$self}); | |||||||||||||||||||||||||||
| 27 | 68 | $path =~ s/^\///smxg; | |||||||||||||||||||||||||||
| 28 | 68 | my @path_parts = split /:/smx, $path; | |||||||||||||||||||||||||||
| 29 | 68 | my ($issuer_prefix, $account_name); | |||||||||||||||||||||||||||
| 30 | 68 | ▶ | if (scalar @path_parts == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 16 | $account_name = $path_parts[0]; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||
| 34 | 52 | $issuer_prefix = $path_parts[0]; | |||||||||||||||||||||||||||
| 35 | 52 | $account_name = $path_parts[1]; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 68 | my %fields = (label => $path, type => $type, account_name => $account_name); | |||||||||||||||||||||||||||
| 38 | 68 | my $issuer_parameter = $self->query_param('issuer'); | |||||||||||||||||||||||||||
| 39 | 68 | ▶ | if (defined $issuer_parameter) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 40 | 45 | ▶ | if ((defined $issuer_prefix) && ($issuer_prefix ne $issuer_parameter)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $issuer_prefix and $issuer_prefix ne $issuer_parameter
MC/DC0%0/2
defined $issuer_prefix and $issuer_prefix ne $issuer_parameter
defined $issuer_prefix
$issuer_prefix ne $issuer_parameter
Truth table66%2/3
A and B
A= defined $issuer_prefixB= $issuer_prefix ne $issuer_parameter
| |||||||||||||||||||||||||||||
| 41 | 0 | Carp::carp( | |||||||||||||||||||||||||||
| 42 | "Issuer prefix from label '$issuer_prefix' does not match issuer parameter '$issuer_parameter'" | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 45 | $fields{issuer} = $issuer_parameter; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | elsif (defined $issuer_prefix) { | ||||||||||||||||||||||||||||
| 48 | 9 | $fields{issuer} = URI::Escape::uri_unescape($issuer_prefix); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 68 | ▶ | if (my $encoded_secret = $self->query_param('secret')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 60 | $fields{secret} = MIME::Base32::decode_base32($encoded_secret); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 68 | foreach my $name (qw(algorithm digits counter period)) { | |||||||||||||||||||||||||||
| 54 | 272 | ▶ | if (my $value = $self->query_param($name)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 56 | $fields{$name} = $value; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 68 | %fields = $self->_set(%fields); | |||||||||||||||||||||||||||
| 59 | 68 | return ($scheme, $fields{type}, \%fields, $query, $frag); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | my $label_escape_regex = qr/[^[:alnum:]@.]/smx; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 73 | ▶ | sub _set { | ||||||||||||||||||||||||||
|
Subroutine
_set: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 65 | 73 | my ($self, %fields) = @_; | |||||||||||||||||||||||||||
| 66 | 73 | delete $fields{label}; | |||||||||||||||||||||||||||
| 67 | 73 | ▶ | if (defined $fields{account_name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 64 | ▶ | if (defined $fields{issuer}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 56 | $fields{label} = $fields{issuer} . q[:] . $fields{account_name}; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||
| 72 | 8 | $fields{label} = $fields{account_name}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 73 | ▶ | if (!length $fields{type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 2 | $fields{type} = 'totp'; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 73 | return %fields; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | my %field_names = map { $_ => 1 } | |||||||||||||||||||||||||||
| 82 | qw(secret label counter algorithm period digits issuer type account_name); | ||||||||||||||||||||||||||||
| 83 | 1 | my @query_names = qw(secret issuer algorithm digits counter period); | |||||||||||||||||||||||||||
| 84 | 1 | my %defaults = (algorithm => 'SHA1', digits => 6, type => 'totp', period => 30); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 68 | ▶ | sub _field { | ||||||||||||||||||||||||||
|
Subroutine
_field: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 87 | 68 | my ($self, $name, @remainder) = @_; | |||||||||||||||||||||||||||
| 88 | 68 | my ($scheme, $type, $fields, $query, $frag) = $self->_parse(); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 68 | ▶ | if (!@remainder) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 67 | ▶ | if (defined $fields->{$name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 42 | return $fields->{$name}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||
| 95 | 25 | return $defaults{$name}; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 1 | $fields->{$name} = shift @remainder; | |||||||||||||||||||||||||||
| 99 | 1 | ${$self} = URI::Split::uri_join( | |||||||||||||||||||||||||||
| 100 | $scheme, $fields->{type}, | ||||||||||||||||||||||||||||
| 101 | 1 | $self->_path(%{$fields}), | |||||||||||||||||||||||||||
| 102 | 1 | $self->_query(%{$fields}), $frag | |||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||
| 104 | 1 | return $self; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 6 | ▶ | sub _query { | ||||||||||||||||||||||||||
|
Subroutine
_query: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 108 | 6 | my ($class, %fields) = @_; | |||||||||||||||||||||||||||
| 109 | 6 | ▶ | if (defined $fields{secret}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 5 | $fields{secret} = MIME::Base32::encode_base32($fields{secret}); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||
| 113 | 1 | Carp::croak('secret is a mandatory parameter for ' . __PACKAGE__); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | return join q[&], | ||||||||||||||||||||||||||||
| 116 | 11 | map { join q[=], $_ => $fields{$_} } | |||||||||||||||||||||||||||
| 117 | 5 | grep { exists $fields{$_} } @query_names; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 6 | ▶ | sub _path { | ||||||||||||||||||||||||||
|
Subroutine
_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 121 | 6 | my ($class, %fields) = @_; | |||||||||||||||||||||||||||
| 122 | 6 | my $path = $fields{label}; | |||||||||||||||||||||||||||
| 123 | 6 | return $path; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 13 | ▶ | sub type { | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 13 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 128 | 13 | return $self->_field('type', @parameters); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 4 | ▶ | sub authority { return shift->type(@_); } | ||||||||||||||||||||||||||
|
Subroutine
authority: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 6 | ▶ | sub label { | ||||||||||||||||||||||||||
|
Subroutine
label: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 6 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 135 | 6 | return $self->_field('label', @parameters); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 3 | ▶ | sub account_name { | ||||||||||||||||||||||||||
|
Subroutine
account_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 139 | 3 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 140 | 3 | return $self->_field('account_name', @parameters); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 8 | ▶ | sub issuer { | ||||||||||||||||||||||||||
|
Subroutine
issuer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 8 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 145 | 8 | return $self->_field('issuer', @parameters); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 9 | ▶ | sub secret { | ||||||||||||||||||||||||||
|
Subroutine
secret: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 9 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 150 | 9 | return $self->_field('secret', @parameters); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 8 | ▶ | sub algorithm { | ||||||||||||||||||||||||||
|
Subroutine
algorithm: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 8 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 155 | 8 | return $self->_field('algorithm', @parameters); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 8 | ▶ | sub counter { | ||||||||||||||||||||||||||
|
Subroutine
counter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 8 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 160 | 8 | return $self->_field('counter', @parameters); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 5 | ▶ | sub digits { | ||||||||||||||||||||||||||
|
Subroutine
digits: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 5 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 165 | 5 | return $self->_field('digits', @parameters); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 8 | ▶ | sub period { | ||||||||||||||||||||||||||
|
Subroutine
period: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 169 | 8 | my ($self, @parameters) = @_; | |||||||||||||||||||||||||||
| 170 | 8 | return $self->_field('period', @parameters); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 1 | 1; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | __END__ | ||||||||||||||||||||||||||||