Debian Codegraph @

dns/rdtypes/ANY/NSEC.py

raw
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2
3 # Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
4 #
5 # Permission to use, copy, modify, and distribute this software and its
6 # documentation for any purpose with or without fee is hereby granted,
7 # provided that the above copyright notice and this permission notice
8 # appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18 import dns.exception
19 import dns.immutable
20 import dns.name
21 import dns.rdata
22 import dns.rdatatype
23 import dns.rdtypes.util
24
25
26 @dns.immutable.immutable
27 class Bitmap(dns.rdtypes.util.Bitmap):
28 type_name = "NSEC"
29
30
31 @dns.immutable.immutable
32 class NSEC(dns.rdata.Rdata):
33 """NSEC record"""
34
35 __slots__ = ["next", "windows"]
36
37 def __init__(self, rdclass, rdtype, next, windows):
38 super().__init__(rdclass, rdtype)
39 self.next = self._as_name(next)
40 if not isinstance(windows, Bitmap):
41 windows = Bitmap(windows)
42 self.windows = tuple(windows.windows)
43
44 def to_text(self, origin=None, relativize=True, **kw):
45 next = self.next.choose_relativity(origin, relativize)
46 text = Bitmap(self.windows).to_text()
47 return f"{next}{text}"
48
49 @classmethod
50 def from_text(
51 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
52 ):
53 next = tok.get_name(origin, relativize, relativize_to)
54 windows = Bitmap.from_text(tok)
55 return cls(rdclass, rdtype, next, windows)
56
57 def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
58 # Note that NSEC downcasing, originally mandated by RFC 4034
59 # section 6.2 was removed by RFC 6840 section 5.1.
60 self.next.to_wire(file, None, origin, False)
61 Bitmap(self.windows).to_wire(file)
62
63 @classmethod
64 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
65 next = parser.get_name(origin)
66 bitmap = Bitmap.from_wire_parser(parser)
67 return cls(rdclass, rdtype, next, bitmap)