TacacsPlus/Packet/AuthorResponseBody.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 100% 62 / 62 CC 3 SCAR 3.1
CC
3
Cov
100%
new
2.0
decode
2.0
BEGIN
1.0
CRAP 1.4
« TacacsPlus/Packet/AuthenContinueBody.pm ↑ Summary TacacsPlus/Constants.pm »
1 package Net::TacacsPlus::Packet::AuthorResponseBody;
2  
3 =head1 NAME
4  
5 Net::TacacsPlus::Packet::AuthorResponseBody - Tacacs+ authorization response body
6  
7 =head1 DESCRIPTION
8  
9 The authorization RESPONSE packet body
10  
11  
12  
13 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
14  
15 +----------------+----------------+----------------+----------------+
16 | status | arg_cnt | server_msg len |
17 +----------------+----------------+----------------+----------------+
18 + data len | arg 1 len | arg 2 len |
19 +----------------+----------------+----------------+----------------+
20 | ... | arg N len | server_msg ...
21 +----------------+----------------+----------------+----------------+
22 | data ...
23 +----------------+----------------+----------------+----------------+
24 | arg 1 ...
25 +----------------+----------------+----------------+----------------+
26 | arg 2 ...
27 +----------------+----------------+----------------+----------------+
28 | ...
29 +----------------+----------------+----------------+----------------+
30 | arg N ...
31 +----------------+----------------+----------------+----------------+
32  
33 =cut
34  
35  
36 11 our $VERSION = '1.10';
37  
38 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 11 ▶use Net::TacacsPlus::Constants 1.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 11 ▶use Carp::Clan;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 11 ▶use base qw{ Class::Accessor::Fast };
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 11 __PACKAGE__->mk_accessors(qw{
48 status
49 server_msg
50 data
51 args
52 });
53  
54 =head1 METHODS
55  
56 =over 4
57  
58 =item new( somekey => somevalue)
59  
60 Construct tacacs+ authorization response body object
61  
62 Parameters:
63  
64 'raw_body': raw body
65  
66 =cut
67  
68 2 ▶sub new() {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
69 2 my $class = shift;
70 2 my %params = @_;
71  
72 #let the class accessor contruct the object
73 2 my $self = $class->SUPER::new(\%params);
74  
75 2 ▶ if ($params{'raw_body'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"raw_body"}) 1 1 2
76 1 $self->decode($params{'raw_body'});
77 1 delete $self->{'raw_body'};
78 1 return $self;
79 }
80  
81 1 return $self;
82 }
83  
84 =item decode($raw_data)
85  
86 Extract status, server_msg, data and arguments from raw packet.
87  
88 =cut
89  
90 1 ▶sub decode {
Subroutine decode: called CC=2 SCAR=6.9
Pod documented
91 1 my ($self, $raw_data) = @_;
92
93 1 my ($server_msg_len,$arg_cnt,@arg_lengths,$data_len,$offset,@args);
94
95 (
96 1 $self->{'status'},
97 $arg_cnt,
98 $server_msg_len,
99 $data_len,
100 ) = unpack("CCnn", $raw_data);
101 1 $offset = 6;
102
103 1 @arg_lengths = unpack("x$offset" . ("C" x $arg_cnt), $raw_data);
104 1 $offset += $arg_cnt;
105  
106 1 ($self->{'server_msg'}, $self->{'data'}) =
107 unpack("x$offset"."a".$server_msg_len."a".$data_len, $raw_data);
108 1 $offset += $server_msg_len + $data_len;
109  
110 1 foreach my $arglen (@arg_lengths)
111 {
112 3 push(@args, unpack("x$offset"."a$arglen", $raw_data));
113 3 $offset += $arglen;
114 }
115
116 1 $self->{'args'} = \@args;
117 }
118  
119  
120 =item raw()
121  
122 Return binary data of packet body.
123  
124 =cut
125  
126 1 ▶sub raw {
Subroutine raw: called CC=1 SCAR=0.0
Pod documented
127 1 my $self = shift;
128  
129 1 my $args_count = scalar(@{$self->{'args'}});
130 my $body = pack('CCnnC'.$args_count.'a*a*a*',
131 $self->{'status'},
132 $args_count,
133 length($self->{'server_msg'}),
134 length($self->{'data'}),
135 3 (map { length($_) } @{$self->{'args'}}),
136 $self->{'server_msg'},
137 $self->{'data'},
138 1 join('', @{$self->{'args'}}),
139 );
140  
141 1 return $body;
142 }
143  
144 =back
145  
146 =cut
147  
148 11 1;
« TacacsPlus/Packet/AuthenContinueBody.pm ↑ Summary TacacsPlus/Constants.pm »