1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """EDNS Options"""
17
18 NSID = 3
21 """Base class for all EDNS option types.
22 """
23
25 """Initialize an option.
26 @param otype: The rdata type
27 @type otype: int
28 """
29 self.otype = otype
30
32 """Convert an option to wire format.
33 """
34 raise NotImplementedError
35
36 @classmethod
37 - def from_wire(cls, otype, wire, current, olen):
38 """Build an EDNS option object from wire format
39
40 @param otype: The option type
41 @type otype: int
42 @param wire: The wire-format message
43 @type wire: string
44 @param current: The offet in wire of the beginning of the rdata.
45 @type current: int
46 @param olen: The length of the wire-format option data
47 @type olen: int
48 @rtype: dns.ends.Option instance"""
49 raise NotImplementedError
50
51 - def _cmp(self, other):
52 """Compare an ENDS option with another option of the same type.
53 Return < 0 if self < other, 0 if self == other, and > 0 if self > other.
54 """
55 raise NotImplementedError
56
58 if not isinstance(other, Option):
59 return False
60 if self.otype != other.otype:
61 return False
62 return self._cmp(other) == 0
63
65 if not isinstance(other, Option):
66 return False
67 if self.otype != other.otype:
68 return False
69 return self._cmp(other) != 0
70
72 if not isinstance(other, Option) or \
73 self.otype != other.otype:
74 return NotImplemented
75 return self._cmp(other) < 0
76
78 if not isinstance(other, Option) or \
79 self.otype != other.otype:
80 return NotImplemented
81 return self._cmp(other) <= 0
82
84 if not isinstance(other, Option) or \
85 self.otype != other.otype:
86 return NotImplemented
87 return self._cmp(other) >= 0
88
90 if not isinstance(other, Option) or \
91 self.otype != other.otype:
92 return NotImplemented
93 return self._cmp(other) > 0
94
97 """Generate Rdata Class
98
99 This class is used for EDNS option types for which we have no better
100 implementation.
101 """
102
106
108 file.write(self.data)
109
110 - def _cmp(self, other):
112
113 @classmethod
114 - def from_wire(cls, otype, wire, current, olen):
115 return cls(otype, wire[current : current + olen])
116
117 _type_to_class = {
118 }
125
127 """Build an EDNS option object from wire format
128
129 @param otype: The option type
130 @type otype: int
131 @param wire: The wire-format message
132 @type wire: string
133 @param current: The offet in wire of the beginning of the rdata.
134 @type current: int
135 @param olen: The length of the wire-format option data
136 @type olen: int
137 @rtype: dns.ends.Option instance"""
138
139 cls = get_option_class(otype)
140 return cls.from_wire(otype, wire, current, olen)
141