Branch Coverage

blib/lib/HTTP/PublicKeyPins.pm
Criterion Covered Total %
branch 51 72 70.8


line true false branch
29 1 34 unless my $handle = 'FileHandle'->new($path)
32 0 34 unless read $handle, my $file_header, _CERTIFICATE_HEADER_SIZE()
35 5 29 if ($file_header =~ /^[-]{5}BEGIN[ ](?:X[.]?509[ ]|TRUSTED[ ])?CERTIFICATE[-]{5}/msx) { }
9 20 elsif ($file_header =~ /^[-]{5}BEGIN[ ](?:RSA[ ])?(PUBLIC|PRIVATE)[ ]KEY[-]{5}/msx) { }
4 16 elsif ($file_header =~ /^[-]{5}BEGIN[ ](?:NEW[ ])?CERTIFICATE[ ]REQUEST[-]{5}/msx) { }
45 1 8 if ($type eq 'PRIVATE') { }
69 1 15 unless (defined $pem_encoded_public_key_string)
90 3 2 if ($file_header =~ /^[-]{5}BEGIN[ ]CERTIFICATE[-]{5}/msx) { }
96 0 2 unless seek $handle, 0, 0
98 0 2 unless defined read($handle, my $pem_encoded_certificate_string, _MAX_PUBLIC_KEY_SIZE())
115 0 4 unless seek $handle, 0, 0
117 0 4 unless defined read($handle, my $pkcs10_certificate_string, _MAX_PUBLIC_KEY_SIZE())
120 0 4 unless my $req = 'Crypt::PKCS10'->new($pkcs10_certificate_string)
131 0 10 unless seek $handle, 0, 0
133 0 10 unless defined read($handle, my $pkcs10_certificate_string, _MAX_PUBLIC_KEY_SIZE())
137 8 2 unless my $req = 'Crypt::PKCS10'->new($pkcs10_certificate_string)
141 8 2 unless (eval { do { Carp::croak("Failed to seek to start of ${path}:$HTTP::PublicKeyPins::EXTENDED_OS_ERROR") unless seek $handle, 0, 0; Carp::croak("Failed to read from ${path}:$HTTP::PublicKeyPins::EXTENDED_OS_ERROR") unless defined read($handle, my $pkcs10_certificate_string, _MAX_PUBLIC_KEY_SIZE()); 'Crypt::PKCS10'->setAPIversion(1); Carp::croak('Failed to initialise Crypt::PKCS10 library:' . 'Crypt::PKCS10'->error) unless my $req = 'Crypt::PKCS10'->new($pkcs10_certificate_string); $pem_encoded_public_key_string = $req->subjectPublicKey(1) } })
151 0 16 unless my $temp_handle = 'FileHandle'->new($path, 0)
159 0 16 unless close $temp_handle
165 11 5 unless (eval { do { Carp::croak("Failed to open '${path}' for reading:$HTTP::PublicKeyPins::EXTENDED_OS_ERROR") unless my $temp_handle = 'FileHandle'->new($path, 0); binmode $temp_handle; my $string; while (defined(my $line = readline $temp_handle)) { do { $string .= $line }; } ; Carp::croak("Failed to close '${path}':$HTTP::PublicKeyPins::EXTENDED_OS_ERROR") unless close $temp_handle; my $x509 = 'Crypt::OpenSSL::X509'->new_from_string($string, 1); $pem_encoded_public_key_string = _get_pem_encoded_public_key_string($x509) } })
174 0 8 unless seek $handle, 0, 0
176 0 8 unless defined read($handle, my $der_encoded_public_key_string, _MAX_PUBLIC_KEY_SIZE())
180 0 8 unless $asn->prepare("SEQUENCE {\n algorithm SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY OPTIONAL },\n subjectPublicKey BIT STRING\n}\n")
188 1 7 unless my $pub_key = $asn->decode($der_encoded_public_key_string)
195 1 7 unless (eval { do { Carp::croak('Failed to decode SubjectPublicKeyInfo in ASN1:' . $asn->error) unless my $pub_key = $asn->decode($der_encoded_public_key_string); $pem_encoded_public_key_string = "-----BEGIN PUBLIC KEY-----\n" . &MIME::Base64::encode_base64($der_encoded_public_key_string) . "-----END PUBLIC KEY-----\n" } })
204 0 11 unless seek $handle, 0, 0
206 0 11 unless defined read($handle, my $der_encoded_private_key_string, _MAX_PUBLIC_KEY_SIZE())
217 10 1 unless (eval { do { my $privkey = 'Crypt::OpenSSL::RSA'->new_private_key($pem_encoded_private_key_string); $pem_encoded_public_key_string = $privkey->get_public_key_x509_string } })
226 0 1 unless seek $handle, 0, 0
228 0 1 unless defined read($handle, my $rsa_private_key_string, _MAX_PUBLIC_KEY_SIZE())
238 1 7 if ($file_header =~ /^[-]{5}BEGIN[ ]RSA[ ]PUBLIC[ ]KEY[-]{5}/msx) { }
239 0 1 unless seek $handle, 0, 0
241 0 1 unless defined read($handle, my $pem_encoded_rsa_public_key_string, _MAX_PUBLIC_KEY_SIZE())
249 0 7 unless seek $handle, 0, 0
251 0 7 unless defined read($handle, $pem_encoded_public_key_string, _MAX_PUBLIC_KEY_SIZE())
261 4 6 if ($x509->key_alg_name eq 'rsaEncryption') { }