Branch Coverage

blib/lib/Crypt/OpenPGP.pm
Criterion Covered Total %
branch 164 312 52.5


line true false branch
114 5 0 unless (ref $ring eq 'Crypt::OpenPGP::KeyRing')
115 1 4 unless $ring = 'Crypt::OpenPGP::KeyRing'->new('Filename', $ring)
118 2 2 if ($type == 2) { }
135 0 15 unless $f
136 0 15 if -e $f
146 0 6 unless my $cfg = $pgp->{'cfg'} = 'Crypt::OpenPGP::Config'->new(%param)
148 0 6 if (not $cfg_file and my $compat = $cfg->get('Compat'))
151 2 4 if ($cfg_file)
156 7 5 unless (defined $cfg->get($s))
157 3 4 $param{'Compat'} ? :
160 0 15 if $ring
163 5 7 if (my $ring = $cfg->get($s))
164 3 2 $s eq 'PubRing' ? :
174 0 0 unless ($data = $param{'Data'})
176 0 0 unless my $file = $param{'Filename'}
177 0 0 unless $data = $pgp->_read_files($file)
179 0 0 unless my $msg = 'Crypt::OpenPGP::Message'->new('Data', $data)
183 0 0 unless @pieces
187 0 0 if (ref $pieces[0] eq 'Crypt::OpenPGP::Compressed')
188 0 0 unless $data = $pieces[0]->decompress
190 0 0 unless $msg = 'Crypt::OpenPGP::Message'->new('Data', $data)
197 0 0 if ($class eq 'Crypt::OpenPGP::OnePassSig' or $class eq 'Crypt::OpenPGP::Signature') { }
200 0 0 unless defined $valid
210 0 0 unless defined $pt
212 0 0 unless defined $valid or $pgp->errstr =~ /^No Signature/
215 0 0 if defined $valid
216 0 0 if defined $sig
224 0 0 if ($cert) { }
244 0 0 $def ? :
245 0 0 if ($noecho)
251 0 0 $ans ? :
257 0 6 unless $pgp->_merge_compat(\%param, 'sign')
261 0 6 unless ($data = $param{'Data'})
263 0 0 unless my $file = $param{'Filename'}
264 0 0 unless $data = $pgp->_read_files($file)
266 5 1 unless ($cert = $param{'Key'})
267 0 5 unless my $kid = $param{'KeyID'}
268 0 5 unless my $ring = $pgp->secrings->[0]
270 0 5 unless my $kb = $ring->find_keyblock_by_keyid(pack('H*', $kid))
275 2 4 if ($cert->is_protected)
277 0 2 if (not defined $pass and my $cb = $param{'PassphraseCallback'})
280 0 2 unless $pass
282 0 2 unless $cert->unlock($pass)
286 0 6 if $param{'Filename'}
287 1 5 if ($param{'Clearsign'}) { }
298 0 6 if (my $hash_alg = $param{'Digest'})
299 0 0 unless my $dgst = 'Crypt::OpenPGP::Digest'->new($hash_alg)
303 1 5 if $param{'Clearsign'}
310 1 5 if ($param{'Clearsign'})
314 2 4 $param{'Detach'} ? :
315 3 3 if ($param{'Armour'})
319 2 1 $param{'Detach'} ? :
0 3 unless $sig_data = 'Crypt::OpenPGP::Armour'->armour('Data', $sig_data, 'Object', $param{'Detach'} ? 'SIGNATURE' : 'MESSAGE')
322 1 5 if ($param{'Clearsign'})
326 0 1 unless $data =~ /\n$/
327 0 1 $hash eq 'MD5' ? :
343 0 0 unless $param{'Signature'} or $param{'SigFile'}
345 7 0 $param{'Signature'} ? :
346 1 6 if $param{'IsPacketStream'}
347 0 7 unless my $msg = 'Crypt::OpenPGP::Message'->new(%arg)
351 0 7 if (ref $pieces[0] eq 'Crypt::OpenPGP::Compressed')
352 0 0 unless $data = $pieces[0]->decompress
354 0 0 unless $msg = 'Crypt::OpenPGP::Message'->new('Data', $data)
359 0 7 if (ref $pieces[0] eq 'Crypt::OpenPGP::OnePassSig') { }
7 0 elsif (ref $pieces[0] eq 'Crypt::OpenPGP::Signature') { }
366 2 5 unless ($data)
367 1 1 if ($param{'Data'}) { }
373 0 1 ref $param{'Files'} eq 'ARRAY' ? :
375 1 0 unless defined $fdata
381 5 1 unless ($cert = $param{'Key'})
384 0 5 unless ($ring and $kb = $ring->find_keyblock_by_keyid($key_id))
386 0 0 if ($cfg->get('AutoKeyRetrieve') and $cfg->get('KeyServer'))
393 0 0 unless $kb
409 0 6 unless $dgst = $sig->hash_data($data)
411 6 0 if substr($dgst, 0, 2) eq $sig->{'chk'}
413 0 6 unless $found
415 5 1 $kb && $kb->primary_uid ? :
6 0 $cert->key->public_key->verify($sig, $dgst) ? :
418 1 5 $wants_object ? :
424 0 23 unless $pgp->_merge_compat(\%param, 'encrypt')
429 0 23 unless ($data = $param{'Data'})
431 0 0 unless my $file = $param{'Filename'}
432 0 0 unless $data = $pgp->_read_files($file)
435 1 22 if ($param{'SignKeyID'}) { }
444 0 1 unless $ptdata = $pgp->sign('Data', $data, 'KeyID', $param{'SignKeyID'}, 'Compat', $param{'Compat'}, 'Armour', 0, 'Passphrase', $param{'SignPassphrase'}, 'PassphraseCallback', $param{'SignPassphraseCallback'})
447 0 22 $param{'Filename'} ? :
450 1 22 if (my $alg = $param{'Compress'})
453 0 1 unless my $cdata = 'Crypt::OpenPGP::Compressed'->new('Data', $ptdata, 'Alg', $alg)
460 0 23 $param{'Cipher'} ? :
462 3 20 if ($param{'Recipients'} and not ref $param{'Recipients'})
465 4 19 if (my $kid = delete $param{'KeyID'})
466 0 4 ref $kid eq 'ARRAY' ? :
469 12 11 if ($param{'Key'} or $param{'Recipients'}) { }
11 0 elsif (my $pass = $param{'Passphrase'}) { }
472 11 1 if (my $recips = $param{'Recipients'})
473 11 0 ref $recips eq 'ARRAY' ? :
478 0 11 if ($cfg->get('AutoKeyRetrieve') and $cfg->get('KeyServer'))
486 14 1 if ($lr == 8 || $lr == 16 and not $r =~ /[^\da-fA-F]/) { }
488 14 0 if $ring
489 0 14 if not @kb and $server
492 1 0 if $ring
493 0 1 if not @kb and $server
497 0 15 unless my $cert = $kb->encrypting_key
498 1 14 if $seen{$cert->key_id}++
503 0 11 if (my $cb = $param{'RecipientsCallback'})
507 1 11 if ($param{'Key'})
509 0 1 ref $param{'Key'} eq 'ARRAY' ? :
511 0 12 unless @keys
514 0 15 unless push @sym_keys, 'Crypt::OpenPGP::SessionKey'->new('Key', $key, 'SymKey', $key_data, 'Cipher', $sym_alg)
526 0 11 if ($param{'Compat'} and $param{'Compat'} eq 'PGP2') { }
532 0 11 unless my $cipher = 'Crypt::OpenPGP::Cipher'->new($sym_alg)
536 0 11 unless push @sym_keys, 'Crypt::OpenPGP::SKSessionKey'->new('Passphrase', $pass, 'SymKey', $key_data, 'Cipher', $sym_alg, 'S2k', $s2k)
553 0 23 $param{'Passphrase'} && $param{'Compat'} && $param{'Compat'} eq 'PGP2' ? :
556 1 22 if ($param{'Armour'})
558 0 1 unless $enc_data = 'Crypt::OpenPGP::Armour'->armour('Data', $enc_data, 'Object', 'MESSAGE')
571 0 23 unless ($data = $param{'Data'})
573 0 0 unless my $file = $param{'Filename'}
574 0 0 unless $data = $pgp->_read_files($file)
576 0 23 unless my $msg = 'Crypt::OpenPGP::Message'->new('Data', $data)
580 0 23 unless @pieces
585 12 11 if (ref $pieces[0] eq 'Crypt::OpenPGP::SessionKey') { }
11 0 elsif (ref $pieces[0] eq 'Crypt::OpenPGP::SKSessionKey') { }
587 9 3 unless ($cert = $param{'Key'})
588 0 9 unless $ring = $pgp->secrings->[0]
593 4 10 if ($cert) { }
594 3 1 if ($cert->key_id eq $sym_key->key_id)
600 9 1 if ($kb = $ring->find_keyblock_by_keyid($sym_key->key_id))
608 0 12 unless $kb or $cert
610 9 3 if ($kb)
614 1 11 if ($cert->is_protected)
616 0 1 if (not defined $pass and my $cb = $param{'PassphraseCallback'})
619 0 1 unless $pass
621 0 1 unless $cert->unlock($pass)
624 0 12 unless ($key, $alg) = $sym_key->decrypt($cert)
630 0 11 if (not defined $pass and my $cb = $param{'PassphraseCallback'})
633 0 11 unless $pass
635 0 11 unless ($key, $alg) = $sym_key->decrypt($pass)
643 0 23 if (not $key || $alg and ref $enc eq 'Crypt::OpenPGP::Ciphertext')
645 0 0 unless my $pass = $param{'Passphrase'}
655 0 23 unless $data = $enc->decrypt($key, $alg)
678 1 22 if (ref $pieces[0] eq 'Crypt::OpenPGP::Compressed')
679 0 1 unless $data = $pieces[0]->decompress
687 1 22 if (ref $pieces[0] eq 'Crypt::OpenPGP::OnePassSig' or ref $pieces[0] eq 'Crypt::OpenPGP::Signature') { }
690 1 0 if ($wants_verify)
698 1 22 $wants_verify ? :
711 0 2 unless $param{'Type'}
714 1 1 if $param{'Type'} eq 'RSA'
720 0 2 unless $pub and $sec
724 0 2 unless my $pubcert = 'Crypt::OpenPGP::Certificate'->new('Key', $pub, 'Version', $param{'Version'})
730 0 2 unless my $seccert = 'Crypt::OpenPGP::Certificate'->new('Key', $sec, 'Passphrase', $param{'Passphrase'}, 'Version', $param{'Version'})
753 0 1 unless @_
759 1 0 unless open FH, $file
762 0 0 unless close FH
773 0 0 unless my $ref = $Crypt::OpenPGP::COMPAT{$compat}{$meth}
776 0 0 unless exists $param->{$arg}
780 0 0 unless exists $param->{$key}