TacacsPlus/Packet/Header.pm

filter: Statementstmt 81.0% 30 / 37 Branchbran 50.0% 6 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 3 / 3 totaltotal 75.4% 46 / 61 CC 7 SCAR 16.1
CC
7
Cov
73%
new
9.3
decode
2.0
raw
2.0
CRAP 5.0
« TacacsPlus/Packet/AccountRequestBody.pm ↑ Summary TacacsPlus/Packet/AuthorRequestBody.pm »
1 package Net::TacacsPlus::Packet::Header;
2  
3 =head1 NAME
4  
5 Net::TacacsPlus::Packet::Header - Tacacs+ packet header
6  
7 =head1 DESCRIPTION
8  
9 3. The TACACS+ packet header
10  
11 All TACACS+ packets always begin with the following 12 byte header.
12 The header is always cleartext and describes the remainder of the
13 packet:
14  
15  
16 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
17
18 +----------------+----------------+----------------+----------------+
19 |major | minor | | | |
20 |version| version| type | seq_no | flags |
21 +----------------+----------------+----------------+----------------+
22 | |
23 | session_id |
24 +----------------+----------------+----------------+----------------+
25 | |
26 | length |
27 +----------------+----------------+----------------+----------------+
28  
29 =cut
30  
31 11 our $VERSION = '1.10';
32  
33 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 11 ▶use Net::TacacsPlus::Constants 1.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 11 ▶use Carp::Clan;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 11 ▶use base qw{ Class::Accessor::Fast };
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 11 __PACKAGE__->mk_accessors(qw{
43 version
44 type
45 seq_no
46 flags
47 session_id
48 length
49 });
50  
51 =head1 METHODS
52  
53 =over 4
54  
55 =item new( somekey => somevalue)
56  
57 Construct tacacs+ packet header object
58  
59 1. if constructing from parameters:
60  
61 'version': protocol version
62 'type': TAC_PLUS_(AUTHEN|AUTHOR|ACCT)
63 'seq_no': sequencenumber - default 1
64 'flags': TAC_PLUS_(UNENCRYPTED_FLAG|SINGLE_CONNECT_FLAG) - default none
65 'session_id': session id
66  
67 2. if constructing from raw packet
68  
69 'raw_header': raw packet
70  
71 =cut
72  
73 1 ▶sub new {
Subroutine new: called CC=7 SCAR=22.3
Pod documented
74 1 my $class = shift;
75 1 my %params = @_;
76
77 #let the class accessor contruct the object
78 1 my $self = $class->SUPER::new(\%params);
79  
80 #build header from binary data
81 1 ▶ if ($params{'raw_header'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"raw_header"}) 0 1 1
82 0 $self->decode($params{'raw_header'});
83 0 delete $self->{'raw_header'};
84 0 return $self;
85 }
86  
87 #parameters check and default values
88 1 ▶ carp("session_id must be set!") if not defined $self->session_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->session_id 0 1 1
89 1 ▶ carp("version must be set!") if not defined $self->version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->version 0 1 1
90 1 ▶ carp("type must be set!") if not defined $self->type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->type 0 1 1
91 1 ▶ $self->seq_no(1) if not defined $self->seq_no();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->seq_no 0 1 1
92 1 ▶ $self->flags(0) if not defined $self->flags();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->flags 0 1 1
93  
94 1 return $self;
95 }
96  
97 =item decode($raw_data)
98  
99 Decode $raw_data to version, type, seq_no, flags, session_id, length
100  
101 =cut
102  
103 0 ▶sub decode {
Subroutine decode: not called CC=1 SCAR=6.9
Pod documented
104 0 my ($self, $raw_data) = @_;
105
106 ( $self->{'version'}, #i dont't use object calls ->xyz() to improve speed a little bit and he it is not really neccesary
107 $self->{'type'},
108 $self->{'seq_no'},
109 $self->{'flags'},
110 $self->{'session_id'},
111 0 $self->{'length'} ) = unpack("CCCCNN", $raw_data);
112
113 }
114  
115 =item raw()
116  
117 returns raw binary representation of header.
118  
119 B<NOTE> For complete binary header, length of body must be
120 added.
121  
122 =cut
123  
124 0 ▶sub raw {
Subroutine raw: not called CC=1 SCAR=6.9
Pod documented
125 0 my $self = shift;
126  
127 return pack("CCCCN", #i dont't use object calls ->xyz() to improve speed a little bit and he it is not really neccesary
128 $self->{'version'},
129 $self->{'type'},
130 $self->{'seq_no'},
131 $self->{'flags'},
132 0 $self->{'session_id'},
133 );
134 }
135  
136 =back
137  
138 =cut
139  
140 11 1;
« TacacsPlus/Packet/AccountRequestBody.pm ↑ Summary TacacsPlus/Packet/AuthorRequestBody.pm »