1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """EDNS Options"""
17
18 NSID = 3
22
23 """Base class for all EDNS option types.
24 """
25
27 """Initialize an option.
28 @param otype: The rdata type
29 @type otype: int
30 """
31 self.otype = otype
32
34 """Convert an option to wire format.
35 """
36 raise NotImplementedError
37
38 @classmethod
39 - def from_wire(cls, otype, wire, current, olen):
40 """Build an EDNS option object from wire format
41
42 @param otype: The option type
43 @type otype: int
44 @param wire: The wire-format message
45 @type wire: string
46 @param current: The offset in wire of the beginning of the rdata.
47 @type current: int
48 @param olen: The length of the wire-format option data
49 @type olen: int
50 @rtype: dns.edns.Option instance"""
51 raise NotImplementedError
52
53 - def _cmp(self, other):
54 """Compare an EDNS option with another option of the same type.
55 Return < 0 if self < other, 0 if self == other,
56 and > 0 if self > other.
57 """
58 raise NotImplementedError
59
61 if not isinstance(other, Option):
62 return False
63 if self.otype != other.otype:
64 return False
65 return self._cmp(other) == 0
66
68 if not isinstance(other, Option):
69 return False
70 if self.otype != other.otype:
71 return False
72 return self._cmp(other) != 0
73
75 if not isinstance(other, Option) or \
76 self.otype != other.otype:
77 return NotImplemented
78 return self._cmp(other) < 0
79
81 if not isinstance(other, Option) or \
82 self.otype != other.otype:
83 return NotImplemented
84 return self._cmp(other) <= 0
85
87 if not isinstance(other, Option) or \
88 self.otype != other.otype:
89 return NotImplemented
90 return self._cmp(other) >= 0
91
93 if not isinstance(other, Option) or \
94 self.otype != other.otype:
95 return NotImplemented
96 return self._cmp(other) > 0
97
100
101 """Generate Rdata Class
102
103 This class is used for EDNS option types for which we have no better
104 implementation.
105 """
106
110
112 file.write(self.data)
113
114 @classmethod
115 - def from_wire(cls, otype, wire, current, olen):
116 return cls(otype, wire[current: current + olen])
117
118 - def _cmp(self, other):
119 if self.data == other.data:
120 return 0
121 if self.data > other.data:
122 return 1
123 return -1
124
125 _type_to_class = {
126 }
134
137 """Build an EDNS option object from wire format
138
139 @param otype: The option type
140 @type otype: int
141 @param wire: The wire-format message
142 @type wire: string
143 @param current: The offset in wire of the beginning of the rdata.
144 @type current: int
145 @param olen: The length of the wire-format option data
146 @type olen: int
147 @rtype: dns.edns.Option instance"""
148
149 cls = get_option_class(otype)
150 return cls.from_wire(otype, wire, current, olen)
151