]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests.recursor-dnssec/paddingoption.py
Merge pull request #13927 from rgacogne/fix-fclose-warnings
[thirdparty/pdns.git] / regression-tests.recursor-dnssec / paddingoption.py
CommitLineData
98e0c0a0
RG
1#!/usr/bin/env python
2
3import dns
4import dns.edns
5import dns.flags
6import dns.message
7import dns.query
8
9class PaddingOption(dns.edns.Option):
10 """Implementation of rfc7830.
11 """
12
13 def __init__(self, numberOfBytes):
14 super(PaddingOption, self).__init__(12)
15 self.numberOfBytes = numberOfBytes
16
c8567be6 17 def to_wire(self, file=None):
98e0c0a0
RG
18 """Create EDNS packet as defined in rfc7830."""
19
c8567be6
RG
20 if file:
21 file.write(bytes(self.numberOfBytes))
22 else:
23 return bytes(self.numberOfBytes)
98e0c0a0
RG
24
25 def from_wire(cls, otype, wire, current, olen):
26 """Read EDNS packet as defined in rfc7830.
27
28 Returns:
29 An instance of PaddingOption based on the EDNS packet
30 """
31
32 numberOfBytes = olen
33
34 return cls(numberOfBytes)
35
36 from_wire = classmethod(from_wire)
37
c8567be6
RG
38 # needed in 2.0.0
39 @classmethod
40 def from_wire_parser(cls, otype, parser):
41 data = parser.get_remaining()
42 return cls(len(data))
43
98e0c0a0
RG
44 def __repr__(self):
45 return '%s(%d)' % (
46 self.__class__.__name__,
47 self.numberOfBytes
48 )
49
50 def __eq__(self, other):
51 if not isinstance(other, PaddingOption):
52 return False
53 return self.numberOfBytes == numberOfBytes
54
55 def __ne__(self, other):
56 return not self.__eq__(other)
57
58
59dns.edns._type_to_class[0x000C] = PaddingOption