Branch Coverage

blib/lib/Crypt/OpenPGP.pm
Criterion Covered Total %
branch 170 314 54.1


line true false branch
115 13 0 unless (ref $ring eq "Crypt::OpenPGP::KeyRing")
116 1 12 unless $ring = "Crypt::OpenPGP::KeyRing"->new("Filename", $ring)
119 6 6 if ($type == 2) { }
136 0 15 unless $f
137 0 15 if -e $f
147 0 10 unless my $cfg = $pgp->{'cfg'} = "Crypt::OpenPGP::Config"->new(%param)
149 0 10 if (not $cfg_file and my $compat = $cfg->get("Compat"))
152 2 8 if ($cfg_file)
157 7 13 unless (defined $cfg->get($s))
158 3 4 $param{'Compat'} ? :
161 0 15 if $ring
164 13 7 if (my $ring = $cfg->get($s))
165 7 6 $s eq 'PubRing' ? :
175 0 0 unless ($data = $param{'Data'})
177 0 0 unless my $file = $param{'Filename'}
178 0 0 unless $data = $pgp->_read_files($file)
180 0 0 unless my $msg = "Crypt::OpenPGP::Message"->new("Data", $data)
184 0 0 unless @pieces
188 0 0 if (ref $pieces[0] eq "Crypt::OpenPGP::Compressed")
189 0 0 unless $data = $pieces[0]->decompress
191 0 0 unless $msg = "Crypt::OpenPGP::Message"->new("Data", $data)
198 0 0 if ($class eq 'Crypt::OpenPGP::OnePassSig' or $class eq 'Crypt::OpenPGP::Signature') { }
201 0 0 unless defined $valid
211 0 0 unless defined $pt
213 0 0 unless defined $valid or $pgp->errstr =~ /^No Signature/
216 0 0 if defined $valid
217 0 0 if defined $sig
225 0 0 if ($cert) { }
245 0 0 $def ? :
246 0 0 if ($noecho)
252 0 0 $ans ? :
258 0 6 unless $pgp->_merge_compat(\%param, "sign")
262 0 6 unless ($data = $param{'Data'})
264 0 0 unless my $file = $param{'Filename'}
265 0 0 unless $data = $pgp->_read_files($file)
267 5 1 unless ($cert = $param{'Key'})
268 0 5 unless my $kid = $param{'KeyID'}
269 0 5 unless my $ring = $pgp->secrings->[0]
271 0 5 unless my $kb = $ring->find_keyblock_by_keyid(pack("H*", $kid))
276 2 4 if ($cert->is_protected)
278 0 2 if (not defined $pass and my $cb = $param{'PassphraseCallback'})
281 0 2 unless $pass
283 0 2 unless $cert->unlock($pass)
287 0 6 if $param{'Filename'}
288 1 5 if ($param{'Clearsign'}) { }
299 0 6 if (my $hash_alg = $param{'Digest'})
300 0 0 unless my $dgst = "Crypt::OpenPGP::Digest"->new($hash_alg)
304 1 5 if $param{'Clearsign'}
311 1 5 if ($param{'Clearsign'})
315 2 4 $param{'Detach'} ? :
316 3 3 if ($param{'Armour'})
320 2 1 $param{'Detach'} ? :
0 3 unless $sig_data = "Crypt::OpenPGP::Armour"->armour("Data", $sig_data, "Object", $param{'Detach'} ? "SIGNATURE" : "MESSAGE")
323 1 5 if ($param{'Clearsign'})
327 0 1 unless $data =~ /\n$/
328 0 1 $hash eq 'MD5' ? :
344 0 1 unless $param{'Signature'} or $param{'SigFile'}
346 9 1 $param{'Signature'} ? :
347 1 9 if $param{'IsPacketStream'}
348 0 10 unless my $msg = "Crypt::OpenPGP::Message"->new(%arg)
352 1 9 if (ref $pieces[0] eq "Crypt::OpenPGP::Compressed")
353 0 1 unless $data = $pieces[0]->decompress
355 0 1 unless $msg = "Crypt::OpenPGP::Message"->new("Data", $data)
360 1 9 if (ref $pieces[0] eq 'Crypt::OpenPGP::OnePassSig') { }
9 0 elsif (ref $pieces[0] eq 'Crypt::OpenPGP::Signature') { }
367 3 7 $sig->{'type'} == 1 ? :
368 3 7 unless ($data)
369 2 1 if ($param{'Data'}) { }
375 0 1 ref $param{'Files'} eq 'ARRAY' ? :
377 1 0 unless defined $fdata
383 8 1 unless ($cert = $param{'Key'})
386 0 8 unless ($ring and $kb = $ring->find_keyblock_by_keyid($key_id))
388 0 0 if ($cfg->get("AutoKeyRetrieve") and $cfg->get("KeyServer"))
395 0 0 unless $kb
411 0 9 unless $dgst = $sig->hash_data($data)
413 9 0 if substr($dgst, 0, 2) eq $sig->{'chk'}
415 0 9 unless $found
417 8 1 $kb && $kb->primary_uid ? :
9 0 $cert->key->public_key->verify($sig, $dgst) ? :
420 1 8 $wants_object ? :
426 0 23 unless $pgp->_merge_compat(\%param, "encrypt")
431 0 23 unless ($data = $param{'Data'})
433 0 0 unless my $file = $param{'Filename'}
434 0 0 unless $data = $pgp->_read_files($file)
437 1 22 if ($param{'SignKeyID'}) { }
446 0 1 unless $ptdata = $pgp->sign("Data", $data, "KeyID", $param{'SignKeyID'}, "Compat", $param{'Compat'}, "Armour", 0, "Passphrase", $param{'SignPassphrase'}, "PassphraseCallback", $param{'SignPassphraseCallback'})
449 0 22 $param{'Filename'} ? :
452 1 22 if (my $alg = $param{'Compress'})
455 0 1 unless my $cdata = "Crypt::OpenPGP::Compressed"->new("Data", $ptdata, "Alg", $alg)
462 0 23 $param{'Cipher'} ? :
464 3 20 if ($param{'Recipients'} and not ref $param{'Recipients'})
467 4 19 if (my $kid = delete $param{'KeyID'})
468 0 4 ref $kid eq 'ARRAY' ? :
471 12 11 if ($param{'Key'} or $param{'Recipients'}) { }
11 0 elsif (my $pass = $param{'Passphrase'}) { }
474 11 1 if (my $recips = $param{'Recipients'})
475 11 0 ref $recips eq 'ARRAY' ? :
480 0 11 if ($cfg->get("AutoKeyRetrieve") and $cfg->get("KeyServer"))
488 14 1 if ($lr == 8 || $lr == 16 and not $r =~ /[^\da-fA-F]/) { }
490 14 0 if $ring
491 0 14 if not @kb and $server
494 1 0 if $ring
495 0 1 if not @kb and $server
499 0 12 unless my $cert = $kb->encrypting_key
500 1 11 if $seen{$cert->key_id}++
505 0 11 if (my $cb = $param{'RecipientsCallback'})
509 1 11 if ($param{'Key'})
511 0 1 ref $param{'Key'} eq 'ARRAY' ? :
513 0 12 unless @keys
516 0 12 unless push @sym_keys, "Crypt::OpenPGP::SessionKey"->new("Key", $key, "SymKey", $key_data, "Cipher", $sym_alg)
528 0 11 if ($param{'Compat'} and $param{'Compat'} eq 'PGP2') { }
534 0 11 unless my $cipher = "Crypt::OpenPGP::Cipher"->new($sym_alg)
538 0 11 unless push @sym_keys, "Crypt::OpenPGP::SKSessionKey"->new("Passphrase", $pass, "SymKey", $key_data, "Cipher", $sym_alg, "S2k", $s2k)
555 0 23 $param{'Passphrase'} && $param{'Compat'} && $param{'Compat'} eq 'PGP2' ? :
558 1 22 if ($param{'Armour'})
560 0 1 unless $enc_data = "Crypt::OpenPGP::Armour"->armour("Data", $enc_data, "Object", "MESSAGE")
573 0 24 unless ($data = $param{'Data'})
575 0 0 unless my $file = $param{'Filename'}
576 0 0 unless $data = $pgp->_read_files($file)
578 0 24 unless my $msg = "Crypt::OpenPGP::Message"->new("Data", $data)
582 0 24 unless @pieces
587 13 11 if (ref $pieces[0] eq 'Crypt::OpenPGP::SessionKey') { }
11 0 elsif (ref $pieces[0] eq 'Crypt::OpenPGP::SKSessionKey') { }
589 10 3 unless ($cert = $param{'Key'})
590 0 10 unless $ring = $pgp->secrings->[0]
595 3 10 if ($cert) { }
596 3 0 if ($cert->key_id eq $sym_key->key_id)
602 10 0 if ($kb = $ring->find_keyblock_by_keyid($sym_key->key_id))
610 0 13 unless $kb or $cert
612 10 3 if ($kb)
616 2 11 if ($cert->is_protected)
618 0 2 if (not defined $pass and my $cb = $param{'PassphraseCallback'})
621 0 2 unless $pass
623 0 2 unless $cert->unlock($pass)
626 0 13 unless ($key, $alg) = $sym_key->decrypt($cert)
632 0 11 if (not defined $pass and my $cb = $param{'PassphraseCallback'})
635 0 11 unless $pass
637 0 11 unless ($key, $alg) = $sym_key->decrypt($pass)
645 0 24 if (not $key || $alg and ref $enc eq "Crypt::OpenPGP::Ciphertext")
647 0 0 unless my $pass = $param{'Passphrase'}
657 0 24 unless $data = $enc->decrypt($key, $alg)
680 2 22 if (ref $pieces[0] eq "Crypt::OpenPGP::Compressed")
681 0 2 unless $data = $pieces[0]->decompress
689 1 23 if (ref $pieces[0] eq 'Crypt::OpenPGP::OnePassSig' or ref $pieces[0] eq 'Crypt::OpenPGP::Signature') { }
692 1 0 if ($wants_verify)
700 1 23 $wants_verify ? :
713 0 2 unless $param{'Type'}
716 1 1 if $param{'Type'} eq "RSA"
722 0 2 unless $pub and $sec
726 0 2 unless my $pubcert = "Crypt::OpenPGP::Certificate"->new("Key", $pub, "Version", $param{'Version'})
732 0 2 unless my $seccert = "Crypt::OpenPGP::Certificate"->new("Key", $sec, "Passphrase", $param{'Passphrase'}, "Version", $param{'Version'})
755 0 1 unless @_
761 1 0 unless open FH, $file
764 0 0 unless close FH
775 0 0 unless my $ref = $COMPAT{$compat}{$meth}
778 0 0 unless exists $param->{$arg}
782 0 0 unless exists $param->{$key}