| 1 | #!/bin/false | ||
| 2 | # ABSTRACT: Authentication option (code 11) -- protocol/algorithm/rdm/replay/auth-info | ||
| 3 | # PODNAME: Net::DHCPv6::Option::Auth | ||
| 4 | use strictures 2; | ||
| 5 | |||
| 6 | package Net::DHCPv6::Option::Auth; | ||
| 7 | $Net::DHCPv6::Option::Auth::VERSION = '0.002'; | ||
| 8 | use Net::DHCPv6::OptionList; | ||
| 9 | use Carp qw( croak ); | ||
| 10 | use Net::DHCPv6::Constants; | ||
| 11 | use Net::DHCPv6::X::Truncated; | ||
| 12 | use parent 'Net::DHCPv6::Option'; | ||
| 13 | use namespace::clean; | ||
| 14 | my $EMPTY = q(); | ||
| 15 | my $REPLAY_WIRE_LEN = 8; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers) | ||
| 16 | my $MIN_PAYLOAD = 11; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers) | ||
| 17 | |||
| 18 | sub new { | ||
| 19 | my ( $class, %args ) = @_; | ||
| 20 | for my $field ( qw(protocol algorithm rdm replay) ) { | ||
| 21 | croak "Auth requires $field" unless defined $args{$field}; | ||
| 22 | } | ||
| 23 | croak 'Auth replay must be exactly 8 bytes' | ||
| 24 | if CORE::length( $args{replay} ) != $REPLAY_WIRE_LEN; | ||
| 25 | $args{code} = $OPTION_AUTH; | ||
| 26 | $args{data} = | ||
| 27 | pack( 'C C C a8 a*', $args{protocol}, $args{algorithm}, $args{rdm}, $args{replay}, $args{auth_info} // $EMPTY ); | ||
| 28 | my $self = $class->SUPER::new( %args ); | ||
| 29 | $self->{protocol} = $args{protocol}; | ||
| 30 | $self->{algorithm} = $args{algorithm}; | ||
| 31 | $self->{rdm} = $args{rdm}; | ||
| 32 | $self->{replay} = $args{replay}; | ||
| 33 | $self->{auth_info} = $args{auth_info} // $EMPTY; | ||
| 34 | return bless $self, $class; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub protocol { return shift->{protocol} } | ||
| 38 | sub algorithm { return shift->{algorithm} } | ||
| 39 | sub rdm { return shift->{rdm} } | ||
| 40 | sub replay { return shift->{replay} } | ||
| 41 | sub auth_info { return shift->{auth_info} } | ||
| 42 | |||
| 43 | sub from_bytes_inner { | ||
| 44 | my ( $class, $code, $payload ) = @_; | ||
| 45 | Net::DHCPv6::X::Truncated->throw( message => 'Truncated Auth option' ) | ||
| 46 | if CORE::length( $payload ) < $MIN_PAYLOAD; | ||
| 47 | my ( $proto, $alg, $rdm, $replay, $auth_info ) = unpack( 'C C C a8 a*', $payload ); | ||
| 48 | return $class->new( | ||
| 49 | protocol => $proto, | ||
| 50 | algorithm => $alg, | ||
| 51 | rdm => $rdm, | ||
| 52 | replay => $replay, | ||
| 53 | auth_info => $auth_info, | ||
| 54 | ); | ||
| 55 | } | ||
| 56 | |||
| 57 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_AUTH} = __PACKAGE__; | ||
| 58 | 1; | ||
| 59 | |||
| 60 | __END__ |