Finger/Keyserver.pm

filter: Statementstmt 32.7% 18 / 55 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 1 totaltotal 29.3% 22 / 75 CC 7 SCAR 21.0
CC
7
Cov
28%
_query_index
20.0
fetch
6.0
_get
6.0
CRAP 8.1
« Finger/File.pm ↑ Summary Finger.pm »
1 package PGP::Finger::Keyserver;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 extends 'PGP::Finger::Source';
6  
7 # ABSTRACT: gpgfinger source to query a keyserver
8 1 our $VERSION = '1.1'; # VERSION
9  
10 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use PGP::Finger::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use PGP::Finger::Key;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 has _agent => ( is => 'ro', isa => 'LWP::UserAgent', lazy => 1,
16 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 LWP::UserAgent->new;
18 },
19 1 );
20  
21 1 has 'exact' => ( is => 'rw', isa => 'Bool', default => 1 );
22  
23 1 has 'url' => ( is => 'rw', isa => 'Str',
24 default => 'http://a.keyserver.pki.scientia.net/pks/lookup',
25 );
26  
27 0 ▶sub fetch {
Subroutine fetch: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my ( $self, $addr ) = @_;
29 0 my @ids = $self->_query_index( $addr );
30 0 my $result = PGP::Finger::Result->new( source => 'keyserver' );
31  
32 0 foreach my $id ( @ids ) {
33 0 my $armored = $self->_retrieve_keys('0x'.$id);
34 0 my $key = PGP::Finger::Key->new_armored(
35 mail => $addr,
36 data => $armored,
37 );
38 0 $key->set_attr( source => 'keyserver' );
39 0 $key->set_attr( url => $self->url );
40 0 $key->set_attr( keyid => $id );
41 0 $result->add_key( $key );
42 }
43  
44 0 return $result;
45 }
46  
47 0 ▶sub _get {
Subroutine _get: not called CC=2 SCAR=17.9
48 0 my ( $self, %params ) = @_;
49 0 my $uri = URI->new( $self->url );
50 0 $uri->query_form( \%params );
51 0 my $request = HTTP::Request->new('GET', $uri);
52 0 my $response = $self->_agent->request( $request );
53 0 ▶ if( ! $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
54 0 die("keylookup for $uri failed: ".$response->status_line);
55 }
56 0 return $response;
57 }
58  
59 0 ▶sub _retrieve_keys {
Subroutine _retrieve_keys: not called CC=2 SCAR=17.9
60 0 my ( $self, $id ) = @_;
61 0 my $response = $self->_get(
62 search => $id,
63 op => 'get',
64 exact => $self->exact,
65 options => 'mr',
66 );
67 0 ▶ if( $response->content !~ /^-----BEGIN PGP PUBLIC KEY BLOCK-----/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->content =~ /^-----BEGIN PGP PUBLIC KEY BLOCK-----/) 0 0 0
68 0 die('returned content is not a PGP public key');
69 }
70 0 return $response->content;
71 }
72  
73 0 ▶sub _query_index {
Subroutine _query_index: not called CC=4 SCAR=30.0
74 0 my ( $self, $addr ) = @_;
75 0 my @ids;
76 0 my $response = $self->_get(
77 search => $addr,
78 op => 'index',
79 exact => $self->exact,
80 options => 'mr',
81 );
82 0 my @lines = split(/\r?\n/, $response->content);
83 # info:<version>:<count>
84 # pub:<keyid>:<algo>:<keylen>:<creationdate>:<expirationdate>:<flags>
85 # ...
86 0 shift(@lines);
87 0 ▶ while( my $line = shift(@lines) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @lines) 0 0 0
88 0 ▶ if( $line !~ /^pub:/) { next; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^pub:/) 0 0 0
89 0 ▶ if( $line =~ /^pub:([^:]+):/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^pub:([^:]+):/) { } 0 0 0
90 0 push( @ids, $1 );
91 } else {
92 0 die("unknown line format: ".$line);
93 }
94 }
95 0 return( @ids );
96 }
97  
98 1 1;
99  
100 __END__
« Finger/File.pm ↑ Summary Finger.pm »