AuthorizedKey/SSH2.pm

filter: Statementstmt 65.7% 48 / 73 Branchbran 40.0% 8 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 6 totaltotal 59.0% 65 / 110 CC 12 SCAR 21.9
CC
12
Cov
60%
parse_multi_line
30.0
option_type
6.0
sanity_check
3.5
CRAP 8.9
↑ Summary AuthorizedKeysFile.pm »
1 ###########################################
2 package Net::SSH::AuthorizedKey::SSH2;
3 ###########################################
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Net::SSH::AuthorizedKey::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use base qw(Net::SSH::AuthorizedKey::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Log::Log4perl qw(:easy);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # No additional options, only global ones
11 12 our %VALID_OPTIONS = ();
12  
13 12 our $KEYTYPE_REGEX = qr/rsa|dsa|ssh-rsa|ssh-dss|ssh-ed25519|ecdsa-\S+/;
14  
15 12 our @REQUIRED_FIELDS = qw(
16 encryption
17 );
18  
19 12 __PACKAGE__->make_accessor( $_ ) for
20 (@REQUIRED_FIELDS);
21  
22 ###########################################
23 35 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
24 ###########################################
25 35 my($class, %options) = @_;
26  
27 35 return $class->SUPER::new( %options, type => "ssh-2" );
28 }
29  
30 ###########################################
31 47 ▶sub as_string {
Subroutine as_string: called CC=3 SCAR=11.0
Pod undocumented
32 ###########################################
33 47 my($self) = @_;
34  
35 47 my $string = $self->options_as_string();
36 47 ▶ $string .= " " if length $string;
Branch: 1 branch
BranchTrueFalseTotal
if length $string 22 25 47
37  
38 47 $string .= "$self->{encryption} $self->{key}";
39 47 ▶ $string .= " $self->{email}" if length $self->{email};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"email"} 43 4 47
40  
41 47 return $string;
42 }
43  
44 ###########################################
45 0 ▶sub parse_multi_line {
Subroutine parse_multi_line: not called CC=5 SCAR=34.0
Pod undocumented
46 ###########################################
47 0 my($self, $string) = @_;
48  
49 0 my @fields = ();
50  
51 0 ▶ while($string =~ s/^(.*):\s+(.*)//gm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^(.*):\s+(.*)//gm) 0 0 0
52 0 my($field, $value) = ($1, $2);
53 # remove quotes
54 0 $value =~ s/^"(.*)"$/$1/;
55 0 push @fields, $field, $value;
56 0 my $lcfield = lc $field;
57  
58 0 ▶ if( $self->accessor_exists( $lcfield ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->accessor_exists($lcfield)) { } 0 0 0
59 0 $self->$lcfield( $value );
60 } else {
61 0 WARN "Ignoring unknown field '$field'";
62 }
63 }
64  
65 # Rest is the key, split across several lines
66 0 $string =~ s/\n//g;
67 0 $self->key( $string );
68 0 $self->type( "ssh-2" );
69  
70 # Comment: "rsa-key-20090703"
71 0 ▶ if($self->comment() =~ /\b(.*?)-key/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->comment =~ /\b(.*?)-key/) { } 0 0 0
elsif (not $self->{'strict'}) { } 0 0 0
72 0 $self->encryption( "ssh-" . $1 );
73 } elsif( ! $self->{strict} ) {
74 0 WARN "Unknown encryption [", $self->comment(),
75 "] fixed to ssh-rsa";
76 0 $self->encryption( "ssh-rsa" );
77 }
78 }
79  
80 ###########################################
81 92 ▶sub key_read {
Subroutine key_read: called CC=3 SCAR=11.1
Pod undocumented
82 ############################################
83 92 my($class, $line) = @_;
84  
85 92 ▶ if($line !~ s/^($KEYTYPE_REGEX)\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ s/^($Net::SSH::AuthorizedKey::SSH2::KEYTYPE_REGEX)\s*//) 57 35 92
86 57 DEBUG "No SSH2 keytype found";
87 57 return undef;
88 }
89  
90 35 my $encryption = $1;
91 35 DEBUG "Parsed encryption $encryption";
92  
93 35 ▶ if($line !~ s/^(\S+)\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ s/^(\S+)\s*//) 0 35 35
94 0 DEBUG "No SSH2 key found";
95 0 return undef;
96 }
97  
98 35 my $key = $1;
99 35 DEBUG "Parsed key $key";
100  
101 35 my $email = $line;
102  
103 35 my $obj = __PACKAGE__->new();
104 35 $obj->encryption( $encryption );
105 35 $obj->key( $key );
106 35 $obj->email( $email );
107 35 $obj->comment( $email );
108  
109 35 return $obj;
110 }
111  
112 ###########################################
113 2 ▶sub sanity_check {
Subroutine sanity_check: called CC=3 SCAR=12.5
Pod undocumented
114 ###########################################
115 2 my($self) = @_;
116  
117 2 for my $field (@REQUIRED_FIELDS) {
118 2 ▶ if(! length $self->$field()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->$field) 0 2 2
119 0 WARN "ssh-2 sanity check failed '$field' requirement";
120 0 return undef;
121 }
122 }
123  
124 2 return 1;
125 }
126  
127 ###########################################
128 0 ▶sub option_type {
Subroutine option_type: not called CC=2 SCAR=17.9
Pod undocumented
129 ###########################################
130 0 my($self, $option) = @_;
131  
132 0 ▶ if(exists $VALID_OPTIONS{ $option }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::SSH::AuthorizedKey::SSH2::VALID_OPTIONS{$option}) 0 0 0
133 0 return $VALID_OPTIONS{ $option };
134 }
135  
136 0 return undef;
137 }
138  
139 12 1;
140  
141 __END__
↑ Summary AuthorizedKeysFile.pm »