1package Net::DNS::RR::TKEY;
2
3use strict;
4use warnings;
5our $VERSION = (qw$Id: TKEY.pm 1814 2020-10-14 21:49:16Z willem $)[2];
6
7use base qw(Net::DNS::RR);
8
9
10=head1 NAME
11
12Net::DNS::RR::TKEY - DNS TKEY resource record
13
14=cut
15
16use integer;
17
18use Carp;
19
20use Net::DNS::Parameters qw(:class :type);
21use Net::DNS::DomainName;
22
23use constant ANY  => classbyname qw(ANY);
24use constant TKEY => typebyname qw(TKEY);
25
26
27sub _decode_rdata {			## decode rdata from wire-format octet string
28	my $self = shift;
29	my ( $data, $offset ) = @_;
30
31	my $limit = $offset + $self->{rdlength};
32
33	( $self->{algorithm}, $offset ) = Net::DNS::DomainName->decode(@_);
34
35	@{$self}{qw(inception expiration mode error)} = unpack "\@$offset N2n2", $$data;
36	$offset += 12;
37
38	my $key_size = unpack "\@$offset n", $$data;
39	$self->{key} = substr $$data, $offset + 2, $key_size;
40	$offset += $key_size + 2;
41
42	my $other_size = unpack "\@$offset n", $$data;
43	$self->{other} = substr $$data, $offset + 2, $other_size;
44	$offset += $other_size + 2;
45
46	croak('corrupt TKEY data') unless $offset == $limit;	# more or less FUBAR
47	return;
48}
49
50
51sub _encode_rdata {			## encode rdata as wire-format octet string
52	my $self = shift;
53
54	return '' unless defined $self->{algorithm};
55	my $rdata = $self->{algorithm}->encode;
56
57	$rdata .= pack 'N2n2', $self->inception, $self->expiration, $self->mode, $self->error;
58
59	my $key = $self->key;					# RFC2930(2.7)
60	$rdata .= pack 'na*', length $key, $key;
61
62	my $other = $self->other;				# RFC2930(2.8)
63	$rdata .= pack 'na*', length $other, $other;
64	return $rdata;
65}
66
67
68sub class {				## overide RR method
69	return 'ANY';
70}
71
72sub encode {				## overide RR method
73	my $self = shift;
74
75	my $owner = $self->{owner}->encode();
76	my $rdata = eval { $self->_encode_rdata() } || '';
77	return pack 'a* n2 N n a*', $owner, TKEY, ANY, 0, length $rdata, $rdata;
78}
79
80
81sub algorithm {
82	my $self = shift;
83
84	$self->{algorithm} = Net::DNS::DomainName->new(shift) if scalar @_;
85	return $self->{algorithm} ? $self->{algorithm}->name : undef;
86}
87
88
89sub inception {
90	my $self = shift;
91
92	$self->{inception} = 0 + shift if scalar @_;
93	return $self->{inception} || 0;
94}
95
96
97sub expiration {
98	my $self = shift;
99
100	$self->{expiration} = 0 + shift if scalar @_;
101	return $self->{expiration} || 0;
102}
103
104
105sub mode {
106	my $self = shift;
107
108	$self->{mode} = 0 + shift if scalar @_;
109	return $self->{mode} || 0;
110}
111
112
113sub error {
114	my $self = shift;
115
116	$self->{error} = 0 + shift if scalar @_;
117	return $self->{error} || 0;
118}
119
120
121sub key {
122	my $self = shift;
123
124	$self->{key} = shift if scalar @_;
125	return $self->{key} || "";
126}
127
128
129sub other {
130	my $self = shift;
131
132	$self->{other} = shift if scalar @_;
133	return $self->{other} || "";
134}
135
136
137sub other_data { return &other; }				# uncoverable pod
138
139
1401;
141__END__
142
143
144=head1 SYNOPSIS
145
146    use Net::DNS;
147
148=head1 DESCRIPTION
149
150Class for DNS TSIG Key (TKEY) resource records.
151
152=head1 METHODS
153
154The available methods are those inherited from the base class augmented
155by the type-specific methods defined in this package.
156
157Use of undocumented package features or direct access to internal data
158structures is discouraged and could result in program termination or
159other unpredictable behaviour.
160
161
162=head2 algorithm
163
164    $algorithm = $rr->algorithm;
165    $rr->algorithm( $algorithm );
166
167The algorithm name is in the form of a domain name with the same
168meaning as in [RFC 2845].  The algorithm determines how the secret
169keying material agreed to using the TKEY RR is actually used to derive
170the algorithm specific key.
171
172=head2 inception
173
174    $inception = $rr->inception;
175    $rr->inception( $inception );
176
177Time expressed as the number of non-leap seconds modulo 2**32 since the
178beginning of January 1970 GMT.
179
180=head2 expiration
181
182    $expiration = $rr->expiration;
183    $rr->expiration( $expiration );
184
185Time expressed as the number of non-leap seconds modulo 2**32 since the
186beginning of January 1970 GMT.
187
188=head2 mode
189
190    $mode = $rr->mode;
191    $rr->mode( $mode );
192
193The mode field specifies the general scheme for key agreement or the
194purpose of the TKEY DNS message, as defined in [RFC2930(2.5)].
195
196=head2 error
197
198    $error = $rr->error;
199    $rr->error( $error );
200
201The error code field is an extended RCODE.
202
203=head2 key
204
205    $key = $rr->key;
206    $rr->key( $key );
207
208Sequence of octets representing the key exchange data.
209The meaning of this data depends on the mode.
210
211=head2 other
212
213    $other = $rr->other;
214    $rr->other( $other );
215
216Content not defined in the [RFC2930] specification but may be used
217in future extensions.
218
219
220=head1 COPYRIGHT
221
222Copyright (c)2000 Andrew Tridgell.
223
224All rights reserved.
225
226Package template (c)2009,2012 O.M.Kolkman and R.W.Franks.
227
228
229=head1 LICENSE
230
231Permission to use, copy, modify, and distribute this software and its
232documentation for any purpose and without fee is hereby granted, provided
233that the above copyright notice appear in all copies and that both that
234copyright notice and this permission notice appear in supporting
235documentation, and that the name of the author not be used in advertising
236or publicity pertaining to distribution of the software without specific
237prior written permission.
238
239THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
240IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
242THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
244FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
245DEALINGS IN THE SOFTWARE.
246
247
248=head1 SEE ALSO
249
250L<perl>, L<Net::DNS>, L<Net::DNS::RR>, RFC2930
251
252=cut
253