1#!/usr/local/bin/perl -w
2######################################################################
3#
4# DNS/Config/Statement/Key.pm
5#
6# $Id: Key.pm,v 1.3 2003/02/16 10:15:33 awolf Exp $
7# $Revision: 1.3 $
8# $Author: awolf $
9# $Date: 2003/02/16 10:15:33 $
10#
11# Copyright (C)2003 Bruce Campbell. All rights reserved.
12# Base Class (Options) (C)2001-2003 Andy Wolf. All rights reserved.
13#
14# This library is free software; you can redistribute it and/or
15# modify it under the same terms as Perl itself.
16#
17######################################################################
18
19package DNS::Config::Statement::Key;
20
21use strict;
22use vars qw(@ISA);
23
24use DNS::Config::Statement;
25
26@ISA = qw(DNS::Config::Statement);
27
28my $VERSION   = '0.66';
29my $REVISION  = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
30
31sub new {
32	my($pkg) = @_;
33	my $class = ref($pkg) || $pkg;
34
35	my $self = {
36                'ALGORITHM' => 'hmac-md5'
37        };
38
39
40	bless $self, $class;
41
42	return $self;
43}
44
45sub parse_tree {
46	my($self, @array) = @_;
47
48	return undef if((scalar(@array) < 2) || (scalar(@array) > 3));
49
50	$self->{'NAME'} = shift @array;
51	$self->{'NAME'} =~ s/^\"//g;
52	$self->{'NAME'} =~ s/\"$//g;
53
54	my $data = shift @array;
55	my @data = @$data;
56
57	foreach my $stmt (@data) {
58		my @stmt = @$stmt;
59
60		my $key = uc shift @stmt;
61
62		if(scalar(@stmt) == 1) {
63			$self->{$key} = shift @stmt;
64			$self->{$key} =~ s/^\"//g;
65			$self->{$key} =~ s/\"$//g;
66		}
67		else {
68			$self->{$key} = \@stmt;
69		}
70	}
71
72	return $self;
73}
74
75sub dump {
76	my($self) = @_;
77	my @array;
78
79	my @array2;
80	foreach my $key (keys %$self) {
81		if(($key =~ /FILE/) || ($key =~ /DIRECTORY/)) {
82			push @array2, ([ lc $key, q(") . $self->{$key} . q(")]);
83		}
84		elsif(($key ne 'NAME') && ($key ne 'CLASS')) {
85			push @array2, ([ lc $key, $self->{$key}]);
86		}
87	}
88
89	push @array, ('key', q(") . $self->{'NAME'} . q("));
90	push @array, ($self->{'CLASS'}) if(exists $self->{'CLASS'});
91	push @array, (\@array2);
92
93	my $string = $self->substatement(@array);
94	print $string, "\n";
95
96	return $self;
97}
98
99sub name {
100	my($self, $name) = @_;
101
102	$self->{'NAME'} = $name if($name);
103
104	return $self->{'NAME'};
105}
106
107sub algorithm {
108	my($self, $alg) = @_;
109
110	$self->{'ALGORITHM'} = $alg if($alg);
111
112	return $self->{'ALGORITHM'};
113}
114
115sub secret {
116	my($self, $secret) = @_;
117
118	$self->{'SECRET'} = $secret if($secret);
119
120	return $self->{'SECRET'};
121}
122
1231;
124
125__END__
126
127=pod
128
129=head1 NAME
130
131DNS::Config::Statement::Key - Key statement
132
133=head1 SYNOPSIS
134
135use DNS::Config::Statement::Key;
136
137my $key = new DNS::Config::Statement::Key();
138
139$key->dump();
140
141
142=head1 ABSTRACT
143
144This class represents a key statement in a domain name service
145daemon (DNS) configuration.  These contain TSIG algorithms and
146secrets.
147
148
149=head1 DESCRIPTION
150
151This class represents a key statement. As such it can, for
152example, have informations about algorithm and secret used.
153
154So far this class is strongly related to the ISCs Bind domain
155name service daemon but it is inteded to get more generic in
156upcoming releases. Your help is welcome.
157
158
159=head1 AUTHOR
160
161Copyright (C)2003 Bruce Campbell. All rights reserved.
162
163This library is free software; you can redistribute it and/or
164modify it under the same terms as Perl itself.
165
166Please address bug reports and comments to:
167bxc@users.sourceforge.net
168
169
170=head1 SEE ALSO
171
172L<DNS::Config>, L<DNS::Config::Statement>
173
174
175=cut
176