| 1 | # frozen_string_literal: true | ||||||||||||||||||||||||||||||||
| 2 | # Copyright 2020 Google LLC and contributors | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||
| 5 | # you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||
| 6 | # You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||
| 10 | # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||
| 13 | # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||
| 14 | # limitations under the License. | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | package Google::Auth::IDTokens::KeySources; | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use URI; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | use Google::Auth; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use MIME::Base64 qw(decode_base64); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 5 | 1; | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | ## | ||||||||||||||||||||||||||||||||
| 30 | # A public key used for verifying ID tokens. | ||||||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||||||
| 32 | # This includes the public key data, ID, and the algorithm used for | ||||||||||||||||||||||||||||||||
| 33 | # signature verification. RSA and Elliptical Curve (EC) keys are | ||||||||||||||||||||||||||||||||
| 34 | # supported. | ||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | package Google::Auth::IDTokens::KeyInfo; | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 5 | my $coder = JSON::MaybeXS->new->ascii->pretty->allow_nonref; | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | ## | ||||||||||||||||||||||||||||||||
| 44 | # Create a public key info structure. | ||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||
| 46 | # @param id [String] The key ID. | ||||||||||||||||||||||||||||||||
| 47 | # @param key [Crypt::PK::RSA,Crypt::PK::ECC] The key itself. | ||||||||||||||||||||||||||||||||
| 48 | # @param algorithm [String] The algorithm (normally `RS256` or `ES256`) | ||||||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||||||
| 50 | 15 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 51 | 15 | my ($class, $params) = @_; | |||||||||||||||||||||||||||||||
| 52 | 15 | ▶ | $params //= {}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$params //= {}
MC/DC100%1/1
$params //= {}
$params
Truth table100%2/2
A
A= $params
| |||||||||||||||||||||||||||||||||
| 53 | 15 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | my $self = bless { | ||||||||||||||||||||||||||||||||
| 55 | id => $params->{id} // undef, | ||||||||||||||||||||||||||||||||
| 56 | key => $params->{key} // undef, | ||||||||||||||||||||||||||||||||
| 57 | algorithm => $params->{algorithm} // undef, | ||||||||||||||||||||||||||||||||
| 58 | 15 | ▶ | }, $class; | ||||||||||||||||||||||||||||||
|
Condition100%6/6
$params->{"id"} // undef
$params->{"key"} // undef
$params->{"algorithm"} // undef
MC/DC100%1/1
$params->{"id"} // undef
$params->{"id"}
MC/DC100%1/1
$params->{"key"} // undef
$params->{"key"}
MC/DC100%1/1
$params->{"algorithm"} // undef
$params->{"algorithm"}
Truth table100%2/2
A
A= $params->{"id"}
Truth table100%2/2
A
A= $params->{"key"}
Truth table100%2/2
A
A= $params->{"algorithm"}
| |||||||||||||||||||||||||||||||||
| 59 | 15 | return $self; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | ## | ||||||||||||||||||||||||||||||||
| 63 | # The key ID. | ||||||||||||||||||||||||||||||||
| 64 | # @return [String] | ||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||
| 66 | 31 | ▶ | sub id { return $_[0]->{id} } | ||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | ## | ||||||||||||||||||||||||||||||||
| 69 | # The key itself. | ||||||||||||||||||||||||||||||||
| 70 | # @return [OpenSSL::PKey::RSA,OpenSSL::PKey::EC] | ||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||
| 72 | 13 | ▶ | sub key { return $_[0]->{key} } | ||||||||||||||||||||||||||||||
|
Subroutine
key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | ## | ||||||||||||||||||||||||||||||||
| 75 | # The signature algorithm. (normally `RS256` or `ES256`) | ||||||||||||||||||||||||||||||||
| 76 | # @return [String] | ||||||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub algorithm { return $_[0]->{algorithm} } | ||||||||||||||||||||||||||||||
|
Subroutine
algorithm: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | ## | ||||||||||||||||||||||||||||||||
| 81 | # Create a KeyInfo from a single JWK, which may be given as either a | ||||||||||||||||||||||||||||||||
| 82 | # hash or an unparsed JSON string. | ||||||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||||||
| 84 | # @param jwk [Hash,String] The JWK specification. | ||||||||||||||||||||||||||||||||
| 85 | # @return [KeyInfo] | ||||||||||||||||||||||||||||||||
| 86 | # @raise [KeySourceError] If the key could not be extracted from the | ||||||||||||||||||||||||||||||||
| 87 | # JWK. | ||||||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||||||
| 89 | 11 | ▶ | sub from_jwk { | ||||||||||||||||||||||||||||||
|
Subroutine
from_jwk: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||
| 90 | 11 | my ($self, $jwk) = @_; | |||||||||||||||||||||||||||||||
| 91 | 11 | $jwk = $self->ensure_json_parsed($jwk); | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 11 | ▶ | my $instance = ref $self ? $self : $self->new(); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 11 | ▶ | if ($jwk->{kty} eq 'RSA') { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 96 | 4 | $instance->{key} = $instance->extract_rsa_key($jwk); | |||||||||||||||||||||||||||||||
| 97 | } elsif ($jwk->{kty} eq 'EC') { | ||||||||||||||||||||||||||||||||
| 98 | 6 | $instance->{key} = $instance->extract_ec_key($jwk); | |||||||||||||||||||||||||||||||
| 99 | } elsif (!defined $jwk->{kty}) { | ||||||||||||||||||||||||||||||||
| 100 | 0 | die 'Key type not found'; | |||||||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||||||
| 102 | 1 | die 'Cannot use key type ' . $jwk->{kty}; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | 10 | $instance->{id} = $jwk->{kid}; | |||||||||||||||||||||||||||||||
| 105 | 10 | $instance->{algorithm} = $jwk->{alg}; | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 10 | return $instance; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | ## | ||||||||||||||||||||||||||||||||
| 110 | # Create an array of KeyInfo from a JWK Set, which may be given as | ||||||||||||||||||||||||||||||||
| 111 | # either a hash or an unparsed JSON string. | ||||||||||||||||||||||||||||||||
| 112 | # | ||||||||||||||||||||||||||||||||
| 113 | # @param jwk [Hash,String] The JWK Set specification. | ||||||||||||||||||||||||||||||||
| 114 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 115 | # @raise [KeySourceError] If a key could not be extracted from the | ||||||||||||||||||||||||||||||||
| 116 | # JWK Set. | ||||||||||||||||||||||||||||||||
| 117 | # | ||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | sub from_jwk_set { | ||||||||||||||||||||||||||||||
|
Subroutine
from_jwk_set: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||
| 119 | 6 | my ($self, $jwk_set) = @_; | |||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | confess 'jwk_set is a required argument' unless $jwk_set; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | 6 | $jwk_set = $self->ensure_json_parsed($jwk_set); | |||||||||||||||||||||||||||||||
| 122 | confess "No keys found in jwk set" | ||||||||||||||||||||||||||||||||
| 123 | unless (exists $jwk_set->{keys} | ||||||||||||||||||||||||||||||||
| 124 | 6 | ▶ | && ref $jwk_set->{keys} eq 'ARRAY'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $jwk_set->{"keys"} and ref $jwk_set->{"keys"} eq "ARRAY"
MC/DC50%1/2
exists $jwk_set->{"keys"} and ref $jwk_set->{"keys"} eq "ARRAY"
exists $jwk_set->{"keys"}
ref $jwk_set->{"keys"} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $jwk_set->{"keys"}B= ref $jwk_set->{"keys"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 125 | 5 | my $jwks = [map { $self->from_jwk($_) } @{$jwk_set->{keys}}]; | |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 4 | return $jwks; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 17 | ▶ | sub ensure_json_parsed { | ||||||||||||||||||||||||||||||
|
Subroutine
ensure_json_parsed: called CC=4 SCAR=20.4
| |||||||||||||||||||||||||||||||||
| 131 | 17 | my ($self, $input) = @_; | |||||||||||||||||||||||||||||||
| 132 | 17 | ▶ | confess 'input is a required argument' unless $input; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 17 | ▶ | return $input if ref $input; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 0 | my $decoded = eval { $coder->decode($input) }; | |||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | confess("Unable to parse JSON: $@$/" . "input: $input") if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 0 | return $decoded; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub symbolize_keys { | ||||||||||||||||||||||||||||||
|
Subroutine
symbolize_keys: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 141 | 0 | my ($self, $hash) = @_; | |||||||||||||||||||||||||||||||
| 142 | 0 | my $result = {}; | |||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | while (my ($key, $val) = each %$hash) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | 0 | $result->{$key} = $val; | |||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||
| 146 | 0 | return $result; | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 20 | ▶ | sub _decode_base64url { | ||||||||||||||||||||||||||||||
|
Subroutine
_decode_base64url: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 150 | 20 | my ($s) = @_; | |||||||||||||||||||||||||||||||
| 151 | 20 | $s =~ tr{-_}{+/}; | |||||||||||||||||||||||||||||||
| 152 | 20 | my $padding = length($s) % 4; | |||||||||||||||||||||||||||||||
| 153 | 20 | ▶ | if ($padding) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | 16 | $s .= '=' x (4 - $padding); | |||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | 20 | return MIME::Base64::decode_base64($s); | |||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 4 | ▶ | sub extract_rsa_key { | ||||||||||||||||||||||||||||||
|
Subroutine
extract_rsa_key: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 160 | 4 | my ($self, $jwk) = @_; | |||||||||||||||||||||||||||||||
| 161 | 4 | my $n = _decode_base64url($jwk->{n}); | |||||||||||||||||||||||||||||||
| 162 | 4 | my $e = _decode_base64url($jwk->{e}); | |||||||||||||||||||||||||||||||
| 163 | 4 | my $pubkey = Google::Auth::load_rsa_pubkey($n, $e); | |||||||||||||||||||||||||||||||
| 164 | 4 | ▶ | die 'Failed to load RSA public key' unless defined $pubkey; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | 4 | return $pubkey; | |||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | # @private | ||||||||||||||||||||||||||||||||
| 169 | 5 | my $CURVE_NAME_MAP = { | |||||||||||||||||||||||||||||||
| 170 | 'P-256' => 'prime256v1', | ||||||||||||||||||||||||||||||||
| 171 | 'P-384' => 'secp384r1', | ||||||||||||||||||||||||||||||||
| 172 | 'P-521' => 'secp521r1', | ||||||||||||||||||||||||||||||||
| 173 | 'secp256k1' => 'secp256k1' | ||||||||||||||||||||||||||||||||
| 174 | }; | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | 6 | ▶ | sub extract_ec_key { | ||||||||||||||||||||||||||||||
|
Subroutine
extract_ec_key: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||
| 177 | 6 | my ($self, $jwk) = @_; | |||||||||||||||||||||||||||||||
| 178 | 6 | my $curve = $jwk->{crv}; | |||||||||||||||||||||||||||||||
| 179 | die 'Unsupported EC curve ' . $curve | ||||||||||||||||||||||||||||||||
| 180 | 6 | ▶ | unless exists $CURVE_NAME_MAP->{$curve}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 6 | my $x = _decode_base64url($jwk->{x}); | |||||||||||||||||||||||||||||||
| 183 | 6 | my $y = _decode_base64url($jwk->{y}); | |||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 6 | my $openssl_curve = $CURVE_NAME_MAP->{$curve}; | |||||||||||||||||||||||||||||||
| 186 | 6 | my $pubkey = Google::Auth::load_ec_pubkey($openssl_curve, $x, $y); | |||||||||||||||||||||||||||||||
| 187 | 6 | ▶ | die 'Failed to load EC public key' unless defined $pubkey; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 188 | 6 | return $pubkey; | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 5 | 1; | |||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | package Google::Auth::IDTokens::StaticKeySource; | ||||||||||||||||||||||||||||||||
| 194 | ## | ||||||||||||||||||||||||||||||||
| 195 | # A key source that contains a static set of keys. | ||||||||||||||||||||||||||||||||
| 196 | # | ||||||||||||||||||||||||||||||||
| 197 | ## | ||||||||||||||||||||||||||||||||
| 198 | # Create a static key source with the given keys. | ||||||||||||||||||||||||||||||||
| 199 | # | ||||||||||||||||||||||||||||||||
| 200 | # @param keys [Array<KeyInfo>] The keys | ||||||||||||||||||||||||||||||||
| 201 | # | ||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 203 | 1 | my ($class, $params) = @_; | |||||||||||||||||||||||||||||||
| 204 | 1 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 205 | 1 | my $self = bless {current_keys => [@{$params->{keys}}]}, $class; | |||||||||||||||||||||||||||||||
| 206 | 1 | return $self; | |||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | ## | ||||||||||||||||||||||||||||||||
| 210 | # Return the current keys. Does not perform any refresh. | ||||||||||||||||||||||||||||||||
| 211 | # | ||||||||||||||||||||||||||||||||
| 212 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 213 | # | ||||||||||||||||||||||||||||||||
| 214 | 2 | ▶ | sub current_keys { return $_[0]->{current_keys} } | ||||||||||||||||||||||||||||||
|
Subroutine
current_keys: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 215 | 5 | *refresh_keys = \¤t_keys; | |||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | ## | ||||||||||||||||||||||||||||||||
| 218 | # Create a static key source containing a single key parsed from a | ||||||||||||||||||||||||||||||||
| 219 | # single JWK, which may be given as either a hash or an unparsed | ||||||||||||||||||||||||||||||||
| 220 | # JSON string. | ||||||||||||||||||||||||||||||||
| 221 | # | ||||||||||||||||||||||||||||||||
| 222 | # @param jwk [Hash,String] The JWK specification. | ||||||||||||||||||||||||||||||||
| 223 | # @return [StaticKeySource] | ||||||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub from_jwk { | ||||||||||||||||||||||||||||||
|
Subroutine
from_jwk: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 226 | 0 | my ($self, $jwk) = @_; | |||||||||||||||||||||||||||||||
| 227 | 0 | return Google::Auth::IDTokens::KeyInfo->new()->from_jwk($jwk); | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | ## | ||||||||||||||||||||||||||||||||
| 231 | # Create a static key source containing multiple keys parsed from a | ||||||||||||||||||||||||||||||||
| 232 | # JWK Set, which may be given as either a hash or an unparsed JSON | ||||||||||||||||||||||||||||||||
| 233 | # string. | ||||||||||||||||||||||||||||||||
| 234 | # | ||||||||||||||||||||||||||||||||
| 235 | # @param jwk_set [Hash,String] The JWK Set specification. | ||||||||||||||||||||||||||||||||
| 236 | # @return [StaticKeySource] | ||||||||||||||||||||||||||||||||
| 237 | # | ||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub from_jwk_set { | ||||||||||||||||||||||||||||||
|
Subroutine
from_jwk_set: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 239 | 0 | my ($self, $jwk_set) = @_; | |||||||||||||||||||||||||||||||
| 240 | 0 | return Google::Auth::IDTokens::KeyInfo->new()->from_jwk_set($jwk_set); | |||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 5 | 1; | |||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | package Google::Auth::IDTokens::HttpKeySource; | ||||||||||||||||||||||||||||||||
| 246 | ## | ||||||||||||||||||||||||||||||||
| 247 | # A base key source that downloads keys from a URI. Subclasses should | ||||||||||||||||||||||||||||||||
| 248 | # override {HttpKeySource#interpret_json} to parse the response. | ||||||||||||||||||||||||||||||||
| 249 | # | ||||||||||||||||||||||||||||||||
| 250 | ## | ||||||||||||||||||||||||||||||||
| 251 | # The default interval between retries in seconds (3600s = 1hr). | ||||||||||||||||||||||||||||||||
| 252 | # | ||||||||||||||||||||||||||||||||
| 253 | # @return [Integer] | ||||||||||||||||||||||||||||||||
| 254 | # | ||||||||||||||||||||||||||||||||
| 255 | 5 | our $DEFAULT_RETRY_INTERVAL = 3600; | |||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | ## | ||||||||||||||||||||||||||||||||
| 258 | # Create an HTTP key source. | ||||||||||||||||||||||||||||||||
| 259 | # | ||||||||||||||||||||||||||||||||
| 260 | # @param uri [String,URI] The URI from which to download keys. | ||||||||||||||||||||||||||||||||
| 261 | # @param retry_interval [Integer,nil] Override the retry interval in | ||||||||||||||||||||||||||||||||
| 262 | # seconds. This is the minimum time between retries of failed key | ||||||||||||||||||||||||||||||||
| 263 | # downloads. | ||||||||||||||||||||||||||||||||
| 264 | # | ||||||||||||||||||||||||||||||||
| 265 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=23.0
| |||||||||||||||||||||||||||||||||
| 266 | 16 | my ($class, $params) = @_; | |||||||||||||||||||||||||||||||
| 267 | 16 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 268 | die "uri is a required parameter$/" . Data::Dumper::Dumper($params) | ||||||||||||||||||||||||||||||||
| 269 | 16 | ▶ | unless (exists $params->{uri} && $params->{uri}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"uri"} and $params->{"uri"}
MC/DC0%0/2
exists $params->{"uri"} and $params->{"uri"}
exists $params->{"uri"}
$params->{"uri"}
Truth table33%1/3
A and B
A= exists $params->{"uri"}B= $params->{"uri"}
| |||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | my $self = bless { | ||||||||||||||||||||||||||||||||
| 272 | retry_interval => $params->{retry_interval} || $DEFAULT_RETRY_INTERVAL, | ||||||||||||||||||||||||||||||||
| 273 | allow_refresh_at => time(), | ||||||||||||||||||||||||||||||||
| 274 | current_keys => [], | ||||||||||||||||||||||||||||||||
| 275 | 16 | ▶ | uri => URI->new($params->{uri}), | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$params->{'retry_interval'} || $Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
MC/DC0%0/2
$params->{'retry_interval'} || $Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
$params->{'retry_interval'}
$Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
Truth table66%2/3
A || B
A= $params->{'retry_interval'}B= $Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
| |||||||||||||||||||||||||||||||||
| 276 | }, $class; | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 16 | ▶ | if (exists $ENV{TESTING} && $ENV{TESTING}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $ENV{"TESTING"} and $ENV{"TESTING"}
MC/DC0%0/2
exists $ENV{"TESTING"} and $ENV{"TESTING"}
exists $ENV{"TESTING"}
$ENV{"TESTING"}
Truth table33%1/3
A and B
A= exists $ENV{"TESTING"}B= $ENV{"TESTING"}
| |||||||||||||||||||||||||||||||||
| 279 | 16 | $self->{ua} = $KeySourcesTest::useragent; | |||||||||||||||||||||||||||||||
| 280 | } else { | ||||||||||||||||||||||||||||||||
| 281 | 0 | $self->{ua} = HTTP::Tiny->new(timeout => 10); | |||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 16 | return $self; | |||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | ## | ||||||||||||||||||||||||||||||||
| 288 | # The URI from which to download keys. | ||||||||||||||||||||||||||||||||
| 289 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 290 | # | ||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub uri { return $_[0]->{uri} } | ||||||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | ## | ||||||||||||||||||||||||||||||||
| 294 | # Return the current keys, without attempting to re-download. | ||||||||||||||||||||||||||||||||
| 295 | # | ||||||||||||||||||||||||||||||||
| 296 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 297 | # | ||||||||||||||||||||||||||||||||
| 298 | 12 | ▶ | sub current_keys { return $_[0]->{current_keys} } | ||||||||||||||||||||||||||||||
|
Subroutine
current_keys: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | ## | ||||||||||||||||||||||||||||||||
| 301 | # Attempt to re-download keys (if the retry interval has expired) and | ||||||||||||||||||||||||||||||||
| 302 | # return the new keys. | ||||||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||||||
| 304 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 305 | # @raise [KeySourceError] if key retrieval failed. | ||||||||||||||||||||||||||||||||
| 306 | # | ||||||||||||||||||||||||||||||||
| 307 | 18 | ▶ | sub refresh_keys { | ||||||||||||||||||||||||||||||
|
Subroutine
refresh_keys: called CC=10 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 308 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 309 | $self->{allow_refresh_at} = time() | ||||||||||||||||||||||||||||||||
| 310 | 18 | ▶ | unless (exists $self->{allow_refresh_at}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | 18 | ▶ | if (time() < $self->{allow_refresh_at}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 313 | 2 | ▶ | print STDERR 'cache hit', $/ if $ENV{TESTING} && $ENV{VERBOSE}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"TESTING"} and $ENV{"VERBOSE"}
MC/DC0%0/2
$ENV{"TESTING"} and $ENV{"VERBOSE"}
$ENV{"TESTING"}
$ENV{"VERBOSE"}
Truth table33%1/3
A and B
A= $ENV{"TESTING"}B= $ENV{"VERBOSE"}
| |||||||||||||||||||||||||||||||||
| 314 | 2 | return $self->{current_keys}; | |||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||
| 316 | 16 | ▶ | print STDERR 'cache miss', $/ if $ENV{TESTING} && $ENV{VERBOSE}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"TESTING"} and $ENV{"VERBOSE"}
MC/DC0%0/2
$ENV{"TESTING"} and $ENV{"VERBOSE"}
$ENV{"TESTING"}
$ENV{"VERBOSE"}
Truth table33%1/3
A and B
A= $ENV{"TESTING"}B= $ENV{"VERBOSE"}
| |||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | 16 | my $response = $self->{ua}->get($self->{uri}); | |||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | 16 | my ($success, $status, $reason, $content); | |||||||||||||||||||||||||||||||
| 321 | 16 | ▶ | if (ref($response) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 322 | 0 | $success = $response->{success}; | |||||||||||||||||||||||||||||||
| 323 | 0 | $status = $response->{status}; | |||||||||||||||||||||||||||||||
| 324 | 0 | $reason = $response->{reason}; | |||||||||||||||||||||||||||||||
| 325 | 0 | $content = $response->{content}; | |||||||||||||||||||||||||||||||
| 326 | } else { | ||||||||||||||||||||||||||||||||
| 327 | 16 | $success = $response->is_success; | |||||||||||||||||||||||||||||||
| 328 | 16 | $status = $response->code; | |||||||||||||||||||||||||||||||
| 329 | 16 | $reason = $response->message; | |||||||||||||||||||||||||||||||
| 330 | 16 | $content = $response->decoded_content; | |||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | 16 | ▶ | die( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 334 | "KeySourceError: Unable to retrieve data from $self->{uri}: $status $reason" | ||||||||||||||||||||||||||||||||
| 335 | ) unless $success; | ||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||
| 337 | 13 | $self->{last_response} = $response; | |||||||||||||||||||||||||||||||
| 338 | 13 | my $data = eval { $coder->decode($content) }; | |||||||||||||||||||||||||||||||
| 339 | 13 | ▶ | die("KeySourceError: Unable to parse JSON: $@") if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | 9 | $self->{current_keys} = [$self->interpret_json($data)]; | |||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||
| 343 | 6 | $self->{allow_refresh_at} = time() + $self->{retry_interval}; | |||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||
| 345 | 6 | return $self->{current_keys}; | |||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | 1 | ▶ | sub interpret_json { | ||||||||||||||||||||||||||||||
|
Subroutine
interpret_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 349 | 1 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||
| 350 | 1 | return (); | |||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | 5 | 1; | |||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | package Google::Auth::IDTokens::X509CertHttpKeySource; | ||||||||||||||||||||||||||||||||
| 356 | 5 | ▶ | use base 'Google::Auth::IDTokens::HttpKeySource'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 357 | ## | ||||||||||||||||||||||||||||||||
| 358 | # A key source that downloads X509 certificates. | ||||||||||||||||||||||||||||||||
| 359 | # Used by the legacy OAuth V1 public certs endpoint. | ||||||||||||||||||||||||||||||||
| 360 | # | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | ## | ||||||||||||||||||||||||||||||||
| 363 | # Create a key source that downloads X509 certificates. | ||||||||||||||||||||||||||||||||
| 364 | # | ||||||||||||||||||||||||||||||||
| 365 | # @param uri [String,URI] The URI from which to download keys. | ||||||||||||||||||||||||||||||||
| 366 | # @param algorithm [String] The algorithm to use for signature | ||||||||||||||||||||||||||||||||
| 367 | # verification. Defaults to "`RS256`". | ||||||||||||||||||||||||||||||||
| 368 | # @param retry_interval [Integer,nil] Override the retry interval in | ||||||||||||||||||||||||||||||||
| 369 | # seconds. This is the minimum time between retries of failed key | ||||||||||||||||||||||||||||||||
| 370 | # downloads. | ||||||||||||||||||||||||||||||||
| 371 | # | ||||||||||||||||||||||||||||||||
| 372 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||||||
| 373 | 4 | my ($class, $params) = @_; | |||||||||||||||||||||||||||||||
| 374 | 4 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | die "missing required parameters" | ||||||||||||||||||||||||||||||||
| 377 | 4 | ▶ | unless exists $params->{uri} && $params->{uri}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"uri"} and $params->{"uri"}
MC/DC0%0/2
exists $params->{"uri"} and $params->{"uri"}
exists $params->{"uri"}
$params->{"uri"}
Truth table33%1/3
A and B
A= exists $params->{"uri"}B= $params->{"uri"}
| |||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||
| 379 | 4 | ▶ | $params->{retry_interval} //= 30; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{"retry_interval"} //= 30
MC/DC0%0/1
$params->{"retry_interval"} //= 30
$params->{"retry_interval"}
Truth table50%1/2
A
A= $params->{"retry_interval"}
| |||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | 4 | my $self = $class->SUPER::new($params); | |||||||||||||||||||||||||||||||
| 382 | 4 | ▶ | $self->{algorithm} = $params->{algorithm} || 'RS256'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{'algorithm'} || 'RS256'
MC/DC0%0/1
$params->{'algorithm'} || 'RS256'
$params->{'algorithm'}
Truth table50%1/2
A
A= $params->{'algorithm'}
| |||||||||||||||||||||||||||||||||
| 383 | 4 | return $self; | |||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | 2 | ▶ | sub interpret_json { | ||||||||||||||||||||||||||||||
|
Subroutine
interpret_json: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 387 | 2 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||
| 388 | return map { | ||||||||||||||||||||||||||||||||
| 389 | 2 | my $pubkey = Google::Auth::load_pubkey_from_x509_cert($data->{$_}); | |||||||||||||||||||||||||||||||
| 390 | 3 | ▶ | die "Failed to load X509 certificate for key $_" unless defined $pubkey; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 391 | Google::Auth::IDTokens::KeyInfo->new({ | ||||||||||||||||||||||||||||||||
| 392 | id => $_, | ||||||||||||||||||||||||||||||||
| 393 | key => $pubkey, | ||||||||||||||||||||||||||||||||
| 394 | 2 | algorithm => $self->{algorithm}}); | |||||||||||||||||||||||||||||||
| 395 | } sort keys %$data; | ||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | package Google::Auth::IDTokens::JwkHttpKeySource; | ||||||||||||||||||||||||||||||||
| 399 | 5 | ▶ | use base 'Google::Auth::IDTokens::HttpKeySource'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 400 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 401 | ## | ||||||||||||||||||||||||||||||||
| 402 | # A key source that downloads a JWK set. | ||||||||||||||||||||||||||||||||
| 403 | # | ||||||||||||||||||||||||||||||||
| 404 | ## | ||||||||||||||||||||||||||||||||
| 405 | # Create a key source that downloads a JWT Set. | ||||||||||||||||||||||||||||||||
| 406 | # | ||||||||||||||||||||||||||||||||
| 407 | # @param uri [String,URI] The URI from which to download keys. | ||||||||||||||||||||||||||||||||
| 408 | # @param retry_interval [Integer,nil] Override the retry interval in | ||||||||||||||||||||||||||||||||
| 409 | # seconds. This is the minimum time between retries of failed key | ||||||||||||||||||||||||||||||||
| 410 | # downloads. | ||||||||||||||||||||||||||||||||
| 411 | # | ||||||||||||||||||||||||||||||||
| 412 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||
| 413 | 9 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||
| 414 | 9 | ▶ | my $class = ref $self ? ref $self : $self; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | die "uri is a required parameter$/" . Data::Dumper::Dumper($params) | ||||||||||||||||||||||||||||||||
| 417 | 9 | ▶ | unless exists($params->{uri}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 418 | 9 | $class->SUPER::new($params); | |||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | 6 | ▶ | sub interpret_json { | ||||||||||||||||||||||||||||||
|
Subroutine
interpret_json: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 422 | 6 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||
| 423 | 6 | ▶ | confess 'data is a required argument' unless $data; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 424 | 6 | my $jwks = Google::Auth::IDTokens::KeyInfo->from_jwk_set($data); | |||||||||||||||||||||||||||||||
| 425 | 4 | return @$jwks; | |||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | ## | ||||||||||||||||||||||||||||||||
| 429 | # The URI from which to download keys. | ||||||||||||||||||||||||||||||||
| 430 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 431 | # | ||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | sub uri { return $_[0]->SUPER->uri } | ||||||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | package Google::Auth::IDTokens::AggregateKeySource; | ||||||||||||||||||||||||||||||||
| 435 | ## | ||||||||||||||||||||||||||||||||
| 436 | # A key source that aggregates other key sources. This means it will | ||||||||||||||||||||||||||||||||
| 437 | # aggregate the keys provided by its constituent sources. Additionally, | ||||||||||||||||||||||||||||||||
| 438 | # when asked to refresh, it will refresh all its constituent sources. | ||||||||||||||||||||||||||||||||
| 439 | # | ||||||||||||||||||||||||||||||||
| 440 | ## | ||||||||||||||||||||||||||||||||
| 441 | # Create a key source that aggregates other key sources. | ||||||||||||||||||||||||||||||||
| 442 | # | ||||||||||||||||||||||||||||||||
| 443 | # @param sources [Array<key source>] The key sources to aggregate. | ||||||||||||||||||||||||||||||||
| 444 | # | ||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 446 | 0 | my ($class, $params) = @_; | |||||||||||||||||||||||||||||||
| 447 | die "sources is a required parameter$/" . Data::Dumper::Dumper($params) | ||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | unless exists $params->{sources} && $params->{sources}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $params->{"sources"} and $params->{"sources"}
MC/DC0%0/2
exists $params->{"sources"} and $params->{"sources"}
exists $params->{"sources"}
$params->{"sources"}
Truth table0%0/3
A and B
A= exists $params->{"sources"}B= $params->{"sources"}
| |||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 451 | 0 | my $self = bless {sources => [@{$params->{sources}}]}, $class; | |||||||||||||||||||||||||||||||
| 452 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||
| 455 | ## | ||||||||||||||||||||||||||||||||
| 456 | # Return the current keys, without attempting to refresh. | ||||||||||||||||||||||||||||||||
| 457 | # | ||||||||||||||||||||||||||||||||
| 458 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 459 | # | ||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | sub current_keys { | ||||||||||||||||||||||||||||||
|
Subroutine
current_keys: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 461 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 462 | 0 | my @current_keys_set; | |||||||||||||||||||||||||||||||
| 463 | 0 | foreach my $source (@{$self->{sources}}) { | |||||||||||||||||||||||||||||||
| 464 | 0 | push(@current_keys_set, $source->current_keys); | |||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||
| 466 | 0 | return @current_keys_set; | |||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | ## | ||||||||||||||||||||||||||||||||
| 470 | # Attempt to refresh keys and return the new keys. | ||||||||||||||||||||||||||||||||
| 471 | # | ||||||||||||||||||||||||||||||||
| 472 | # @return [Array<KeyInfo>] | ||||||||||||||||||||||||||||||||
| 473 | # @raise [KeySourceError] if key retrieval failed. | ||||||||||||||||||||||||||||||||
| 474 | # | ||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | sub refresh_keys { | ||||||||||||||||||||||||||||||
|
Subroutine
refresh_keys: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 476 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 477 | 0 | my @current_keys_set; | |||||||||||||||||||||||||||||||
| 478 | 0 | foreach my $source (@{$self->{sources}}) { | |||||||||||||||||||||||||||||||
| 479 | 0 | eval { $source->refresh_keys(); }; | |||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | die "KeySourceError: $@" if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 481 | 0 | push(@current_keys_set, $source->current_keys); | |||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||
| 483 | 0 | return @current_keys_set; | |||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||