aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/DNS-LDNS/lib/DNS/LDNS/RRList.pm
blob: 11570acbcdde624ecfc29a5bd15b90d6d8213d0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package DNS::LDNS::RRList;

use 5.008008;
use strict;
use warnings;

use DNS::LDNS;

our $VERSION = '0.06';

sub new {
    my ($class, %args) = @_;

    if ($args{hosts_filename} or $args{hosts_file})  {
	my $file = $args{hosts_file};
	if ($args{hosts_filename}) {
	    unless (open FILE, $args{hosts_filename}) {
		$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
		$DNS::LDNS::line_nr = 0;
		return;
	    }
	    $file = \*FILE;
	}
	my $list = _new_hosts_from_file($file, $DNS::LDNS::line_nr);
	if ($args{hosts_filename}) {
	    close $file;
	}
	return $list;
    }
    
    return _new();
}

sub rr {
    my ($self, $index) = @_;
    return DNS::LDNS::GC::own($self->_rr($index), $self);
}

sub push {
    my ($self, @rrs) = @_;

    for my $rr (@rrs) {
	# Push a copy of the rr in case it is already owned
	$self->_push(my $copy = $rr->clone);
	DNS::LDNS::GC::own($copy, $self);
    }
}

sub push_list {
    my ($self, $list) = @_;

    $self->_push_list(my $copy = $list->clone);
    DNS::LDNS::GC::own($copy, $self);
}

sub verify {
    my ($self, $sig, $keys) = @_;
    my $goodkeys = new DNS::LDNS::RRList;
    my $s = _verify($self, $sig, $keys, $goodkeys);
    $DNS::LDNS::last_status = $s;
    return wantarray ? ($s, $goodkeys) : $s;
}

sub verify_time {
    my ($self, $sig, $keys, $checktime) = @_;
    my $goodkeys = new DNS::LDNS::RRList;
    my $s = _verify_time($self, $sig, $keys, $checktime, $goodkeys);
    $DNS::LDNS::last_status = $s;
    return wantarray ? ($s, $goodkeys) : $s;
}

sub verify_notime {
    my ($self, $sig, $keys) = @_;
    my $goodkeys = new DNS::LDNS::RRList;
    my $s = _verify_notime($self, $sig, $keys, $goodkeys);
    $DNS::LDNS::last_status = $s;
    return wantarray ? ($s, $goodkeys) : $s;
}

sub verify_rrsig_keylist {
    my ($self, $sig, $keys) = @_;
    my $goodkeys = new DNS::LDNS::RRList;
    my $s = _verify_rrsig_keylist($self, $sig, $keys, $goodkeys);
    $DNS::LDNS::last_status = $s;
    return wantarray ? ($s, $goodkeys) : $s;
}

sub verify_rrsig_keylist_notime {
    my ($self, $sig, $keys, $check_time) = @_;
    my $goodkeys = new DNS::LDNS::RRList;
    my $s = _verify_rrsig_keylist_notime($self, $sig, $keys, $goodkeys);
    $DNS::LDNS::last_status = $s;
    return wantarray ? ($s, $goodkeys) : $s;
}

sub get_dnskey_for_rrsig {
    my ($self, $rrsig) = @_;
    return DNS::LDNS::GC::own(_get_dnskey_for_rrsig($rrsig, $self), $self);
}

sub get_rrsig_for_name_and_type {
    my ($self, $name, $type) = @_;
    return DNS::LDNS::GC::own(
	_get_dnskey_for_name_and_type($name, $type, $self), $self);
}

sub DESTROY {
    DNS::LDNS::GC::free($_[0]);
}

1;
__END__

=head1 NAME

DNS::LDNS::RRList - List of rrs

=head1 SYNOPSIS

  use DNS::LDNS ':all'

  my l = new DNS::LDNS::RRList
  my l = new DNS::LDNS::RRList(hosts_file => \*FILE)
  my l = new DNS::LDNS::RRList(hosts_filename => fname)
  my l2 = l->clone

  l->to_string

  l->print(\*FILE)
  count = l->rr_count

  rr = l->rr(index)
  l->push(@rr)
  rr = l->pop

  l->push_list(l2)
  l2 = l->pop_list(count)
  l2 = l->pop_rrset

  l->compare(l2)

  l2 = l->subtype_by_rdata(rdata, pos)

  bool = l->is_rrset

  bool = l->contains_rr(rr)

  (status, goodkeys) = l->verify(sig, keys)
  (status, goodkeys) = l->verify_time(sig, keys, checktime)
  (status, goodkeys) = l->verify_notime(sig, keys)
  (status, goodkeys) = l->verify_rrsig_keylist(sig, keys)
  (status, goodkeys) = l->verify_rrsig_keylist_time(sig, keys, checktime)
  (status, goodkeys) = l->verify_rrsig_keylist_notime(sig, keys)
  status = l->verify_rrsig(sig, keys)
  status = l->verify_rrsig_time(sig, keys, checktime)

  rr = l->create_empty_rrsig(key)
  rrlist = l->sign_public(keylist)

  rrlist->canonicalize
  rrlist->sort
  rrlist->sort_nsec3   # the list must contain only nsec3 rrs

  rr = keylist->get_dnskey_for_rrsig(rrsig)
  rr = keylist->get_rrsig_for_name_and_type(name, type)

=head1 SEE ALSO

http://www.nlnetlabs.nl/projects/ldns

=head1 AUTHOR

Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2013 by UNINETT Norid AS

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.

=cut