PWSafe3/HeaderField.pm

filter: Statementstmt 31.0% 23 / 74 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 41.6% 5 / 12 Podpod 0.0% 0 / 2 totaltotal 22.0% 28 / 127 CC 19 SCAR 46.1
CC
19
Cov
21%
new
210.0
__ANON__
5.6
__ANON__
5.6
CRAP 100.1
↑ Summary PWSafe3/Field.pm »
1 #
2 # Copyright (c) 2011-2015 T.v.Dein <tlinden |AT| cpan.org>.
3 #
4 # Licensed under the terms of the Artistic License 2.0
5 # see: http://www.perlfoundation.org/artistic_license_2_0
6 #
7 #
8 package Crypt::PWSafe3::HeaderField;
9  
10 1 ▶use Carp::Heavy;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use vars qw(@ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 $Crypt::PWSafe3::HeaderField::VERSION = '1.05';
17  
18 1 %Crypt::PWSafe3::HeaderField::map2name = (
19 0x00 => "version",
20 0x01 => "uuid",
21 0x02 => "preferences",
22 0x03 => "treedisplaystatus",
23 0x04 => "lastsavetime",
24 0x05 => "wholastsaved",
25 0x06 => "whatlastsaved",
26 0x07 => "savedbyuser",
27 0x08 => "savedonhost",
28 0x09 => "databasename",
29 0x0a => "databasedescr",
30 0x0b => "databasefilters",
31 0xff => "eof"
32 );
33  
34 1 %Crypt::PWSafe3::HeaderField::map2type = map { $Crypt::PWSafe3::HeaderField::map2name{$_} => $_ } keys %Crypt::PWSafe3::HeaderField::map2name;
35  
36 1 my @fields = qw(raw len value type name);
37 1 foreach my $field (@fields) {
38 0 ▶ eval qq(
Subroutine __ANON__: not called CC=2 SCAR=17.3
Subroutine __ANON__: not called CC=2 SCAR=17.3
Subroutine __ANON__: not called CC=2 SCAR=17.3
Subroutine __ANON__: not called CC=2 SCAR=17.3
Subroutine __ANON__: not called CC=2 SCAR=17.3
Branch: 5 branches
BranchTrueFalseTotal
if ($arg) { } 0 0 0
if ($arg) { } 0 0 0
if ($arg) { } 0 0 0
if ($arg) { } 0 0 0
if ($arg) { } 0 0 0
39 *Crypt::PWSafe3::HeaderField::$field = sub {
40 my(\$this, \$arg) = \@_;
41 if (\$arg) {
42 return \$this->{$field} = \$arg;
43 }
44 else {
45 return \$this->{$field};
46 }
47 }
48 );
49 }
50  
51 0 ▶sub new {
Subroutine new: not called CC=14 SCAR=53.5
Pod undocumented
52 #
53 # new header field object
54 0 my($this, %param) = @_;
55 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
56 0 my $self = \%param;
57 0 bless($self, $class);
58  
59 0 ▶ if (! exists $param{type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $param{"type"}) 0 0 0
60 0 ▶ if (exists $param{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{'name'}) { } 0 0 0
61 0 ▶ if (exists $Crypt::PWSafe3::HeaderField::map2type{$param{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map2type{$param{'name'}}) { } 0 0 0
62 0 $param{type} = $Crypt::PWSafe3::HeaderField::map2type{$param{name}};
63 }
64 else {
65 0 croak "Unknown header type $param{name}";
66 }
67 }
68 else {
69 0 croak "HeaderField needs to have a type/name parameter!";
70 }
71 }
72  
73 0 ▶ if (exists $param{raw}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{'raw'}) { } 0 0 0
74 0 ▶ if ($param{type} == 0x00) {
Branch: 3 branches
BranchTrueFalseTotal
if ($param{'type'} == 0) { } 0 0 0
elsif ($param{'type'} == 1) { } 0 0 0
elsif ($param{'type'} == 4) { } 0 0 0
75 0 $self->{value} = unpack('L<2', $param{raw});# maybe WW or CC ?
76 }
77 elsif ($param{type} == 0x01) {
78 0 $self->{value} = unpack('L<4', $param{raw});
79 }
80 elsif ($param{type} == 0x04) {
81 0 $self->{value} = unpack('L<', $param{raw});
82 }
83 else {
84 0 $self->{value} = $param{raw};
85 }
86 0 $self->{len} = length($param{raw});
87 }
88 else {
89 0 ▶ if (exists $param{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{'value'}) { } 0 0 0
90 0 ▶ if ($param{type} == 0x00) {
Branch: 3 branches
BranchTrueFalseTotal
if ($param{'type'} == 0) { } 0 0 0
elsif ($param{'type'} == 1) { } 0 0 0
elsif ($param{'type'} == 4) { } 0 0 0
91 0 $self->{raw} = pack("L<2", $param{value});
92 }
93 elsif ($param{type} == 0x01) {
94 0 $self->{raw} = pack('L<4', $param{value});
95 }
96 elsif ($param{type} == 0x04) {
97 0 $self->{raw} = pack('L<', $param{value});
98 }
99 else {
100 0 $self->{raw} = $param{value};
101 }
102 }
103 else {
104 0 croak "Either raw or value must be given to Crypt::PWSafe3::Field->new()";
105 }
106 }
107  
108 0 $self->{len} = length($param{raw});
109  
110 0 ▶ if (exists $Crypt::PWSafe3::HeaderField::map2name{$self->{type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map2name{$self->{'type'}}) { } 0 0 0
111 0 $self->{name} = $Crypt::PWSafe3::HeaderField::map2name{$self->{type}};
112 }
113 else {
114 0 $self->{name} = $self->{type};
115 }
116  
117 0 return $self;
118 }
119  
120  
121 0 ▶sub eq {
Subroutine eq: not called CC=1 SCAR=6.9
Pod undocumented
122 #
123 # compare this field with the given one
124 0 my ($this, $field) = @_;
125 0 return $this->type == $field->type and $this->value eq $field->value;
126 }
127  
128 =head1 NAME
129  
130 Crypt::PWSafe3::HeaderField - represent a passwordsafe v3 header field.
131  
132 =head1 SYNOPSIS
133  
134 use Crypt::PWSafe3;
135 my $who = $vault->getheader('wholastsaved');
136 print $who->value;
137  
138 my $h = Crypt::PWSafe3::HeaderField->new(name => 'savedonhost',
139 value => 'localhost');
140 $vault->addheader($h);
141  
142 =head1 DESCRIPTION
143  
144 B<Crypt::PWSafe3::HeaderField> represents a header field. This is the
145 raw implementation and you normally don't have to cope with it.
146  
147 However, if you ever do, you can add/replace any field type
148 this way:
149  
150 my $field = Crypt::PWSafe3::HeaderField->new(
151 value => 'localhost',
152 name => 'savedonhost'
153 );
154 $record->addheader($field);
155  
156 This is the preferred way to do it, Crypt::PWSafe3 does
157 it internaly exactly like this.
158  
159 If there already exists a field of this type, it will
160 be overwritten.
161  
162 =head1 HEADER FIELDS
163  
164 A password safe v3 database supports the following header fields:
165  
166 version
167  
168 uuid
169  
170 preferences
171  
172 treedisplaystatus
173  
174 lastsavetime
175  
176 wholastsaved
177  
178 whatlastsaved
179  
180 savedbyuser
181  
182 savedonhost
183  
184 databasename
185  
186 databasedescr
187  
188 databasefilters
189  
190 eof
191  
192 Refer to L<Crypt::PWSafe3::Databaseformat> for details on those
193 header fields.
194  
195 =head1 SEE ALSO
196  
197 L<Crypt::PWSafe3>
198  
199 =head1 AUTHOR
200  
201 T.v.Dein <tlinden@cpan.org>
202  
203 =head1 COPYRIGHT
204  
205 Copyright (c) 2011-2015 by T.v.Dein <tlinden@cpan.org>.
206 All rights reserved.
207  
208 =head1 LICENSE
209  
210 This program is free software; you can redistribute it
211 and/or modify it under the same terms of the Artistic
212 License 2.0, see: L<http://www.perlfoundation.org/artistic_license_2_0>
213  
214 =cut
215  
216 1 1;
↑ Summary PWSafe3/Field.pm »