]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
more strings that should be bytes
authorBob Halley <halley@nominum.com>
Tue, 3 May 2011 10:05:35 +0000 (11:05 +0100)
committerBob Halley <halley@nominum.com>
Tue, 3 May 2011 10:05:35 +0000 (11:05 +0100)
dns/message.py
dns/query.py
dns/rdtypes/ANY/DNSKEY.py
dns/renderer.py
dns/tsig.py
dns/tsigkeyring.py

index bd904fba7fa653fb0604c81235e229c53ca78dcc..a8bc3ab1d59605473c18d04f0903d65e220fc4b6 100644 (file)
@@ -111,9 +111,9 @@ class Message(object):
     @ivar tsig_error: TSIG error code; default is 0.
     @type tsig_error: int
     @ivar other_data: TSIG other data.
-    @type other_data: string
+    @type other_data: bytes
     @ivar mac: The TSIG MAC for this message.
-    @type mac: string
+    @type mac: bytes
     @ivar xfr: Is the message being used to contain the results of a DNS
     zone transfer?  The default is False.
     @type xfr: bool
@@ -158,12 +158,12 @@ class Message(object):
         self.keyring = None
         self.keyname = None
         self.keyalgorithm = dns.tsig.default_algorithm
-        self.request_mac = ''
-        self.other_data = ''
+        self.request_mac = b''
+        self.other_data = b''
         self.tsig_error = 0
         self.fudge = 300
         self.original_id = self.id
-        self.mac = ''
+        self.mac = b''
         self.xfr = False
         self.origin = None
         self.tsig_ctx = None
@@ -426,7 +426,7 @@ class Message(object):
         return r.get_wire()
 
     def use_tsig(self, keyring, keyname=None, fudge=300,
-                 original_id=None, tsig_error=0, other_data='',
+                 original_id=None, tsig_error=0, other_data=b'',
                  algorithm=dns.tsig.default_algorithm):
         """When sending, a TSIG signature using the specified keyring
         and keyname should be added.
@@ -447,7 +447,7 @@ class Message(object):
         @param tsig_error: TSIG error code; default is 0.
         @type tsig_error: int
         @param other_data: TSIG other data.
-        @type other_data: string
+        @type other_data: bytes
         @param algorithm: The TSIG algorithm to use; defaults to
         dns.tsig.default_algorithm
         """
@@ -730,7 +730,7 @@ class _WireReader(object):
             self.message.tsig_ctx.update(self.wire)
 
 
-def from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None,
+def from_wire(wire, keyring=None, request_mac=b'', xfr=False, origin=None,
               tsig_ctx = None, multi = False, first = True,
               question_only = False, one_rr_per_rrset = False):
     """Convert a DNS wire format message into a message
@@ -740,7 +740,7 @@ def from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None,
     @type keyring: dict
     @param request_mac: If the message is a response to a TSIG-signed request,
     I{request_mac} should be set to the MAC of that request.
-    @type request_mac: string
+    @type request_mac: bytes
     @param xfr: Is this message part of a zone transfer?
     @type xfr: bool
     @param origin: If the message is part of a zone transfer, I{origin}
index c41b4447ba65203c2b9b1ee35b4b886c5b9d32dc..1be34cc06965ceb65bddb1301ad2773af56749ea 100644 (file)
@@ -221,11 +221,11 @@ def _net_read(sock, count, expiration):
     A Timeout exception will be raised if the operation is not completed
     by the expiration time.
     """
-    s = ''
+    s = b''
     while count > 0:
         _wait_for_readable(sock, expiration)
         n = sock.recv(count)
-        if n == '':
+        if n == b'':
             raise EOFError
         count = count - len(n)
         s = s + n
index 336287247858d5c1a6b27285e8f153b192cf30fc..321b17452ff1ab33e9140cc61eb46e488c0a9a02 100644 (file)
@@ -49,7 +49,7 @@ class DNSKEY(dns.rdata.Rdata):
 
     def to_text(self, origin=None, relativize=True, **kw):
         return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm,
-                                dns.rdata._base64ify(self.key))
+                                dns.rdata._base64ify(self.key).decode('ascii'))
 
     @classmethod
     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
index b0a081d9410c3da392b041626b40120dfaec59d2..a66f9a55763749772e9800cc388bb3c2f2986de5 100644 (file)
@@ -47,7 +47,7 @@ class Renderer(object):
         r.add_rrset(dns.renderer.ADDTIONAL, ad_rrset_1)
         r.add_rrset(dns.renderer.ADDTIONAL, ad_rrset_2)
         r.write_header()
-        r.add_tsig(keyname, secret, 300, 1, 0, '', request_mac)
+        r.add_tsig(keyname, secret, 300, 1, 0, b'', request_mac)
         wire = r.get_wire()
 
     @ivar output: where rendering is written
@@ -68,7 +68,7 @@ class Renderer(object):
     @ivar counts: list of the number of RRs in each section
     @type counts: int list of length 4
     @ivar mac: the MAC of the rendered message (if TSIG was used)
-    @type mac: string
+    @type mac: bytes
     """
 
     def __init__(self, id=None, flags=0, max_size=65535, origin=None):
@@ -98,7 +98,7 @@ class Renderer(object):
         self.section = QUESTION
         self.counts = [0, 0, 0, 0]
         self.output.write(b'\x00' * 12)
-        self.mac = ''
+        self.mac = b''
 
     def _rollback(self, where):
         """Truncate the output buffer at offset I{where}, and remove any
@@ -267,8 +267,9 @@ class Renderer(object):
         @type other_data: string
         @param request_mac: This message is a response to the request which
         had the specified MAC.
+        @type request_mac: bytes
         @param algorithm: the TSIG algorithm to use
-        @type request_mac: string
+        @type algorithm: dns.name.Name object
         """
 
         self._set_section(ADDITIONAL)
index e1f706a6b13757778c912e3383b69120cc2e73a8..c3d0b0fbb03d9ccb01a16ffe2ecf6335de0913e7 100644 (file)
@@ -21,6 +21,7 @@ import struct
 import sys
 
 import dns.exception
+import dns.hash
 import dns.rdataclass
 import dns.name
 
@@ -74,7 +75,7 @@ def sign(wire, keyname, secret, time, fudge, original_id, error,
     """Return a (tsig_rdata, mac, ctx) tuple containing the HMAC TSIG rdata
     for the input parameters, the HMAC MAC calculated by applying the
     TSIG signature algorithm, and the TSIG digest context.
-    @rtype: (string, string, hmac.HMAC object)
+    @rtype: (bytes, bytes, hmac.HMAC object)
     @raises ValueError: I{other_data} is too long
     @raises NotImplementedError: I{algorithm} is not supported
     """
index cbd1a27bbf8faac69608ab4986e166d2bea9c111..85b62f48ea946440b99bd234c526040403568d03 100644 (file)
@@ -21,13 +21,13 @@ import dns.name
 
 def from_text(textring):
     """Convert a dictionary containing (textual DNS name, base64 secret) pairs
-    into a binary keyring which has (dns.name.Name, binary secret) pairs.
+    into a binary keyring which has (dns.name.Name, bytes) pairs.
     @rtype: dict"""
-    
+
     keyring = {}
     for keytext in textring:
         keyname = dns.name.from_text(keytext)
-        secret = base64.decodestring(textring[keytext])
+        secret = base64.decodestring(textring[keytext].encode('ascii'))
         keyring[keyname] = secret
     return keyring
 
@@ -35,7 +35,7 @@ def to_text(keyring):
     """Convert a dictionary containing (dns.name.Name, binary secret) pairs
     into a text keyring which has (textual DNS name, base64 secret) pairs.
     @rtype: dict"""
-    
+
     textring = {}
     for keyname in keyring:
         keytext = dns.name.to_text(keyname)