PWSafe3/Field.pm

filter: Statementstmt 27.7% 23 / 83 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 41.6% 5 / 12 Podpod 0.0% 0 / 2 totaltotal 20.9% 28 / 134 CC 18 SCAR 44.3
CC
18
Cov
19%
new
182.0
__ANON__
5.6
__ANON__
5.6
CRAP 83.8
« PWSafe3/HeaderField.pm ↑ Summary PWSafe3.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 package Crypt::PWSafe3::Field;
8  
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::Field::VERSION = '1.06';
17  
18 1 %Crypt::PWSafe3::Field::map2type = (
19 uuid => 0x01,
20 group => 0x02,
21 title => 0x03,
22 user => 0x04,
23 passwd => 0x06,
24 notes => 0x05,
25 ctime => 0x07,
26 mtime => 0x08,
27 atime => 0x09,
28 reserve => 0x0b,
29 lastmod => 0x0c,
30 url => 0x0d,
31 autotype => 0x0e,
32 pwhist => 0x0f,
33 pwpol => 0x10,
34 pwexp => 0x11,
35 eof => 0xff
36 );
37 1 %Crypt::PWSafe3::Field::map2name = map { $Crypt::PWSafe3::Field::map2type{$_} => $_ } keys %Crypt::PWSafe3::Field::map2type;
38  
39 1 my @fields = qw(raw len value type name);
40 1 foreach my $field (@fields) {
41 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
42 *Crypt::PWSafe3::Field::$field = sub {
43 my(\$this, \$arg) = \@_;
44 if (\$arg) {
45 return \$this->{$field} = \$arg;
46 }
47 else {
48 return \$this->{$field};
49 }
50 }
51 );
52 }
53  
54 0 ▶sub new {
Subroutine new: not called CC=13 SCAR=52.0
Pod undocumented
55 #
56 # new field object
57 0 my($this, %param) = @_;
58 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
59 0 my $self = \%param;
60 0 bless($self, $class);
61  
62  
63  
64 0 ▶ if (! exists $param{type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $param{"type"}) 0 0 0
65 0 ▶ if (exists $param{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{'name'}) { } 0 0 0
66 0 $param{type} = $Crypt::PWSafe3::Field::map2type{$param{name}};
67 }
68 else {
69 0 croak "HeaderField needs to have a type/name parameter!";
70 }
71 }
72  
73 0 my @convtime = (0x07, 0x08, 0x09, 0x0a, 0x0c);
74 0 my @convhex = (0x01);
75 0 my @convbyte = (0x00, 0x11);
76  
77 0 ▶ if (exists $param{raw}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{'raw'}) { } 0 0 0
78 0 ▶ if (grep { $_ eq $param{type} } @convtime) {
Branch: 3 branches
BranchTrueFalseTotal
if (grep {$_ eq $param{'type'};} @convtime) { } 0 0 0
elsif (grep {$_ eq $param{'type'};} @convhex) { } 0 0 0
elsif (grep {$_ eq $param{'type'};} @convbyte) { } 0 0 0
79 0 $self->{value} = unpack("L<", $param{raw});
80 }
81 0 elsif (grep { $_ eq $param{type} } @convhex) {
82 0 $self->{value} = unpack('H*', $param{raw});
83 }
84 0 elsif (grep { $_ eq $param{type} } @convbyte) {
85 0 $self->{value} = unpack('S<', $param{raw});
86 }
87 else {
88 0 $self->{value} = $param{raw};
89 0 utf8::decode($self->{value});
90 }
91 0 $self->{len} = length($param{raw});
92 }
93 else {
94 0 ▶ if (exists $param{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{'value'}) { } 0 0 0
95 0 ▶ if (grep { $_ eq $param{type} } @convtime) {
Branch: 3 branches
BranchTrueFalseTotal
if (grep {$_ eq $param{'type'};} @convtime) { } 0 0 0
elsif (grep {$_ eq $param{'type'};} @convhex) { } 0 0 0
elsif (grep {$_ eq $param{'type'};} @convbyte) { } 0 0 0
96 0 $self->{raw} = pack("L<", $param{value});
97 }
98 0 elsif (grep { $_ eq $param{type} } @convhex) {
99 0 $self->{raw} = pack('H*', $param{value});
100 }
101 0 elsif (grep { $_ eq $param{type} } @convbyte) {
102 0 $self->{raw} = pack('S<', $param{value});
103 }
104 else {
105 0 $self->{raw} = $param{value};
106 0 utf8::encode($param{raw});
107 }
108 }
109 else {
110 0 croak "Either raw or value must be given to Crypt::PWSafe3::Field->new()";
111 }
112 }
113  
114 0 $self->{len} = length($param{raw});
115  
116 0 ▶ if (exists $Crypt::PWSafe3::Field::map2name{$self->{type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map2name{$self->{'type'}}) { } 0 0 0
117 0 $self->{name} = $Crypt::PWSafe3::Field::map2name{$self->{type}};
118 }
119 else {
120 0 $self->{name} = $self->{type};
121 }
122  
123 0 return $self;
124 }
125  
126 0 ▶sub eq {
Subroutine eq: not called CC=1 SCAR=6.9
Pod undocumented
127 #
128 # compare this field with the given one
129 0 my ($this, $field) = @_;
130 0 return $this->type == $field->type and $this->value eq $field->value;
131 }
132  
133 =head1 NAME
134  
135 Crypt::PWSafe3::Field - represent a passwordsafe v3 record field.
136  
137 =head1 SYNOPSIS
138  
139 use Crypt::PWSafe3;
140 my $record = $vault->getrecord($uuid);
141 print $record-{field}->{user}->raw();
142 print $record-{field}->{user}->len();
143  
144 =head1 DESCRIPTION
145  
146 B<Crypt::PWSafe3::Field> represents a record field. This is the
147 raw implementation and you normally don't have to cope with it.
148  
149 However, if you ever do, you can do it this way:
150  
151 my $field = Crypt::PWSafe3::Field->new(
152 value => 'testing',
153 name => 'title
154 );
155 $record->addfield($field);
156  
157 This is the preferred way to do it, Crypt::PWSafe3 does
158 it internaly exactly like this.
159  
160 If there already exists a record field of this type, it will
161 be overwritten.
162  
163 The better way to handle fields is the method B<modifyfield()>
164 of the class L<Crypt::PWSafe3::Record>.
165  
166 =head1 SEE ALSO
167  
168 L<Crypt::PWSafe3::Record>
169  
170 =head1 AUTHOR
171  
172 T.v.Dein <tlinden@cpan.org>
173  
174 =head1 COPYRIGHT
175  
176 Copyright (c) 2011-2015 by T.v.Dein <tlinden@cpan.org>.
177 All rights reserved.
178  
179 =head1 LICENSE
180  
181 This program is free software; you can redistribute it
182 and/or modify it under the same terms of the Artistic
183 License 2.0, see: L<http://www.perlfoundation.org/artistic_license_2_0>
184  
185 =cut
186  
187 1 1;
« PWSafe3/HeaderField.pm ↑ Summary PWSafe3.pm »