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