blib/lib/File/SOPS/Metadata.pm

filter: Statementstmt 98.9% 366 / 370 Branchbran 93.7% 240 / 256 Conditioncond 86.0% 86 / 100 MC/DCmcdc 73.3% 44 / 60 Subroutinesub 100% 48 / 48 Podpod 91.6% 11 / 12 totaltotal 93.9% 795 / 846 CC 169 SCAR 25.6
CC
169
Cov
95%
_re2_divergent_construct
35.1
_go_parse_int
17.0
should_encrypt_path
16.2
CRAP 12.9
↑ Summary blib/lib/File/SOPS.pm »
1 package File::SOPS::Metadata;
2 # ABSTRACT: SOPS metadata section handling
3 96 our $VERSION = '0.005';
4 96 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 96 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 96 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 96 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 96 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 96 ▶use File::SOPS::Encrypted;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 96 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 96 our $SOPS_VERSION = '3.7.3';
13  
14 # The encryption rules this class models, in the order should_encrypt_path
15 # applies them.
16 96 our @ENCRYPTION_RULES = qw(
17 unencrypted_suffix encrypted_suffix unencrypted_regex encrypted_regex
18 );
19  
20 # Rules the reference implementation has and this distribution does not: they
21 # select values by the COMMENT attached to them, and neither of our parsers
22 # keeps comments. They are listed because they take part in the mutual
23 # exclusion below -- a document carrying one of these must not also carry one
24 # of ours, whether we understand it or not.
25 96 our @UNSUPPORTED_ENCRYPTION_RULES = qw(
26 unencrypted_comment_regex encrypted_comment_regex
27 );
28  
29 96 our $DEFAULT_UNENCRYPTED_SUFFIX = '_unencrypted';
30  
31 # Every field that holds the data key wrapped for one recipient or one
32 # backend. key_groups is in the list although this class does not model it:
33 # whatever else it is, it holds wrapped copies of the data key, and a caller
34 # generating a new one has to know it is there.
35 96 our @KEY_MATERIAL_FIELDS = qw(
36 age pgp kms gcp_kms azure_kv hc_vault key_groups
37 );
38 96 my %IS_KEY_MATERIAL = map { $_ => 1 } @KEY_MATERIAL_FIELDS;
39  
40 # Everything this class holds in an attribute of its own. Anything else in a
41 # document's sops section goes to, and comes back out of, `extra`.
42 96 my %MODELLED_FIELD = map { $_ => 1 } qw(
43 age pgp kms gcp_kms azure_kv hc_vault
44 mac lastmodified version mac_only_encrypted
45 ), @ENCRYPTION_RULES;
46  
47 # The fields sops declares as a Go string. Everything a `sops` section holds
48 # is one of these except the per-backend key lists, mac_only_encrypted (bool)
49 # and shamir_threshold (int) -- and except a field neither implementation
50 # knows, which sops ignores whatever it holds. The two comment rules are in
51 # the list although this distribution does not implement them: it reads them,
52 # and to sops they are strings exactly like the four it does implement.
53 96 my @STRING_FIELDS = (
54 qw( mac lastmodified version ),
55 @ENCRYPTION_RULES,
56 @UNSUPPORTED_ENCRYPTION_RULES,
57 );
58  
59  
60 890 ▶has age => (is => 'rw', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
61  
62  
63 891 ▶has pgp => (is => 'rw', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
64  
65  
66 891 ▶has kms => (is => 'rw', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
67  
68  
69 891 ▶has gcp_kms => (is => 'rw', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
70  
71  
72 891 ▶has azure_kv => (is => 'rw', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
73  
74  
75 891 ▶has hc_vault => (is => 'rw', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
76  
77  
78 96 has mac => (is => 'rw');
79  
80  
81 96 has lastmodified => (is => 'rw');
82  
83  
84 890 ▶has version => (is => 'rw', default => sub { $SOPS_VERSION });
Subroutine __ANON__: called CC=1 SCAR=0.0
85  
86  
87 96 has unencrypted_suffix => (
88 is => 'rw',
89 lazy => 1,
90 builder => '_build_unencrypted_suffix',
91 );
92  
93 # The default applies only when NO other rule was asked for. sops does the
94 # same (`sops -e` writes `unencrypted_suffix: _unencrypted`, but
95 # `sops -e --encrypted-suffix _enc` writes only `encrypted_suffix: _enc`), and
96 # it is not cosmetic: the six rule fields are mutually exclusive and sops
97 # refuses a document carrying two of them outright, so a default that ignored
98 # the others would make every configured document unreadable.
99 844 ▶sub _build_unencrypted_suffix {
Subroutine _build_unencrypted_suffix: called CC=2 SCAR=6.9
100 844 my ($self) = @_;
101 844 ▶ return undef if $self->_other_rules_configured('unencrypted_suffix');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_other_rules_configured("unencrypted_suffix") 190 654 844
102 654 return $DEFAULT_UNENCRYPTED_SUFFIX;
103 }
104  
105  
106 96 has encrypted_suffix => (is => 'rw');
107  
108  
109 96 has unencrypted_regex => (is => 'rw');
110  
111  
112 96 has encrypted_regex => (is => 'rw');
113  
114  
115 96 has mac_only_encrypted => (is => 'rw');
116  
117  
118 857 ▶has extra => (is => 'rw', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
119  
120  
121 1837 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
122 1837 my ($self) = @_;
123  
124 # unencrypted_suffix's builder stands its default down as soon as another
125 # rule is configured, so asking the object -- rather than counting the
126 # constructor arguments -- cannot report the default as a conflict.
127 my @set = grep {
128 1837 my $value = $self->rule_value($_);
129 11022 ▶ defined $value && length $value;
Condition66%2/3
defined $value && length $value
!ll&&!rl&&r
948201540
MC/DC50%1/2
defined $value && length $value
defined $value length $value
Truth table66%2/3
A && B
A= defined $valueB= length $value
ABresult
0X0
100
111
130 } @ENCRYPTION_RULES, @UNSUPPORTED_ENCRYPTION_RULES;
131  
132 1837 ▶ croak "Cannot use more than one of "
Branch: 1 branch
BranchTrueFalseTotal
if @set > 1 3 1834 1837
133 . join(', ', @ENCRYPTION_RULES, @UNSUPPORTED_ENCRYPTION_RULES)
134 . " in the same document (got " . join(' and ', @set) . "); "
135 . "sops refuses such a file outright"
136 if @set > 1;
137  
138 1834 return;
139 }
140  
141 # The name of a configured rule field other than $except, or undef if there is
142 # none. $except keeps unencrypted_suffix's lazy builder from asking for the
143 # value it is in the middle of producing.
144 844 ▶sub _other_rules_configured {
Subroutine _other_rules_configured: called CC=5 SCAR=16.1
145 844 my ($self, $except) = @_;
146  
147 844 for my $rule (@ENCRYPTION_RULES, @UNSUPPORTED_ENCRYPTION_RULES) {
148 4533 ▶ next if $rule eq $except;
Branch: 1 branch
BranchTrueFalseTotal
if $rule eq $except 844 3689 4533
149 3689 my $value = $self->rule_value($rule);
150 3689 ▶ return $rule if defined $value && length $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and length $value 190 3499 3689
Condition66%2/3
defined $value and length $value
!ll&&!rl&&r
34990190
MC/DC50%1/2
defined $value and length $value
defined $value length $value
Truth table66%2/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
151 }
152  
153 654 return;
154 }
155  
156 16089 ▶sub rule_value {
Subroutine rule_value: called CC=2 SCAR=6.9
Pod documented
157 16089 my ($self, $rule) = @_;
158 16089 ▶ return $self->$rule if $self->can($rule);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($rule) 9729 6360 16089
159 6360 return $self->extra->{$rule};
160 }
161  
162  
163 34 ▶sub policy_args {
Subroutine policy_args: called CC=2 SCAR=6.9
Pod documented
164 34 my ($self) = @_;
165  
166 # All four are handed over even when undef, because "no rule at all" is a
167 # setting and not an absence: passing them through as explicit undef is
168 # what stops the constructor's default from inventing an
169 # unencrypted_suffix the source document did not have -- which would leave
170 # every key ending in _unencrypted in plaintext on the next write.
171 34 my %args = map { $_ => $self->$_ } @ENCRYPTION_RULES;
172 34 ▶ $args{mac_only_encrypted} = 1 if $self->mac_only_encrypted;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mac_only_encrypted 2 32 34
173  
174 # Unmodelled fields come along, minus any that turn out to hold key
175 # material: key_groups wraps the data key that is about to be replaced,
176 # so carrying it over would leave the new document advertising a stale
177 # copy of the old key.
178 $args{extra} = {
179 3 map { $_ => $self->extra->{$_} }
180 34 grep { !$IS_KEY_MATERIAL{$_} } keys %{ $self->extra }
181 };
182  
183 34 return %args;
184 }
185  
186  
187 70 ▶sub key_material_fields {
Subroutine key_material_fields: called CC=3 SCAR=11.0
Pod documented
188 70 my ($self) = @_;
189  
190 return grep {
191 70 ▶ my $value = $self->can($_) ? $self->$_ : $self->extra->{$_};
Branch: 1 branch
BranchTrueFalseTotal
$self->can($_) ? : 420 70 490
192 490 ▶ ref $value eq 'ARRAY' ? scalar @$value : defined $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 421 69 490
193 } @KEY_MATERIAL_FIELDS;
194 }
195  
196  
197 # What the `sops` entry turned out to be, for the refusal below. Names the
198 # shape only -- never the value, which in a document using that key for its own
199 # purposes is the user's data.
200 70 ▶sub _shape_of {
Subroutine _shape_of: called CC=5 SCAR=16.1
201 70 my ($value) = @_;
202 70 ▶ return 'null' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 6 64 70
203 64 my $ref = ref $value;
204 64 ▶ return 'a scalar' unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 8 56 64
205 56 ▶ return 'a list' if $ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "ARRAY" 27 29 56
206 29 ▶ return 'a code reference' if $ref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "CODE" 9 20 29
207 20 return "a $ref reference";
208 }
209  
210 ###############################################################################
211 # Weak decoding -- the two fields in a `sops` section that are not strings
212 #
213 # sops decodes its whole metadata section through mapstructure with
214 # WeaklyTypedInput, so a field's TEXT is read as its type: `mac_only_encrypted:
215 # "false"` is the boolean false and `shamir_threshold: "2"` is the integer 2.
216 # Anything outside the accepted set is not guessed at -- sops stops with
217 # `cannot parse value as 'bool'` / `as 'int'` and exit 1.
218 #
219 # That is not a property of the untyped ENV and INI encodings, which is what
220 # decides that this lives HERE and not in File::SOPS::Metadata::Flat->unflatten:
221 # measured against sops 3.13.3 in a NESTED yaml section, a quoted "false" is
222 # false there too. Coercing in unflatten would leave the identical bug in the
223 # format that has a handler today. See docs/adr/0042, and t/55 for the tables.
224 #
225 # It matters most for mac_only_encrypted, which PICKS THE DIGEST: with it set
226 # the MAC covers only the encrypted values, behind a 32-byte prefix. Perl's
227 # 'false' is TRUE, so reading the string as Perl would means computing the
228 # wrong MAC for a document sops reads at exit 0.
229  
230 # strconv.ParseBool's accepted set, exactly -- and it is short. `yes`, `no`,
231 # `on` and `off` are NOT in it, in any case, quoted or bare.
232 96 my %PARSE_BOOL = (
233 '1' => 1, 't' => 1, 'T' => 1, 'TRUE' => 1, 'true' => 1, 'True' => 1,
234 '0' => 0, 'f' => 0, 'F' => 0, 'FALSE' => 0, 'false' => 0, 'False' => 0,
235 );
236  
237 # A reference where sops wants a scalar: it refuses with "expected type 'bool',
238 # got unconvertible type". A JSON::PP::Boolean is not one of these -- it is the
239 # typed value itself.
240 3333 ▶sub _is_unconvertible {
Subroutine _is_unconvertible: called CC=4 SCAR=13.9
241 3333 my ($value) = @_;
242 3333 ▶ return 0 unless ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 3256 77 3333
243 77 ▶ return 0 if blessed($value) && $value->isa('JSON::PP::Boolean');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("JSON::PP::Boolean") 27 50 77
Condition100%3/3
builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
!ll&&!rl&&r
41927
MC/DC100%2/2
builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
builtin::blessed($value) $value->isa("JSON::PP::Boolean")
Truth table100%3/3
A and B
A= builtin::blessed($value)B= $value->isa("JSON::PP::Boolean")
ABresult
0X0
100
111
244 50 return 1;
245 }
246  
247 # Whether the parser already typed this scalar. Asked of
248 # File::SOPS::Encrypted->detect_type rather than of the SV flags here, so that
249 # the question "is this a string or a number" has ONE answer in this
250 # distribution -- see ADR 0002. Only a string is decoded; a value that arrived
251 # typed is what sops's decoder does no work on.
252 956 ▶sub _is_text {
Subroutine _is_text: called CC=2 SCAR=6.9
253 956 my ($value) = @_;
254 956 ▶ return File::SOPS::Encrypted->detect_type($value) eq 'str' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
'File::SOPS::Encrypted'->detect_type($value) eq 'str' ? : 914 42 956
255 }
256  
257 # The other side of the same weak decoding: the fields that ARE strings.
258 # mapstructure stringifies whatever scalar it finds there -- measured on sops
259 # 3.13.3, `unencrypted_suffix: 3` is read as "3", `true` as "1" and `1e20` as
260 # "100000000000000000000", and `sops rotate` writes that text back out -- but
261 # a LIST or a MAP is refused outright, in every one of them, exit 1. So this
262 # refuses the container and passes the scalar through; Perl's own text agrees
263 # with Go's for every spelling but a float outside positional range, which no
264 # document either implementation writes can carry. docs/adr/0043.
265 #
266 # The refusal is not decoration. Measured before it landed: `encrypted_regex:
267 # []` reached should_encrypt_key as the pattern, matched no key, and
268 # File::SOPS->rotate wrote every value of the document in PLAINTEXT and
269 # reported success -- for a document sops will not open at all. A reference in
270 # `lastmodified` becomes the AAD of the MAC, whose bytes are then a memory
271 # address.
272 3203 ▶sub _assert_string_field {
Subroutine _assert_string_field: called CC=2 SCAR=6.9
273 3203 my ($field, $value) = @_;
274  
275 3203 ▶ croak "the 'sops' section's '$field' is " . _shape_of($value) . ", and a "
Branch: 1 branch
BranchTrueFalseTotal
if _is_unconvertible($value) 46 3157 3203
276 . "string is what belongs there. sops refuses the same document with "
277 . "\"'$field' expected type 'string', got unconvertible type\", exit 1."
278 if _is_unconvertible($value);
279  
280 3157 return $value;
281 }
282  
283 958 ▶sub _decode_bool_field {
Subroutine _decode_bool_field: called CC=7 SCAR=19.5
284 958 my ($field, $value) = @_;
285  
286 958 ▶ return $value unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 881 77 958
287  
288 77 ▶ croak "the 'sops' section's '$field' is " . _shape_of($value) . ", and a "
Branch: 1 branch
BranchTrueFalseTotal
if _is_unconvertible($value) 2 75 77
289 . "boolean is what belongs there. sops refuses the same document with "
290 . "\"'$field' expected type 'bool', got unconvertible type\", exit 1."
291 if _is_unconvertible($value);
292  
293 # A real boolean passes through, and so does a number: Go asks `!= 0` of
294 # one, which is Perl's own truth for it.
295 75 ▶ return $value unless _is_text($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_text($value) 35 40 75
296  
297 # mapstructure maps the empty string to the zero value before ParseBool
298 # ever sees it, so `mac_only_encrypted: ""` is false and not an error.
299 40 ▶ return JSON->false unless length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 2 38 40
300  
301 croak "the 'sops' section's '$field' is '$value', which sops cannot read "
302 . "as a boolean. It decodes that section weakly, through "
303 . "strconv.ParseBool -- 1, t, T, TRUE, true, True, 0, f, F, FALSE, "
304 . "false, False, and the empty string as false -- and refuses "
305 . "anything else with \"cannot parse value as 'bool'\", exit 1. Note "
306 . "that yes, no, on and off are not in that set."
307 38 ▶ unless exists $PARSE_BOOL{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $PARSE_BOOL{$value} 10 28 38
308  
309 # A JSON::PP::Boolean and not 1/0, so that every emitter writes `true` or
310 # `false` rather than degrading it to an int on the next write.
311 28 ▶ return $PARSE_BOOL{$value} ? JSON->true : JSON->false;
Branch: 1 branch
BranchTrueFalseTotal
$PARSE_BOOL{$value} ? : 14 14 28
312 }
313  
314 # Go's RFC3339 grammar, as the layout `2006-01-02T15:04:05Z07:00` and Go's
315 # fallback parser accept it. Deliberately lexical and deliberately without the
316 # range checks: Go applies those AFTER lexing, so a month of 13 or an offset
317 # hour of 25 only ever appears in a document sops refuses at exit 1, where the
318 # AAD we would derive is unobservable. What the corners look like is measured
319 # in docs/adr/0044 -- a one-digit HOUR is accepted where a one-digit month is
320 # not, the fraction may be introduced by a comma, and `T` and `Z` are
321 # case-sensitive.
322 96 my $RFC3339 = qr{
323 \A
324 ( [0-9]{4} ) - ( [0-9]{2} ) - ( [0-9]{2} ) # year, month, day
325 T
326 ( [0-9]{1,2} ) : ( [0-9]{2} ) : ( [0-9]{2} ) # hour (one digit or two), minute, second
327 (?: [.,] [0-9]+ )? # fractional seconds, dropped
328 (?: Z | ( [+-] ) ( [0-9]{2} ) : ( [0-9]{2} ) )
329 \z
330 }x;
331  
332 # `time.Parse(time.RFC3339, $text).Format(time.RFC3339)` -- the value sops
333 # hands to the MAC as its AAD, and writes back into the document. Returns
334 # undef exactly where the text does not parse, which is where from_hash keeps
335 # the document's own bytes.
336 #
337 # The round trip is purely lexical because the location Go builds is a fixed
338 # zone carrying the offset it just read: the wall-clock fields it formats back
339 # are the ones it parsed, so nothing is converted and no calendar is involved.
340 # The zone is the one part that IS recomputed, from the TOTAL offset -- +00:60
341 # comes back out as +01:00 -- and it is written `Z` whenever that total is
342 # zero, whichever sign the document spelled it with. See docs/adr/0044.
343 829 ▶sub _go_rfc3339_form {
Subroutine _go_rfc3339_form: called CC=4 SCAR=13.9
344 829 my ($text) = @_;
345  
346 829 ▶ my ($year, $month, $day, $hour, $minute, $second, $sign, $zone_hour,
Branch: 1 branch
BranchTrueFalseTotal
() = $text =~ /$RFC3339/ or return undef 702 127 829
347 $zone_minute) = $text =~ $RFC3339
348 or return undef;
349  
350 702 my $zone = 'Z';
351 702 ▶ if (defined $sign) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sign) 66 636 702
352 66 my $offset = $zone_hour * 60 + $zone_minute;
353 66 ▶ $zone = sprintf '%s%02d:%02d', $sign, int($offset / 60), $offset % 60
Branch: 1 branch
BranchTrueFalseTotal
if $offset 51 15 66
354 if $offset;
355 }
356  
357 702 return sprintf '%s-%s-%sT%02d:%s:%s%s',
358 $year, $month, $day, $hour, $minute, $second, $zone;
359 }
360  
361 # `lastmodified` is a Go string where mapstructure decodes it and a
362 # `time.Time` everywhere after that, and the AAD of the metadata MAC is taken
363 # from the second one. A document is therefore free to spell the instant in
364 # any RFC3339 form -- sops reads it and authenticates the MAC with its own
365 # rendering -- so the value this class holds has to be that rendering rather
366 # than the document's text. Measured 45 spellings deep in docs/adr/0044, which
367 # also records why an unparseable one is passed through instead of refused.
368 958 ▶sub _decode_lastmodified {
Subroutine _decode_lastmodified: called CC=4 SCAR=13.9
369 958 my ($value) = @_;
370  
371 958 ▶ return $value unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 128 830 958
372 830 ▶ return $value unless _is_text($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_text($value) 1 829 830
373  
374 829 ▶ return _go_rfc3339_form($value) // $value;
Condition66%2/3
_go_rfc3339_form($value) // $value
l!l&&r!l&&!r
7021270
MC/DC0%0/2
_go_rfc3339_form($value) // $value
_go_rfc3339_form($value) $value
Truth table66%2/3
A // B
A= _go_rfc3339_form($value)B= $value
ABresult
1X1
011
000
375 }
376  
377 53 ▶sub _decode_int_field {
Subroutine _decode_int_field: called CC=6 SCAR=17.9
378 53 my ($field, $value) = @_;
379  
380 53 ▶ return $value unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 53 53
381  
382 53 ▶ croak "the 'sops' section's '$field' is " . _shape_of($value) . ", and an "
Branch: 1 branch
BranchTrueFalseTotal
if _is_unconvertible($value) 2 51 53
383 . "integer is what belongs there. sops refuses the same document with "
384 . "\"'$field' expected type 'int', got unconvertible type\", exit 1."
385 if _is_unconvertible($value);
386  
387 51 ▶ return $value unless _is_text($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_text($value) 6 45 51
388  
389 # Same rule as above, one type over: the empty string is the zero value.
390 45 ▶ return 0 unless length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 1 44 45
391  
392 44 my $number = _go_parse_int($value);
393  
394 44 ▶ croak "the 'sops' section's '$field' is '$value', which sops cannot read "
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 22 22 44
395 . "as an integer. It decodes that section weakly, through "
396 . "strconv.ParseInt(s, 0, 64): the spelling picks the base (0x hex, "
397 . "0b binary, 0o or a bare leading zero octal, otherwise decimal), "
398 . "underscores may separate digits, and the value has to fit Go's "
399 . "int64. Anything else is refused with \"cannot parse value as "
400 . "'int'\", exit 1."
401 unless defined $number;
402  
403 22 return $number;
404 }
405  
406 # strconv.ParseInt($text, 0, 64) -- the call mapstructure makes for an int
407 # field. Returns undef exactly where Go returns an error. Measured row for row
408 # against sops 3.13.3 (t/55): "010" is 8 and not 10, "0x10" is 16, "1_000" is
409 # 1000, and " 2", "2 ", "08", "1__0" and 2**63 are all refused.
410 44 ▶sub _go_parse_int {
Subroutine _go_parse_int: called CC=17 SCAR=28.3
411 44 my ($text) = @_;
412  
413 44 ▶ return undef unless _underscores_ok($text);
Branch: 1 branch
BranchTrueFalseTotal
unless _underscores_ok($text) 5 39 44
414  
415 39 my $rest = $text;
416 39 ▶ my $negative = ($rest =~ s/\A([+-])//) && $1 eq '-';
Condition100%3/3
$rest =~ s/\A([+-])// && $1 eq '-'
!ll&&!rl&&r
3126
MC/DC100%2/2
$rest =~ s/\A([+-])// && $1 eq '-'
$rest =~ s/\A([+-])// $1 eq '-'
Truth table100%3/3
A && B
A= $rest =~ s/\A([+-])//B= $1 eq '-'
ABresult
0X0
100
111
417  
418 # ParseUint's own emptiness check, which is why a bare sign is an error.
419 39 ▶ return undef unless length $rest;
Branch: 1 branch
BranchTrueFalseTotal
unless length $rest 2 37 39
420  
421 # The base prefix. Go tests len(s) >= 3 here, so `0x` on its own is not a
422 # prefix at all -- it falls through to the bare-leading-zero octal and
423 # then fails on the digit `x`.
424 37 my $base = 10;
425 37 ▶ if (length($rest) >= 3 && $rest =~ /\A0([bBoOxX])/) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $rest >= 3 and $rest =~ /\A0([bBoOxX])/) { } 13 24 37
elsif ($rest =~ /\A0/) { } 8 16 24
Condition100%3/3
length $rest >= 3 and $rest =~ /\A0([bBoOxX])/
!ll&&!rl&&r
121213
MC/DC100%2/2
length $rest >= 3 and $rest =~ /\A0([bBoOxX])/
length $rest >= 3 $rest =~ /\A0([bBoOxX])/
Truth table100%3/3
A and B
A= length $rest >= 3B= $rest =~ /\A0([bBoOxX])/
ABresult
0X0
100
111
426 13 my $marker = lc $1;
427 13 ▶ $base = $marker eq 'b' ? 2 : $marker eq 'o' ? 8 : 16;
Branch: 2 branches
BranchTrueFalseTotal
$marker eq 'b' ? : 2 11 13
$marker eq 'o' ? : 3 8 11
428 13 $rest = substr $rest, 2;
429 }
430 elsif ($rest =~ /\A0/) {
431 8 $base = 8;
432 8 $rest = substr $rest, 1;
433 }
434  
435 37 $rest =~ tr/_//d;
436  
437 # Only the bare-leading-zero branch can empty $rest, and there Go's digit
438 # loop runs zero times over a zero accumulator: "0" and "-0" are both 0.
439 37 ▶ return 0 unless length $rest;
Branch: 1 branch
BranchTrueFalseTotal
unless length $rest 2 35 37
440  
441 35 my %DIGITS = (
442 2 => qr/\A[01]+\z/,
443 8 => qr/\A[0-7]+\z/,
444 10 => qr/\A[0-9]+\z/,
445 16 => qr/\A[0-9a-fA-F]+\z/,
446 );
447 35 ▶ return undef unless $rest =~ $DIGITS{$base};
Branch: 1 branch
BranchTrueFalseTotal
unless $rest =~ /$DIGITS{$base}/ 11 24 35
448  
449 # Past a UV both of these hand back a double, which is far outside the
450 # window and so refused below -- the rounding cannot pull a too-large
451 # magnitude back inside it.
452 24 my $magnitude = do {
453 96 ▶ no warnings qw( portable overflow );
Subroutine BEGIN: called CC=1 SCAR=0.0
454 24 ▶ $base == 10 ? 0 + $rest
Branch: 3 branches
BranchTrueFalseTotal
$base == 10 ? : 9 15 24
$base == 16 ? : 8 7 15
$base == 2 ? : 2 5 7
455 : $base == 16 ? oct("0x$rest")
456 : $base == 2 ? oct("0b$rest")
457 : oct("0$rest");
458 };
459  
460 # int64 reaches one further down than up, so a negative magnitude fits
461 # exactly when magnitude-1 fits as a positive one. Asked of
462 # File::SOPS::Encrypted rather than spelled here, because two copies of
463 # that boundary is this distribution's signature defect.
464 24 ▶ return undef unless File::SOPS::Encrypted->integer_fits_int64(
Branch: 2 branches
BranchTrueFalseTotal
unless "File::SOPS::Encrypted"->integer_fits_int64($negative ? $magnitude - 1 : $magnitude) 4 20 24
$negative ? : 4 20 24
465 $negative ? $magnitude - 1 : $magnitude);
466  
467 # Built from the magnitude's own decimal spelling, so that int64's floor
468 # survives: negating a Perl UV of 2**63 produces a double, while numifying
469 # '-9223372036854775808' produces the integer.
470 20 ▶ return $negative ? 0 + ('-' . $magnitude) : $magnitude;
Branch: 1 branch
BranchTrueFalseTotal
$negative ? : 3 17 20
471 }
472  
473 # A port of Go's strconv.underscoreOK, which is where ParseInt's underscore
474 # rule lives: an underscore may appear only between digits, or between a base
475 # prefix and the first digit.
476 44 ▶sub _underscores_ok {
Subroutine _underscores_ok: called CC=11 SCAR=24.0
477 44 my ($text) = @_;
478  
479 44 my $s = $text;
480 44 $s =~ s/\A[+-]//;
481  
482 # '^' before the number, '0' after a digit or a base prefix, '_' after an
483 # underscore, '!' after anything else.
484 44 my $saw = '^';
485 44 my $i = 0;
486 44 my $hex = 0;
487  
488 44 ▶ if (length($s) >= 2 && $s =~ /\A0([bBoOxX])/) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $s >= 2 and $s =~ /\A0([bBoOxX])/) 15 29 44
Condition100%3/3
length $s >= 2 and $s =~ /\A0([bBoOxX])/
!ll&&!rl&&r
82115
MC/DC100%2/2
length $s >= 2 and $s =~ /\A0([bBoOxX])/
length $s >= 2 $s =~ /\A0([bBoOxX])/
Truth table100%3/3
A and B
A= length $s >= 2B= $s =~ /\A0([bBoOxX])/
ABresult
0X0
100
111
489 15 $i = 2;
490 15 $saw = '0';
491 15 $hex = lc($1) eq 'x';
492 }
493  
494 44 ▶ for (; $i < length $s; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $s) 231 41 272
495 231 my $c = substr $s, $i, 1;
496  
497 231 ▶ if ($c =~ /\A[0-9]\z/ || ($hex && $c =~ /\A[a-fA-F]\z/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /\A[0-9]\z/ or $hex and $c =~ /\A[a-fA-F]\z/) 206 25 231
Condition100%6/6
$c =~ /\A[0-9]\z/ or $hex and $c =~ /\A[a-fA-F]\z/
l!l&&r!l&&!r
1733325
$hex and $c =~ /\A[a-fA-F]\z/
!ll&&!rl&&r
24133
MC/DC100%3/3
$c =~ /\A[0-9]\z/ or $hex and $c =~ /\A[a-fA-F]\z/
$c =~ /\A[0-9]\z/ $hex $c =~ /\A[a-fA-F]\z/
Truth table100%4/4
A or B and C
A= $c =~ /\A[0-9]\z/B= $hexC= $c =~ /\A[a-fA-F]\z/
ABCresult
1XX1
0111
00X0
0100
498 206 $saw = '0';
499 206 next;
500 }
501  
502 25 ▶ if ($c eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "_") 8 17 25
503 8 ▶ return 0 unless $saw eq '0';
Branch: 1 branch
BranchTrueFalseTotal
unless $saw eq 0 2 6 8
504 6 $saw = '_';
505 6 next;
506 }
507  
508 17 ▶ return 0 if $saw eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if $saw eq "_" 1 16 17
509 16 $saw = '!';
510 }
511  
512 41 ▶ return $saw eq '_' ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$saw eq '_' ? : 2 39 41
513 }
514  
515 1048 ▶sub from_hash {
Subroutine from_hash: called CC=11 SCAR=24.0
Pod documented
516 1048 my ($class, $hash) = @_;
517  
518 # Returning undef here is how a document lost a key. Both format handlers
519 # call this as from_hash(delete $data->{sops}) once they have seen the key
520 # EXIST, so undef meant "there was a top-level sops entry, it was not a
521 # mapping, and it has already been removed from the tree" -- and every
522 # caller reads undef as "this document has no metadata". File::SOPS::encrypt
523 # then wrote a document without the entry, over the original if the caller
524 # had asked for that. `sops: mine` in a plaintext file was silently deleted.
525 #
526 # sops refuses such a document from both directions, and does not care what
527 # the entry holds: `sops -e` stops with exit code 203 on the same
528 # reserved-key message it gives an already-encrypted file, whether the entry
529 # is a scalar, a list, null or an empty mapping; `sops -d` and `sops rotate`
530 # stop with "Found sops entry that is not a mapping". Measured on 3.13.3.
531 #
532 # The check cannot live at the call sites' `delete`, which collapses "no
533 # entry" and "entry holding null" into the same undef, and sops refuses the
534 # second. So an undef arriving here is a caller that has already established
535 # the key exists -- there is no reason to ask this method about a section
536 # that is not there, and no caller in this distribution does.
537 1048 ▶ croak "the top-level 'sops' entry is " . _shape_of($hash) . ", not a "
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash eq "HASH" 20 1028 1048
538 . "mapping. That name is reserved for the SOPS metadata section, so a "
539 . "document using it for anything else can neither be read (there is "
540 . "no metadata to read) nor encrypted (the entry is where the metadata "
541 . "goes). If this is plaintext that happens to use the name, rename the "
542 . "entry. sops refuses the same document: 'Found sops entry that is not "
543 . "a mapping' when reading, exit code 203 when encrypting."
544 unless ref $hash eq 'HASH';
545  
546 # Before anything is built out of the section: a reference where sops
547 # wants a string. It refuses such a document at exit 1 without opening it,
548 # and here the reference would reach an encryption rule and be used as the
549 # suffix or the pattern.
550 _assert_string_field($_, $hash->{$_})
551 1028 for grep { exists $hash->{$_} } @STRING_FIELDS;
552  
553 66 my %extra = map { $_ => $hash->{$_} }
554 982 grep { !$MODELLED_FIELD{$_} } keys %$hash;
555  
556 # The one unmodelled field with a type of its own. It stays in `extra`
557 # because this class does not model what it MEANS -- only what it is.
558 $extra{shamir_threshold}
559 = _decode_int_field('shamir_threshold', $extra{shamir_threshold})
560 982 ▶ if exists $extra{shamir_threshold};
Branch: 1 branch
BranchTrueFalseTotal
if exists $extra{"shamir_threshold"} 53 929 982
561  
562 return $class->new(
563 extra => \%extra,
564 age => $hash->{age} // [],
565 pgp => $hash->{pgp} // [],
566 kms => $hash->{kms} // [],
567 gcp_kms => $hash->{gcp_kms} // [],
568 azure_kv => $hash->{azure_kv} // [],
569 hc_vault => $hash->{hc_vault} // [],
570 mac => $hash->{mac},
571 lastmodified => _decode_lastmodified($hash->{lastmodified}),
572 version => $hash->{version} // $SOPS_VERSION,
573 unencrypted_suffix => $hash->{unencrypted_suffix},
574 encrypted_suffix => $hash->{encrypted_suffix},
575 unencrypted_regex => $hash->{unencrypted_regex},
576 encrypted_regex => $hash->{encrypted_regex},
577 mac_only_encrypted =>
578 958 ▶ _decode_bool_field('mac_only_encrypted', $hash->{mac_only_encrypted}),
Condition93%14/15
$hash->{"age"} // []
l!l
834124
$hash->{"pgp"} // []
l!l
602356
$hash->{"kms"} // []
l!l
602356
$hash->{"gcp_kms"} // []
l!l
602356
$hash->{"azure_kv"} // []
l!l
602356
$hash->{"hc_vault"} // []
l!l
602356
$hash->{"version"} // $File::SOPS::Metadata::SOPS_VERSION
l!l&&r!l&&!r
910480
MC/DC100%1/1
$hash->{"age"} // []
$hash->{"age"}
MC/DC100%1/1
$hash->{"pgp"} // []
$hash->{"pgp"}
MC/DC100%1/1
$hash->{"kms"} // []
$hash->{"kms"}
MC/DC100%1/1
$hash->{"gcp_kms"} // []
$hash->{"gcp_kms"}
MC/DC100%1/1
$hash->{"azure_kv"} // []
$hash->{"azure_kv"}
MC/DC100%1/1
$hash->{"hc_vault"} // []
$hash->{"hc_vault"}
MC/DC0%0/2
$hash->{"version"} // $File::SOPS::Metadata::SOPS_VERSION
$hash->{"version"} $File::SOPS::Metadata::SOPS_VERSION
Truth table100%2/2
A
A= $hash->{"age"}
Aresult
11
00
Truth table100%2/2
A
A= $hash->{"pgp"}
Aresult
11
00
Truth table100%2/2
A
A= $hash->{"kms"}
Aresult
11
00
Truth table100%2/2
A
A= $hash->{"gcp_kms"}
Aresult
11
00
Truth table100%2/2
A
A= $hash->{"azure_kv"}
Aresult
11
00
Truth table100%2/2
A
A= $hash->{"hc_vault"}
Aresult
11
00
Truth table66%2/3
A // B
A= $hash->{"version"}B= $File::SOPS::Metadata::SOPS_VERSION
ABresult
1X1
011
000
579 );
580 }
581  
582  
583 662 ▶sub to_hash {
Subroutine to_hash: called CC=9 SCAR=22.0
Pod documented
584 662 my ($self) = @_;
585  
586 # Unmodelled fields go down first so that a modelled one always wins: the
587 # attributes are the truth about this document, extra is only what nobody
588 # here has an opinion about.
589 my $hash = {
590 662 %{ $self->extra },
591 kms => $self->kms,
592 gcp_kms => $self->gcp_kms,
593 azure_kv => $self->azure_kv,
594 hc_vault => $self->hc_vault,
595 age => $self->age,
596 pgp => $self->pgp,
597 };
598  
599 662 ▶ $hash->{lastmodified} = $self->lastmodified if defined $self->lastmodified;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->lastmodified 654 8 662
600 662 ▶ $hash->{mac} = $self->mac if defined $self->mac;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->mac 646 16 662
601 662 ▶ $hash->{version} = $self->version if defined $self->version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->version 662 0 662
602  
603 662 ▶ $hash->{unencrypted_suffix} = $self->unencrypted_suffix
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->unencrypted_suffix 633 29 662
604 if defined $self->unencrypted_suffix;
605 662 ▶ $hash->{encrypted_suffix} = $self->encrypted_suffix
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->encrypted_suffix 11 651 662
606 if defined $self->encrypted_suffix;
607 662 ▶ $hash->{unencrypted_regex} = $self->unencrypted_regex
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->unencrypted_regex 7 655 662
608 if defined $self->unencrypted_regex;
609 662 ▶ $hash->{encrypted_regex} = $self->encrypted_regex
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->encrypted_regex 5 657 662
610 if defined $self->encrypted_regex;
611 # sops omits the key entirely when the option is off, so a false must not
612 # be written back as `mac_only_encrypted: false`.
613 662 ▶ $hash->{mac_only_encrypted} = JSON->true if $self->mac_only_encrypted;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mac_only_encrypted 45 617 662
614  
615 662 return $hash;
616 }
617  
618  
619 682 ▶sub update_lastmodified {
Subroutine update_lastmodified: called CC=1 SCAR=0.0
Pod documented
620 682 my ($self) = @_;
621 682 $self->lastmodified(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime));
622 682 return $self;
623 }
624  
625  
626 1 ▶sub add_age_recipient {
Subroutine add_age_recipient: called CC=3 SCAR=11.2
Pod documented
627 1 my ($self, %args) = @_;
628 1 ▶ my $recipient = $args{recipient} // croak "recipient required";
Condition50%1/2
$args{"recipient"} // croak("recipient required")
l!l
10
MC/DC0%0/1
$args{"recipient"} // croak("recipient required")
$args{"recipient"}
Truth table50%1/2
A
A= $args{"recipient"}
Aresult
11
00
629 1 ▶ my $enc = $args{enc} // croak "enc required";
Condition50%1/2
$args{"enc"} // croak("enc required")
l!l
10
MC/DC0%0/1
$args{"enc"} // croak("enc required")
$args{"enc"}
Truth table50%1/2
A
A= $args{"enc"}
Aresult
11
00
630  
631 1 push @{$self->age}, {
632 recipient => $recipient,
633 enc => $enc,
634 };
635  
636 1 return $self;
637 }
638  
639  
640 9 ▶sub get_age_encrypted_keys {
Subroutine get_age_encrypted_keys: called CC=1 SCAR=0.0
Pod documented
641 9 my ($self) = @_;
642 9 return @{$self->age};
643 }
644  
645  
646 ###############################################################################
647 # The two regex rules, and the dialect they are matched in
648 ###############################################################################
649  
650 # unencrypted_regex and encrypted_regex are matched HERE with Perl and in sops
651 # with Go's RE2, and those are not the same dialect. Two consequences, both
652 # measured against sops 3.13.3 -- docs/adr/0048, k161.
653 #
654 # 1. RE2's \w \W \d \D \s \S \b \B and its POSIX classes are ASCII-only for
655 # every subject. Perl's are Unicode-aware for any string carrying the UTF-8
656 # flag -- which is every non-ASCII key our parsers produce. So an
657 # `unencrypted_regex: ^\w+$` is a rule under which sops ENCRYPTS `café`,
658 # `密`, `n٣` and `a<NBSP>b` and this library left them BARE. That is why the
659 # patterns are compiled /a below: it is RE2's answer for these classes, and
660 # it makes the answer independent of a flag ADR 0003 forbids reading
661 # anywhere else in this distribution.
662 #
663 # 2. A pattern RE2 cannot COMPILE is not reported by sops. It matches with the
664 # error discarded, so the rule silently matches NOTHING: measured,
665 # `--encrypted-regex '(?=f)foo'` writes every value of the document in
666 # PLAINTEXT at exit 0, and `--unencrypted-regex '(?=f)foo'` encrypts every
667 # value. Neither is a classification that can be reproduced quietly, so the
668 # constructs RE2 rejects are refused here instead.
669  
670 # The escapes RE2 accepts, meaning by them what Perl means once the pattern is
671 # compiled /a. Every OTHER alphanumeric escape is refused, because RE2 either
672 # rejects it -- \Z \K \G \R \h \H \V \N \X \C \c \e \o \g \k \u \l \U \L are
673 # all "invalid escape sequence", measured through a .sops.yaml path_regex,
674 # which is the one place sops reports a compile error -- or reads it as
675 # something else:
676 #
677 # \v the vertical TAB to Go, the vertical-whitespace CLASS to Perl.
678 # \Q a quoted literal run to RE2, and NOTHING to Perl: \Q and \E are
679 # double-quotish escapes, processed when a pattern is written out in
680 # source and not by the regex compiler, so a pattern arriving in a
681 # variable -- which is every pattern here -- keeps them as the literal
682 # letters Q and E. Measured: `\Qa.b\E` selects the key `a.b` at sops
683 # and the key `Qa.bE` here.
684 #
685 # \0 covers the octal escapes (\0, \00, \017); a leading 1..9 is a
686 # backreference here and an error there.
687 96 my %RE2_ESCAPE = map { $_ => 1 } qw(
688 A B D P S W
689 a b d f n p r s t w x z
690 0
691 );
692  
693 # The regex flags RE2 has, plus the `-` that turns one off. Perl's a, d, l, u,
694 # n, p and x are all "invalid or unsupported Perl syntax" there; U is the
695 # reverse case -- RE2 has it and Perl does not -- and fails to compile here,
696 # which is _rule_qr's other croak.
697 96 my %RE2_FLAG = map { $_ => 1 } qw( i m s U - );
698  
699 # The escapes both dialects accept and do not mean the same thing by. These
700 # are the ones a whitelist cannot catch: nothing fails, the rule just selects
701 # different keys on the two sides.
702 96 my %RE2_MEANS_OTHER = (
703 v => 'the vertical TAB to Go RE2 and the vertical-whitespace CLASS to '
704 . 'Perl',
705 Q => 'a quoted literal run to Go RE2 and nothing at all to Perl',
706 E => 'the end of a quoted literal run to Go RE2 and nothing at all to '
707 . 'Perl',
708 );
709  
710 # What in this pattern, if any, the two dialects do not agree on. Returns the
711 # empty list when they do, and otherwise the construct and which KIND of
712 # disagreement it is:
713 #
714 # 'unsupported' -- RE2 cannot compile it, so the rule matches nothing there
715 # 'different' -- both compile it and read it as different things
716 #
717 # The check is deliberately whitelist-shaped for escapes and for (?...) groups:
718 # a construct nobody here has measured is refused rather than assumed
719 # harmless, because the harm runs one way (a key sops encrypts, left bare).
720 282 ▶sub _re2_divergent_construct {
Subroutine _re2_divergent_construct: called CC=35 SCAR=35.6
721 282 my ($pattern) = @_;
722 282 ▶ return () unless defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 282 282
723  
724 282 my @c = split //, $pattern;
725 282 my $i = 0;
726 282 my $in_class = 0;
727 282 my $class_pos = 0; # how far into the current [...] we are; a ] at 0 is
728 # the literal character, in both dialects
729 282 my $quantified = 0; # the token just read was a quantifier
730  
731 282 ▶ while ($i < @c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @c) 1446 190 1636
732 1446 my $ch = $c[$i];
733  
734 1446 ▶ if ($ch eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\\") 95 1351 1446
735 95 my $next = $c[$i+1];
736 95 ▶ return ('a trailing backslash', 'unsupported') unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 95 95
737  
738 95 ▶ if ($next =~ /\A[0-9A-Za-z]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next =~ /\A[0-9A-Za-z]\z/) 78 17 95
739 78 ▶ return ('a backreference (\\1, \\2, ...)', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $next =~ /\A[1-9]\z/ 4 74 78
740 if $next =~ /\A[1-9]\z/;
741 return ("the escape \\$next, which is $RE2_MEANS_OTHER{$next}",
742 'different')
743 74 ▶ if $RE2_MEANS_OTHER{$next};
Branch: 1 branch
BranchTrueFalseTotal
if $RE2_MEANS_OTHER{$next} 10 64 74
744 return ("the escape \\$next", 'unsupported')
745 64 ▶ unless $RE2_ESCAPE{$next};
Branch: 1 branch
BranchTrueFalseTotal
unless $RE2_ESCAPE{$next} 21 43 64
746  
747 # Outside a character class \b is the word boundary both
748 # dialects have; inside one it is BACKSPACE, which RE2 rejects.
749 43 ▶ return ('the escape \\b inside a character class', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $next eq "b" and $in_class 2 41 43
Condition100%3/3
$next eq "b" and $in_class
!ll&&!rl&&r
4012
MC/DC100%2/2
$next eq "b" and $in_class
$next eq "b" $in_class
Truth table100%3/3
A and B
A= $next eq "b"B= $in_class
ABresult
0X0
100
111
750 if $next eq 'b' && $in_class;
751 }
752  
753 58 $i += 2;
754 58 ▶ $class_pos++ if $in_class;
Branch: 1 branch
BranchTrueFalseTotal
if $in_class 2 56 58
755 58 $quantified = 0;
756 58 next;
757 }
758  
759 1351 ▶ if ($in_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_class) 55 1296 1351
760 55 ▶ if ($ch eq ']' && $class_pos > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "]" and $class_pos > 0) 25 30 55
Condition100%3/3
$ch eq "]" and $class_pos > 0
!ll&&!rl&&r
28225
MC/DC100%2/2
$ch eq "]" and $class_pos > 0
$ch eq "]" $class_pos > 0
Truth table100%3/3
A and B
A= $ch eq "]"B= $class_pos > 0
ABresult
0X0
100
111
761 25 $in_class = 0;
762 25 $quantified = 0;
763 25 $i++;
764 25 next;
765 }
766  
767 # [:alpha:] and [:^alpha:] carry a ] of their own.
768 30 ▶ if ($ch eq '[' && defined $c[$i+1] && $c[$i+1] eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "[" and defined $c[$i + 1] and $c[$i + 1] eq ":") 17 13 30
Condition66%4/6
$ch eq "[" and defined $c[$i + 1] and $c[$i + 1] eq ":"
!ll&&!rl&&r
13017
$ch eq "[" and defined $c[$i + 1]
!ll&&!rl&&r
13017
MC/DC33%1/3
$ch eq "[" and defined $c[$i + 1] and $c[$i + 1] eq ":"
$ch eq "[" defined $c[$i + 1] $c[$i + 1] eq ":"
Truth table50%2/4
A and B and C
A= $ch eq "["B= defined $c[$i + 1]C= $c[$i + 1] eq ":"
ABCresult
0XX0
10X0
1100
1111
769 17 my $end = index($pattern, ':]', $i + 2);
770 17 ▶ if ($end >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end >= 0) 17 0 17
771 17 $class_pos += $end + 2 - $i;
772 17 $i = $end + 2;
773 17 next;
774 }
775 }
776  
777 13 $class_pos++;
778 13 $i++;
779 13 next;
780 }
781  
782 1296 ▶ if ($ch eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "[") 28 1268 1296
783 28 $in_class = 1;
784 28 $class_pos = 0;
785 28 $quantified = 0;
786 28 $i++;
787 28 ▶ $i++ if defined $c[$i] && $c[$i] eq '^'; # [^...] is still at 0
Branch: 1 branch
BranchTrueFalseTotal
if defined $c[$i] and $c[$i] eq "^" 2 26 28
Condition100%3/3
defined $c[$i] and $c[$i] eq "^"
!ll&&!rl&&r
1252
MC/DC100%2/2
defined $c[$i] and $c[$i] eq "^"
defined $c[$i] $c[$i] eq "^"
Truth table100%3/3
A and B
A= defined $c[$i]B= $c[$i] eq "^"
ABresult
0X0
100
111
788 28 next;
789 }
790  
791 1268 ▶ if ($ch eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "(") 84 1184 1268
792 84 $quantified = 0;
793 84 ▶ if (defined $c[$i+1] && $c[$i+1] eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c[$i + 1] and $c[$i + 1] eq "?") 69 15 84
Condition100%3/3
defined $c[$i + 1] and $c[$i + 1] eq "?"
!ll&&!rl&&r
21369
MC/DC100%2/2
defined $c[$i + 1] and $c[$i + 1] eq "?"
defined $c[$i + 1] $c[$i + 1] eq "?"
Truth table100%3/3
A and B
A= defined $c[$i + 1]B= $c[$i + 1] eq "?"
ABresult
0X0
100
111
794 69 my @divergent = _re2_divergent_group(substr($pattern, $i));
795 69 ▶ return @divergent if @divergent;
Branch: 1 branch
BranchTrueFalseTotal
if @divergent 49 20 69
796 }
797 35 $i++;
798 35 next;
799 }
800  
801 1184 ▶ if ($ch eq '*' || $ch eq '+' || $ch eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "*" or $ch eq "+" or $ch eq "?") 75 1109 1184
Condition100%6/6
$ch eq "*" or $ch eq "+" or $ch eq "?"
l!l&&r!l&&!r
53221109
$ch eq "*" or $ch eq "+"
l!l&&r!l&&!r
6471131
MC/DC100%3/3
$ch eq "*" or $ch eq "+" or $ch eq "?"
$ch eq "*" $ch eq "+" $ch eq "?"
Truth table100%4/4
A or B or C
A= $ch eq "*"B= $ch eq "+"C= $ch eq "?"
ABCresult
1XX1
01X1
0011
0000
802 75 ▶ return ('a possessive quantifier (*+, ++, ?+ or {n,m}+)',
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "+" and $quantified 6 69 75
Condition100%3/3
$ch eq "+" and $quantified
!ll&&!rl&&r
28416
MC/DC100%2/2
$ch eq "+" and $quantified
$ch eq "+" $quantified
Truth table100%3/3
A and B
A= $ch eq "+"B= $quantified
ABresult
0X0
100
111
803 'unsupported')
804 if $ch eq '+' && $quantified;
805 # A ? after a quantifier is the lazy form, which both dialects
806 # have, and it ends the quantifier rather than extending it.
807 69 ▶ $quantified = ($ch eq '?' && $quantified) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$ch eq '?' && $quantified ? : 2 67 69
Condition100%3/3
$ch eq "?" and $quantified
!ll&&!rl&&r
47202
MC/DC100%2/2
$ch eq "?" and $quantified
$ch eq "?" $quantified
Truth table100%3/3
A and B
A= $ch eq "?"B= $quantified
ABresult
0X0
100
111
808 69 $i++;
809 69 next;
810 }
811  
812 1109 ▶ if ($ch eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "{") 11 1098 1109
813 # A brace run that is a repetition; anything else is a literal
814 # brace in both dialects.
815 11 ▶ if (substr($pattern, $i) =~ /\A(\{[0-9]+(?:,[0-9]*)?\})/) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($pattern, $i) =~ /\A(\{[0-9]+(?:,[0-9]*)?\})/) 4 7 11
816 4 $i += length $1;
817 4 $quantified = 1;
818 4 next;
819 }
820 7 $quantified = 0;
821 7 $i++;
822 7 next;
823 }
824  
825 1098 $quantified = 0;
826 1098 $i++;
827 }
828  
829 190 return ();
830 }
831  
832 # What follows a `(?`, given the rest of the pattern from the `(`.
833 69 ▶sub _re2_divergent_group {
Subroutine _re2_divergent_group: called CC=16 SCAR=27.8
834 69 my ($rest) = @_;
835  
836 69 ▶ return () if $rest =~ /\A\(\?:/; # (?:...) non-capturing
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?:/ 1 68 69
837 68 ▶ return () if $rest =~ /\A\(\?P</; # (?P<n>..) named
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?P</ 2 66 68
838 66 ▶ return ('a lookbehind ((?<=...) or (?<!...))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?<[=!]/ 6 60 66
839 if $rest =~ /\A\(\?<[=!]/;
840 60 ▶ return () if $rest =~ /\A\(\?</; # (?<n>...) named, Go 1.22+
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?</ 1 59 60
841 59 ▶ return ('a lookahead ((?=...) or (?!...))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?[=!]/ 18 41 59
842 if $rest =~ /\A\(\?[=!]/;
843 41 ▶ return ('an atomic group ((?>...))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?>/ 3 38 41
844 if $rest =~ /\A\(\?>/;
845 38 ▶ return ('an inline comment ((?#...))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?#/ 3 35 38
846 if $rest =~ /\A\(\?#/;
847 35 ▶ return ('a branch reset ((?|...))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?\|/ 3 32 35
848 if $rest =~ /\A\(\?\|/;
849 32 ▶ return ('embedded code ((?{...}))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?\??\{/ 0 32 32
850 if $rest =~ /\A\(\?\??\{/;
851 32 ▶ return ('a backreference ((?P=name))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?P=/ 3 29 32
852 if $rest =~ /\A\(\?P=/;
853 29 ▶ return ('a subpattern call or recursion', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?(?:R\)|[0-9]|[&+]|-[0-9]|P>)/ 3 26 29
854 if $rest =~ /\A\(\?(?:R\)|[0-9]|[&+]|-[0-9]|P>)/;
855 26 ▶ return ("a named group in Perl's (?'name'...) spelling", 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?'/ 2 24 26
856 if $rest =~ /\A\(\?'/;
857 24 ▶ return ('a flag reset ((?^...))', 'unsupported')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A\(\?\^/ 2 22 24
858 if $rest =~ /\A\(\?\^/;
859  
860 22 ▶ if ($rest =~ /\A\(\?([a-zA-Z-]*)[:)]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A\(\?([a-zA-Z-]*)[:)]/) 22 0 22
861 22 my ($bad) = grep { !$RE2_FLAG{$_} } split //, $1;
862 22 ▶ return defined $bad ? ("the regex flag (?$bad)", 'unsupported') : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $bad ? : 6 16 22
863 }
864  
865 0 return ('a (?...) group RE2 does not have', 'unsupported');
866 }
867  
868 {
869 # Everything in this block is compiled with ASCII-only character classes,
870 # which is what RE2 gives the pattern on the other side. It is deliberately
871 # /a and not /aa: measured, Go folds `k` to U+212A KELVIN SIGN and `s` to
872 # U+017F LONG S under (?i), which /a keeps and /aa would break. What /a
873 # does not reach is Perl's FULL case folding -- `(?i)^ss$` matches U+00DF
874 # here and not there -- which is recorded as a limit in docs/adr/0048.
875 96 ▶ use re '/a';
Subroutine BEGIN: called CC=1 SCAR=0.0
876  
877 # sops's own answer for a pattern RE2 cannot compile: it discards the
878 # compile error, so the rule matches NOTHING. Compiled once, in here with
879 # the real patterns, because that is the answer the read path uses.
880 96 my $MATCHES_NOTHING = qr/(?!)/;
881  
882 # The one place a rule pattern is looked at. Returns the matcher to use,
883 # the KIND of disagreement if there is one, and the refusal that goes with
884 # it -- because the two paths need different halves of that answer:
885 #
886 # 'unsupported' RE2 cannot compile it, so sops matches nothing. That is
887 # reproducible, and $MATCHES_NOTHING reproduces it, so the
888 # READ path is given a matcher and no refusal is raised.
889 # 'different' both dialects compile it and read it apart (\v, \Q, \E).
890 # 'perl' RE2 compiles it and we cannot ((?U) is the only measured
891 # one; \C, \g and \k are rejected by BOTH).
892 #
893 # The last two have no answer to reproduce, so they are refused wherever
894 # they are met. The write path refuses all three. See docs/adr/0051.
895 241 ▶ sub _rule_verdict {
Subroutine _rule_verdict: called CC=6 SCAR=17.9
896 241 my ($field, $pattern) = @_;
897  
898 241 ▶ my $shown = length($pattern) > 60
Branch: 1 branch
BranchTrueFalseTotal
length $pattern > 60 ? : 0 241 241
899 ? substr($pattern, 0, 57) . '...'
900 : $pattern;
901  
902 241 my ($construct, $kind) = _re2_divergent_construct($pattern);
903 return (
904 241 ▶ $kind eq 'unsupported' ? $MATCHES_NOTHING : undef,
Branch: 3 branches
BranchTrueFalseTotal
if defined $construct 71 170 241
$kind eq 'unsupported' ? : 64 7 71
$kind eq 'unsupported' ? : 64 7 71
905 $kind,
906 "Cannot use '$shown' as the $field: it uses $construct, "
907 . ($kind eq 'unsupported'
908 ? "which Go RE2 does not support. sops does not report that "
909 . "-- it discards the compile error, so the rule silently "
910 . "matches NOTHING. Measured on sops 3.13.3: an "
911 . "encrypted_regex it cannot compile leaves every value of "
912 . "the document in PLAINTEXT at exit 0, and an "
913 . "unencrypted_regex it cannot compile encrypts every value."
914 : "which both dialects accept and read DIFFERENTLY, so the "
915 . "same rule selects different keys in the two "
916 . "implementations.")
917 . " Rewrite the pattern in constructs both dialects agree on. "
918 . "See docs/adr/0048."
919 ) if defined $construct;
920  
921 170 my $qr = eval { qr/$pattern/ };
922 170 ▶ return ($qr, undef, undef) if defined $qr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $qr 164 6 170
923  
924 6 return (undef, 'perl',
925 "Cannot use '$shown' as the $field: it is not a valid Perl "
926 . "regular expression (" . _regex_reason($@) . "). RE2 and Perl "
927 . "do not accept the same patterns in either direction -- '(?U)' "
928 . "compiles there and not here -- so a rule sops took can still "
929 . "be one this side cannot match with. See docs/adr/0048.");
930 }
931  
932 154 ▶ sub _rule_qr {
Subroutine _rule_qr: called CC=2 SCAR=6.9
933 154 my ($field, $pattern) = @_;
934  
935 154 my ($qr, undef, $refusal) = _rule_verdict($field, $pattern);
936  
937 # A pattern RE2 cannot compile arrives here WITH a matcher -- the one
938 # that matches nothing, which is what sops matches with. Every other
939 # refusal is one this side cannot reproduce, and it stands wherever
940 # the rule is asked, read path included. docs/adr/0051.
941 154 ▶ croak $refusal unless defined $qr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $qr 12 142 154
942  
943 142 return $qr;
944 }
945 }
946  
947 96 ▶sub _regex_reason {
Subroutine _regex_reason: called CC=3 SCAR=11.2
948 6 my ($error) = @_;
949 6 ▶ my $reason = defined $error ? "$error" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 6 0 6
950 6 $reason =~ s/\s+at\s+\S+\s+line\s+\d+\.?\s*\z//;
951 6 $reason =~ s/\s+/ /g;
952 6 $reason =~ s/\A\s+|\s+\z//g;
953 6 ▶ return length $reason ? $reason : 'no reason given';
Branch: 1 branch
BranchTrueFalseTotal
length $reason ? : 6 0 6
954 }
955  
956 # Private, and it lives here rather than with the modelled fields because it
957 # is not one: nothing constructs it, to_hash never sees it, and its only
958 # reader is the method below.
959 has _rule_matchers => (
960 is => 'ro',
961 init_arg => undef,
962 1837 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
963 96 );
964  
965 # One compiled matcher per rule pattern. Keyed by the pattern itself, so a
966 # caller changing the attribute -- both are rw -- gets a matcher for what the
967 # attribute now holds rather than for what it held first.
968 675 ▶sub _rule_matcher {
Subroutine _rule_matcher: called CC=2 SCAR=6.9
969 675 my ($self, $field) = @_;
970  
971 675 my $pattern = $self->$field;
972 675 ▶ return $self->_rule_matchers->{$field}{$pattern}
Condition100%3/3
$self->_rule_matchers->{$field}{$pattern} ||= _rule_qr($field, $pattern)
l!l&&r!l&&!r
5211477
MC/DC100%2/2
$self->_rule_matchers->{$field}{$pattern} ||= _rule_qr($field, $pattern)
$self->_rule_matchers->{$field}{$pattern} _rule_qr($field, $pattern)
Truth table100%3/3
A ||= B
A= $self->_rule_matchers->{$field}{$pattern}B= _rule_qr($field, $pattern)
ABresult
1X1
011
000
973 ||= _rule_qr($field, $pattern);
974 }
975  
976 6 ▶sub should_encrypt_key {
Subroutine should_encrypt_key: called CC=9 SCAR=24.6
Pod documented
977 6 my ($self, $key) = @_;
978  
979 6 ▶ if (defined $self->unencrypted_suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->unencrypted_suffix) 4 2 6
980 4 ▶ return 0 if $key =~ /\Q$self->{unencrypted_suffix}\E$/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /\Q$self->{"unencrypted_suffix"}\E$/ 2 2 4
981 }
982  
983 4 ▶ if (defined $self->encrypted_suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->encrypted_suffix) 2 2 4
984 2 ▶ return 1 if $key =~ /\Q$self->{encrypted_suffix}\E$/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /\Q$self->{"encrypted_suffix"}\E$/ 1 1 2
985 1 return 0;
986 }
987  
988 2 ▶ if (defined $self->unencrypted_regex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->unencrypted_regex) 0 2 2
989 0 ▶ return 0 if $key =~ $self->_rule_matcher('unencrypted_regex');
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ $self->_rule_matcher("unencrypted_regex") 0 0 0
990 }
991  
992 2 ▶ if (defined $self->encrypted_regex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->encrypted_regex) 0 2 2
993 0 ▶ return 1 if $key =~ $self->_rule_matcher('encrypted_regex');
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ $self->_rule_matcher("encrypted_regex") 0 0 0
994 0 return 0;
995 }
996  
997 2 return 1;
998 }
999  
1000  
1001 32390 ▶sub should_encrypt_path {
Subroutine should_encrypt_path: called CC=16 SCAR=27.8
Pod documented
1002 32390 my ($self, $path) = @_;
1003 32390 ▶ $path //= [];
Condition50%1/2
$path //= []
l!l
323900
MC/DC0%0/1
$path //= []
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
1004  
1005 32390 my $encrypted = 1;
1006  
1007 # Each rule attribute is read once. unencrypted_suffix is lazy, so it must
1008 # go through its accessor to fire the builder; the other three are plain rw
1009 # fields whose accessor is just a hash read, so reading them directly --
1010 # the same way should_encrypt_key and the grep below already read these
1011 # fields -- drops three sub calls from the common single-rule path without
1012 # changing what is read. The two suffix rules match through a qr cached by
1013 # value in _rule_matchers -- the same store, keying and rw-invalidation
1014 # _rule_matcher uses for the regex rules, so a changed attribute gets a
1015 # fresh matcher -- rather than recompiling qr/\Q$suffix\E$/ on every call;
1016 # the suffix and regex field names are disjoint, so they share the store
1017 # without colliding. Order and later-overrides-earlier are unchanged.
1018 32390 my $us = $self->unencrypted_suffix;
1019 32390 ▶ if (defined $us && length $us) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $us and length $us) 31492 898 32390
Condition66%2/3
defined $us and length $us
!ll&&!rl&&r
898031492
MC/DC50%1/2
defined $us and length $us
defined $us length $us
Truth table66%2/3
A and B
A= defined $usB= length $us
ABresult
0X0
100
111
1020 31492 ▶ my $qr = $self->{_rule_matchers}{unencrypted_suffix}{$us}
Condition100%2/2
$self->{"_rule_matchers"}{"unencrypted_suffix"}{$us} ||= qr/\Q$us\E$/
l!l
303741118
MC/DC100%1/1
$self->{"_rule_matchers"}{"unencrypted_suffix"}{$us} ||= qr/\Q$us\E$/
$self->{"_rule_matchers"}{"unencrypted_suffix"}{$us}
Truth table100%2/2
A
A= $self->{"_rule_matchers"}{"unencrypted_suffix"}{$us}
Aresult
11
00
1021 ||= qr/\Q$us\E$/;
1022 31492 ▶ $encrypted = 0 if grep { $_ =~ $qr } @$path;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /$qr/;} @$path 1451 30041 31492
1023 }
1024  
1025 32390 my $es = $self->{encrypted_suffix};
1026 32390 ▶ if (defined $es && length $es) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $es and length $es) 205 32185 32390
Condition66%2/3
defined $es and length $es
!ll&&!rl&&r
321850205
MC/DC50%1/2
defined $es and length $es
defined $es length $es
Truth table66%2/3
A and B
A= defined $esB= length $es
ABresult
0X0
100
111
1027 205 ▶ my $qr = $self->{_rule_matchers}{encrypted_suffix}{$es}
Condition100%2/2
$self->{"_rule_matchers"}{"encrypted_suffix"}{$es} ||= qr/\Q$es\E$/
l!l
18025
MC/DC100%1/1
$self->{"_rule_matchers"}{"encrypted_suffix"}{$es} ||= qr/\Q$es\E$/
$self->{"_rule_matchers"}{"encrypted_suffix"}{$es}
Truth table100%2/2
A
A= $self->{"_rule_matchers"}{"encrypted_suffix"}{$es}
Aresult
11
00
1028 ||= qr/\Q$es\E$/;
1029 205 ▶ $encrypted = (grep { $_ =~ $qr } @$path) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ =~ /$qr/;} @$path) ? : 103 102 205
1030 }
1031  
1032 32390 my $ur = $self->{unencrypted_regex};
1033 32390 ▶ if (defined $ur && length $ur) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ur and length $ur) 496 31894 32390
Condition66%2/3
defined $ur and length $ur
!ll&&!rl&&r
318940496
MC/DC50%1/2
defined $ur and length $ur
defined $ur length $ur
Truth table66%2/3
A and B
A= defined $urB= length $ur
ABresult
0X0
100
111
1034 496 my $qr = $self->_rule_matcher('unencrypted_regex');
1035 484 ▶ $encrypted = 0 if grep { $_ =~ $qr } @$path;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /$qr/;} @$path 366 118 484
1036 }
1037  
1038 32378 my $er = $self->{encrypted_regex};
1039 32378 ▶ if (defined $er && length $er) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $er and length $er) 176 32202 32378
Condition66%2/3
defined $er and length $er
!ll&&!rl&&r
322020176
MC/DC50%1/2
defined $er and length $er
defined $er length $er
Truth table66%2/3
A and B
A= defined $erB= length $er
ABresult
0X0
100
111
1040 176 my $qr = $self->_rule_matcher('encrypted_regex');
1041 176 ▶ $encrypted = (grep { $_ =~ $qr } @$path) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ =~ /$qr/;} @$path) ? : 68 108 176
1042 }
1043  
1044 32378 return $encrypted;
1045 }
1046  
1047  
1048 803 ▶sub assert_rule_regexes_agree {
Subroutine assert_rule_regexes_agree: called CC=5 SCAR=16.1
Pod documented
1049 803 my ($self) = @_;
1050  
1051 803 for my $field (qw( unencrypted_regex encrypted_regex )) {
1052 1573 my $pattern = $self->$field;
1053 1573 ▶ next unless defined $pattern && length $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern and length $pattern 1486 87 1573
Condition66%2/3
defined $pattern and length $pattern
!ll&&!rl&&r
1486087
MC/DC50%1/2
defined $pattern and length $pattern
defined $pattern length $pattern
Truth table66%2/3
A and B
A= defined $patternB= length $pattern
ABresult
0X0
100
111
1054  
1055 87 my (undef, undef, $refusal) = _rule_verdict($field, $pattern);
1056 87 ▶ croak $refusal if defined $refusal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $refusal 61 26 87
1057 }
1058  
1059 742 return 1;
1060 }
1061  
1062  
1063  
1064 96 1;
1065  
1066 __END__
↑ Summary blib/lib/File/SOPS.pm »