Bind8/Conf/Key.pm

filter: Statementstmt 29.3% 17 / 58 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 5 / 10 Podpod 100% 4 / 4 totaltotal 22.6% 26 / 115 CC 20 SCAR 41.2
CC
20
Cov
17%
new
132.0
name
42.0
algorithm
12.0
CRAP 61.5
« Bind8/Conf/Trustedkeys.pm ↑ Summary Bind8/Conf/Controls.pm »
1 # Bind8 key directive handling
2 #
3 # Copyright Karthik Krishnamurthy <karthik.k@extremix.net>
4  
5 =head1 NAME
6  
7 Unix::Conf::Bind8::Conf::Key - Class for handling Bind8 configuration
8 directive `key'
9  
10 =head1 SYNOPSIS
11  
12 use Unix::Conf::Bind8;
13  
14 my ($conf, $key, $ret);
15  
16 $conf = Unix::Conf::Bind8->new_conf (
17 FILE => '/etc/named.conf',
18 SECURE_OPEN => 1,
19 ) or $conf->die ("couldn't open `named.conf'");
20  
21 #
22 # Ways to get a key object
23 #
24  
25 $key = $conf->new_key (
26 NAME => 'sample_key',
27 ALGORITHM => 'hmac-md5',
28 SECRET => '"abcdefgh"',
29 ) or $key->die ("couldn't create key");
30  
31 # OR
32  
33 $key = $conf->get_key ('extremix-slaves.key')
34 or $key->die ("couldn't get key");
35  
36 #
37 # Operations that can be performed on a Key object
38 #
39  
40 $ret = $key->name ('some_other_key')
41 or $ret->die ("couldn't set name");
42  
43 $ret = $key->secret ('"secret"')
44 or $ret->die ("couldn't set secret");
45  
46 # get attributes
47 printf ("KEY ID => %s, ALGORITHM => %s, SECRET => %s",
48 $key->name (), $key->algorithm (), $key->secret ());
49  
50 # delete key
51 $ret = $key->delete () or $ret->die ("couldn't delete");
52  
53 $ret = $conf->delete_key ('sample_key')
54 or $ret->die ("couldn't delete");
55  
56 =head1 METHODS
57  
58 =cut
59  
60 package Unix::Conf::Bind8::Conf::Key;
61  
62  
63 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 10 ▶use Unix::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67  
68 10 ▶use Unix::Conf::Bind8::Conf::Directive;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 10 our (@ISA) = qw (Unix::Conf::Bind8::Conf::Directive);
70  
71 10 ▶use Unix::Conf::Bind8::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 =over 4
74  
75 =item new ()
76  
77 Arguments
78 NAME => scalar,
79 ALGORITHM => scalar, # number
80 SECRET => scalar, # quoted string
81 WHERE => 'FIRST'|'LAST'|'BEFORE'|'AFTER'
82 WARG => Unix::Conf::Bind8::Conf::Directive subclass object
83 # WARG is to be provided only in case WHERE eq 'BEFORE
84 # or WHERE eq 'AFTER'
85 PARENT => reference,
86 # to the Conf object datastructure.
87  
88 Class constructor
89 Creates a new Unix::Conf::Bind8::Conf::Key object and returns it, on success,
90 an Err object otherwise. Do not use this constructor directly. Use the
91 Unix::Conf::Bind8::Conf::new_key () method instead.
92  
93 =cut
94  
95 sub new
96 0 ▶{
Subroutine new: not called CC=11 SCAR=48.8
Pod documented
97 0 my $self = shift ();
98 0 my $new = bless ({});
99 0 my %args = @_;
100 0 my $ret;
101  
102 0 ▶ $args{NAME} || return (Unix::Conf->_err ('new', "NAME not defined"));
Branch: 1 branch
BranchTrueFalseTotal
$args{"NAME"} or return "Unix::Conf"->_err("new", "NAME not defined") 0 0 0
103 0 ▶ $args{ALGORITHM}|| return (Unix::Conf->_err ('new', "ALGORITHM not defined"));
Branch: 1 branch
BranchTrueFalseTotal
$args{"ALGORITHM"} or return "Unix::Conf"->_err("new", "ALGORITHM not defined") 0 0 0
104 0 ▶ $args{SECRET} || return (Unix::Conf->_err ('new', "SECRET not defined"));
Branch: 1 branch
BranchTrueFalseTotal
$args{"SECRET"} or return "Unix::Conf"->_err("new", "SECRET not defined") 0 0 0
105 0 ▶ $args{PARENT} || return (Unix::Conf->_err ('new', "PARENT not defined"));
Branch: 1 branch
BranchTrueFalseTotal
$args{"PARENT"} or return "Unix::Conf"->_err("new", "PARENT not defined") 0 0 0
106  
107 0 ▶ $ret = $new->_parent ($args{PARENT}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->_parent($args{"PARENT"}) or return $ret 0 0 0
108 0 ▶ $ret = $new->name ($args{NAME}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->name($args{"NAME"}) or return $ret 0 0 0
109 $ret = $new->algorithm ($args{ALGORITHM})
110 0 ▶ or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->algorithm($args{"ALGORITHM"}) or return $ret 0 0 0
111 0 ▶ $ret = $new->secret ($args{SECRET}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->secret($args{"SECRET"}) or return $ret 0 0 0
112  
113 0 ▶ $args{WHERE} = 'LAST' unless ($args{WHERE});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"WHERE"} 0 0 0
114 $ret = Unix::Conf::Bind8::Conf::_insert_in_list ($new, $args{WHERE}, $args{WARG})
115 0 ▶ or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::_insert_in_list($new, $args{"WHERE"}, $args{"WARG"}) or return $ret 0 0 0
116 0 return ($new);
117 }
118  
119  
120 =item name
121  
122 Arguments
123 value
124  
125 Object method.
126 Get/set the corresponding attribute. Returns the attribute value or true
127 on success, an Err object otherwise.
128  
129 =cut
130  
131 sub name
132 0 ▶{
Subroutine name: not called CC=6 SCAR=37.4
Pod documented
133 0 my ($self, $name) = @_;
134  
135 0 ▶ if ($name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
136 0 my $ret;
137 $ret = Unix::Conf::Bind8::Conf::_del_key ($self) or return ($ret)
138 0 ▶ if ($self->{name});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"name"} 0 0 0
Condition0%0/5
$self->{'name'} && (($ret = Unix::Conf::Bind8::Conf::_del_key($self)) || (return $ret))
!ll&&!rl&&r
000
$ret = Unix::Conf::Bind8::Conf::_del_key($self) or return $ret
l!l
00
MC/DC0%0/2
$self->{'name'} && (($ret = Unix::Conf::Bind8::Conf::_del_key($self)) || (return $ret))
$self->{'name'} $ret = Unix::Conf::Bind8::Conf::_del_key($self)
Truth table0%0/3
A && B
A= $self->{'name'}B= $ret = Unix::Conf::Bind8::Conf::_del_key($self)
ABresult
0X0
100
111
139 0 $self->{name} = $name;
140 0 ▶ $ret = Unix::Conf::Bind8::Conf::_add_key ($self) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::_add_key($self) or return $ret 0 0 0
141 0 $self->dirty (1);
142 0 return (1);
143 }
144 return (
145 defined ($self->{name}) ? $self->{name} :
146 0 ▶ Unix::Conf->_err ('name', "name not defined for key")
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'name'} ? : 0 0 0
147 );
148 }
149  
150 =item algorithm
151  
152 Arguments
153 value
154  
155 Object method.
156 Get/set the corresponding attribute. Returns the attribute value or true
157 on success, an Err object otherwise.
158  
159 =cut
160  
161 sub algorithm
162 0 ▶{
Subroutine algorithm: not called CC=3 SCAR=24.8
Pod documented
163 0 my ($self, $algo) = @_;
164  
165 0 ▶ if ($algo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algo) 0 0 0
166 # validate later
167  
168 0 $self->{algo} = $algo;
169 0 $self->dirty (1);
170 0 return (1);
171 }
172 return (
173 defined ($self->{algo}) ? $self->{algo} :
174 0 ▶ Unix::Conf->_err ('algorithm', "algorithm not defined for key")
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'algo'} ? : 0 0 0
175 );
176 }
177  
178 =item secret
179  
180 Arguments
181 value
182  
183 Object method.
184 Get/set the corresponding attribute. Returns the attribute value or true
185 on success, an Err object otherwise.
186  
187 =cut
188  
189 sub secret
190 0 ▶{
Subroutine secret: not called CC=3 SCAR=24.8
Pod documented
191 0 my ($self, $secret) = @_;
192  
193 0 ▶ if ($secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secret) 0 0 0
194 # strip quotes
195 0 $secret =~ s/^"(.+)"$/$1/;
196 0 $self->{secret} = $secret;
197 0 $self->dirty (1);
198 0 return (1);
199 }
200 return (
201 defined ($self->{secret}) ? $self->{secret} :
202 0 ▶ Unix::Conf->_err ('secret', "secret not defined for key")
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'secret'} ? : 0 0 0
203 );
204 }
205  
206 sub __render
207 0 ▶{
Subroutine __render: not called CC=1 SCAR=6.9
208 0 my $self = $_[0];
209 0 my $rendered;
210  
211 0 $rendered = sprintf (
212 qq /key %s {\n\talgorithm %s;\n\tsecret "%s";\n};/,
213 $self->name (), $self->algorithm (), $self->secret (),
214 );
215 0 return ($self->_rstring (\$rendered));
216 }
217  
218 10 1;
« Bind8/Conf/Trustedkeys.pm ↑ Summary Bind8/Conf/Controls.pm »