Debian Codegraph @

dns/rdtypes/ANY/CSYNC.py

raw
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2
3 # Copyright (C) 2004-2007, 2009-2011, 2016 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 struct
19
20 import dns.exception
21 import dns.immutable
22 import dns.name
23 import dns.rdata
24 import dns.rdatatype
25 import dns.rdtypes.util
26
27
28 @dns.immutable.immutable
29 class Bitmap(dns.rdtypes.util.Bitmap):
30 type_name = "CSYNC"
31
32
33 @dns.immutable.immutable
34 class CSYNC(dns.rdata.Rdata):
35 """CSYNC record"""
36
37 __slots__ = ["serial", "flags", "windows"]
38
39 def __init__(self, rdclass, rdtype, serial, flags, windows):
40 super().__init__(rdclass, rdtype)
41 self.serial = self._as_uint32(serial)
42 self.flags = self._as_uint16(flags)
43 if not isinstance(windows, Bitmap):
44 windows = Bitmap(windows)
45 self.windows = tuple(windows.windows)
46
47 def to_text(self, origin=None, relativize=True, **kw):
48 text = Bitmap(self.windows).to_text()
49 return f"{self.serial} {self.flags}{text}"
50
51 @classmethod
52 def from_text(
53 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
54 ):
55 serial = tok.get_uint32()
56 flags = tok.get_uint16()
57 bitmap = Bitmap.from_text(tok)
58 return cls(rdclass, rdtype, serial, flags, bitmap)
59
60 def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
61 file.write(struct.pack("!IH", self.serial, self.flags))
62 Bitmap(self.windows).to_wire(file)
63
64 @classmethod
65 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
66 (serial, flags) = parser.get_struct("!IH")
67 bitmap = Bitmap.from_wire_parser(parser)
68 return cls(rdclass, rdtype, serial, flags, bitmap)