]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
constructor checking for EDNS options
authorBob Halley <halley@dnspython.org>
Tue, 25 Aug 2020 13:49:55 +0000 (06:49 -0700)
committerBob Halley <halley@dnspython.org>
Tue, 25 Aug 2020 13:49:55 +0000 (06:49 -0700)
dns/edns.py

index 199e8c48638304060342ff09d4c2edc971ec7c24..237178f24985c66dce4d803b2a636b3e907da163 100644 (file)
@@ -23,6 +23,8 @@ import struct
 
 import dns.enum
 import dns.inet
+import dns.rdata
+
 
 class OptionType(dns.enum.IntEnum):
     #: NSID
@@ -60,7 +62,7 @@ class Option:
 
         *otype*, an ``int``, is the option type.
         """
-        self.otype = otype
+        self.otype = OptionType.make(otype)
 
     def to_wire(self, file=None):
         """Convert an option to wire format.
@@ -148,7 +150,7 @@ class GenericOption(Option):
 
     def __init__(self, otype, data):
         super().__init__(otype)
-        self.data = data
+        self.data = dns.rdata.Rdata._as_bytes(data, True)
 
     def to_wire(self, file=None):
         if file:
@@ -185,10 +187,16 @@ class ECSOption(Option):
             self.family = 2
             if srclen is None:
                 srclen = 56
+            address = dns.rdata.Rdata._as_ipv6_address(address)
+            srclen = dns.rdata.Rdata._as_int(srclen, 0, 128)
+            scopelen = dns.rdata.Rdata._as_int(scopelen, 0, 128)
         elif af == socket.AF_INET:
             self.family = 1
             if srclen is None:
                 srclen = 24
+            address = dns.rdata.Rdata._as_ipv4_address(address)
+            srclen = dns.rdata.Rdata._as_int(srclen, 0, 32)
+            scopelen = dns.rdata.Rdata._as_int(scopelen, 0, 32)
         else:  # pragma: no cover   (this will never happen)
             raise ValueError('Bad address family')