"""
rdata = key.to_wire()
+ assert rdata is not None # for mypy
if key.algorithm == Algorithm.RSAMD5:
return (rdata[-3] << 8) + rdata[-2]
else:
if isinstance(name, str):
name = dns.name.from_text(name, origin)
wire = name.canonicalize().to_wire()
- assert wire is not None
+ kwire = key.to_wire(origin=origin)
+ assert wire is not None and kwire is not None # for mypy
dshash.update(wire)
- dshash.update(key.to_wire(origin=origin))
+ dshash.update(kwire)
digest = dshash.digest()
dsrdata = struct.pack("!HBB", key_id(key), key.algorithm, algorithm) + digest
rrname, rdataset = _get_rrname_rdataset(rrset)
data = b""
- data += rrsig.to_wire(origin=signer)[:18]
+ wire = rrsig.to_wire(origin=signer)
+ assert wire is not None # for mypy
+ data += wire[:18]
data += rrsig.signer.to_digestable(signer)
# Derelativize the name before considering labels.
compress: Optional[dns.name.CompressType] = None,
origin: Optional[dns.name.Name] = None,
canonicalize: bool = False,
- ) -> bytes:
+ ) -> None:
raise NotImplementedError # pragma: no cover
def to_wire(
compress: Optional[dns.name.CompressType] = None,
origin: Optional[dns.name.Name] = None,
canonicalize: bool = False,
- ) -> bytes:
+ ) -> Optional[bytes]:
"""Convert an rdata to wire format.
- Returns a ``bytes`` or ``None``.
+ Returns a ``bytes`` if no output file was specified, or ``None`` otherwise.
"""
if file:
- return self._to_wire(file, compress, origin, canonicalize)
+ # We call _to_wire() and then return None explicitly instead of
+ # of just returning the None from _to_wire() as mypy's func-returns-value
+ # unhelpfully errors out with "error: "_to_wire" of "Rdata" does not return
+ # a value (it only ever returns None)"
+ self._to_wire(file, compress, origin, canonicalize)
+ return None
else:
f = io.BytesIO()
self._to_wire(f, compress, origin, canonicalize)
Returns a ``bytes``.
"""
-
- return self.to_wire(origin=origin, canonicalize=True)
+ wire = self.to_wire(origin=origin, canonicalize=True)
+ assert wire is not None # for mypy
+ return wire
def __repr__(self):
covers = self.covers()