blib/lib/SMB/v1/Header.pm untested

filter: Statementstmt 0.0% 0 / 20 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 13 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 45 SCAR 17.9
CC
2
Cov
0%
is_response
6.0
new
2.0
is_signed
2.0
CRAP 6.0
1 # SMB Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15  
16 package SMB::v1::Header;
17  
18 use strict;
19 use warnings;
20  
21 use parent 'SMB::Header';
22  
23 use constant {
24 # the command is a response, otherwise a request
25 FLAGS_RESPONSE => 0x80,
26 # client supports signing, server forces signing
27 FLAGS2_SECURITY_SIGNATURE => 0x0004,
28 # client desires compression, server agrees to compress
29 FLAGS2_COMPRESSED => 0x0008,
30 # client supports signing, server forces signing
31 FLAGS2_SECURITY_SIGNATURE_REQUIRED => 0x0010,
32 # extended security negotiation is supported
33 FLAGS2_EXTENDED_SECURITY_NEGOTIATION => 0x0800,
34 # string are in Unicode (UTF-16LE) encoding
35 FLAGS2_UNICODE => 0x8000,
36 # NT statuses used
37 FLAGS2_NT_STATUS => 0x4000,
38 };
39  
40 sub new ($%) {
41 my $class = shift;
42 my %options = @_;
43  
44 return $class->SUPER::new(
45 pid => delete $options{pid} || 0,
46 flags2 => delete $options{flags2} || 0,
47 %options,
48 );
49 }
50  
51 sub is_response ($) {
52 my $self = shift;
53  
54 return $self->flags & FLAGS_RESPONSE ? 1 : 0;
55 }
56  
57 sub is_signed ($) {
58 my $self = shift;
59 my $signature = $self->signature;
60  
61 return ref($signature) eq 'ARRAY' && @$signature == 8 &&
62 (join('', $signature) ne "\0" x 8) &&
63 ($self->flags2 & FLAGS2_SECURITY_SIGNATURE) != 0;
64 }
65  
66 1;