| 1 |
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license |
| 2 |
|
| 3 |
import base64 |
| 4 |
import enum |
| 5 |
import struct |
| 6 |
from typing import Any, Dict |
| 7 |
|
| 8 |
import dns.enum |
| 9 |
import dns.exception |
| 10 |
import dns.immutable |
| 11 |
import dns.ipv4 |
| 12 |
import dns.ipv6 |
| 13 |
import dns.name |
| 14 |
import dns.rdata |
| 15 |
import dns.rdtypes.util |
| 16 |
import dns.renderer |
| 17 |
import dns.tokenizer |
| 18 |
import dns.wire |
| 19 |
|
| 20 |
# Until there is an RFC, this module is experimental and may be changed in |
| 21 |
# incompatible ways. |
| 22 |
|
| 23 |
|
| 24 |
class UnknownParamKey(dns.exception.DNSException): |
| 25 |
"""Unknown SVCB ParamKey""" |
| 26 |
|
| 27 |
|
| 28 |
class ParamKey(dns.enum.IntEnum): |
| 29 |
"""SVCB ParamKey""" |
| 30 |
|
| 31 |
MANDATORY = 0 |
| 32 |
ALPN = 1 |
| 33 |
NO_DEFAULT_ALPN = 2 |
| 34 |
PORT = 3 |
| 35 |
IPV4HINT = 4 |
| 36 |
ECH = 5 |
| 37 |
IPV6HINT = 6 |
| 38 |
DOHPATH = 7 |
| 39 |
OHTTP = 8 |
| 40 |
|
| 41 |
@classmethod |
| 42 |
def _maximum(cls): |
| 43 |
return 65535 |
| 44 |
|
| 45 |
@classmethod |
| 46 |
def _short_name(cls): |
| 47 |
return "SVCBParamKey" |
| 48 |
|
| 49 |
@classmethod |
| 50 |
def _prefix(cls): |
| 51 |
return "KEY" |
| 52 |
|
| 53 |
@classmethod |
| 54 |
def _unknown_exception_class(cls): |
| 55 |
return UnknownParamKey |
| 56 |
|
| 57 |
|
| 58 |
class Emptiness(enum.IntEnum): |
| 59 |
NEVER = 0 |
| 60 |
ALWAYS = 1 |
| 61 |
ALLOWED = 2 |
| 62 |
|
| 63 |
|
| 64 |
def _validate_key(key): |
| 65 |
force_generic = False |
| 66 |
if isinstance(key, bytes): |
| 67 |
# We decode to latin-1 so we get 0-255 as valid and do NOT interpret |
| 68 |
# UTF-8 sequences |
| 69 |
key = key.decode("latin-1") |
| 70 |
if isinstance(key, str): |
| 71 |
if key.lower().startswith("key"): |
| 72 |
force_generic = True |
| 73 |
if key[3:].startswith("0") and len(key) != 4: |
| 74 |
# key has leading zeros |
| 75 |
raise ValueError("leading zeros in key") |
| 76 |
key = key.replace("-", "_") |
| 77 |
return (ParamKey.make(key), force_generic) |
| 78 |
|
| 79 |
|
| 80 |
def key_to_text(key): |
| 81 |
return ParamKey.to_text(key).replace("_", "-").lower() |
| 82 |
|
| 83 |
|
| 84 |
# Like rdata escapify, but escapes ',' too. |
| 85 |
|
| 86 |
_escaped = b'",\\' |
| 87 |
|
| 88 |
|
| 89 |
def _escapify(qstring): |
| 90 |
text = "" |
| 91 |
for c in qstring: |
| 92 |
if c in _escaped: |
| 93 |
text += "\\" + chr(c) |
| 94 |
elif c >= 0x20 and c < 0x7F: |
| 95 |
text += chr(c) |
| 96 |
else: |
| 97 |
text += f"\\{c:03d}" |
| 98 |
return text |
| 99 |
|
| 100 |
|
| 101 |
def _unescape(value: str) -> bytes: |
| 102 |
if value == "": |
| 103 |
return b"" |
| 104 |
unescaped = b"" |
| 105 |
l = len(value) |
| 106 |
i = 0 |
| 107 |
while i < l: |
| 108 |
c = value[i] |
| 109 |
i += 1 |
| 110 |
if c == "\\": |
| 111 |
if i >= l: # pragma: no cover (can't happen via tokenizer get()) |
| 112 |
raise dns.exception.UnexpectedEnd |
| 113 |
c = value[i] |
| 114 |
i += 1 |
| 115 |
if c.isdigit(): |
| 116 |
if i >= l: |
| 117 |
raise dns.exception.UnexpectedEnd |
| 118 |
c2 = value[i] |
| 119 |
i += 1 |
| 120 |
if i >= l: |
| 121 |
raise dns.exception.UnexpectedEnd |
| 122 |
c3 = value[i] |
| 123 |
i += 1 |
| 124 |
if not (c2.isdigit() and c3.isdigit()): |
| 125 |
raise dns.exception.SyntaxError |
| 126 |
codepoint = int(c) * 100 + int(c2) * 10 + int(c3) |
| 127 |
if codepoint > 255: |
| 128 |
raise dns.exception.SyntaxError |
| 129 |
unescaped += b"%c" % (codepoint) |
| 130 |
continue |
| 131 |
unescaped += c.encode() |
| 132 |
return unescaped |
| 133 |
|
| 134 |
|
| 135 |
def _split(value): |
| 136 |
l = len(value) |
| 137 |
i = 0 |
| 138 |
items = [] |
| 139 |
unescaped = b"" |
| 140 |
while i < l: |
| 141 |
c = value[i] |
| 142 |
i += 1 |
| 143 |
if c == ord("\\"): |
| 144 |
if i >= l: # pragma: no cover (can't happen via tokenizer get()) |
| 145 |
raise dns.exception.UnexpectedEnd |
| 146 |
c = value[i] |
| 147 |
i += 1 |
| 148 |
unescaped += b"%c" % (c) |
| 149 |
elif c == ord(","): |
| 150 |
items.append(unescaped) |
| 151 |
unescaped = b"" |
| 152 |
else: |
| 153 |
unescaped += b"%c" % (c) |
| 154 |
items.append(unescaped) |
| 155 |
return items |
| 156 |
|
| 157 |
|
| 158 |
@dns.immutable.immutable |
| 159 |
class Param: |
| 160 |
"""Abstract base class for SVCB parameters""" |
| 161 |
|
| 162 |
@classmethod |
| 163 |
def emptiness(cls) -> Emptiness: |
| 164 |
return Emptiness.NEVER |
| 165 |
|
| 166 |
|
| 167 |
@dns.immutable.immutable |
| 168 |
class GenericParam(Param): |
| 169 |
"""Generic SVCB parameter""" |
| 170 |
|
| 171 |
def __init__(self, value): |
| 172 |
self.value = dns.rdata.Rdata._as_bytes(value, True) |
| 173 |
|
| 174 |
@classmethod |
| 175 |
def emptiness(cls): |
| 176 |
return Emptiness.ALLOWED |
| 177 |
|
| 178 |
@classmethod |
| 179 |
def from_value(cls, value): |
| 180 |
if value is None or len(value) == 0: |
| 181 |
return None |
| 182 |
else: |
| 183 |
return cls(_unescape(value)) |
| 184 |
|
| 185 |
def to_text(self): |
| 186 |
return '"' + dns.rdata._escapify(self.value) + '"' |
| 187 |
|
| 188 |
@classmethod |
| 189 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 190 |
value = parser.get_bytes(parser.remaining()) |
| 191 |
if len(value) == 0: |
| 192 |
return None |
| 193 |
else: |
| 194 |
return cls(value) |
| 195 |
|
| 196 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 197 |
file.write(self.value) |
| 198 |
|
| 199 |
|
| 200 |
@dns.immutable.immutable |
| 201 |
class MandatoryParam(Param): |
| 202 |
def __init__(self, keys): |
| 203 |
# check for duplicates |
| 204 |
keys = sorted([_validate_key(key)[0] for key in keys]) |
| 205 |
prior_k = None |
| 206 |
for k in keys: |
| 207 |
if k == prior_k: |
| 208 |
raise ValueError(f"duplicate key {k:d}") |
| 209 |
prior_k = k |
| 210 |
if k == ParamKey.MANDATORY: |
| 211 |
raise ValueError("listed the mandatory key as mandatory") |
| 212 |
self.keys = tuple(keys) |
| 213 |
|
| 214 |
@classmethod |
| 215 |
def from_value(cls, value): |
| 216 |
keys = [k.encode() for k in value.split(",")] |
| 217 |
return cls(keys) |
| 218 |
|
| 219 |
def to_text(self): |
| 220 |
return '"' + ",".join([key_to_text(key) for key in self.keys]) + '"' |
| 221 |
|
| 222 |
@classmethod |
| 223 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 224 |
keys = [] |
| 225 |
last_key = -1 |
| 226 |
while parser.remaining() > 0: |
| 227 |
key = parser.get_uint16() |
| 228 |
if key < last_key: |
| 229 |
raise dns.exception.FormError("manadatory keys not ascending") |
| 230 |
last_key = key |
| 231 |
keys.append(key) |
| 232 |
return cls(keys) |
| 233 |
|
| 234 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 235 |
for key in self.keys: |
| 236 |
file.write(struct.pack("!H", key)) |
| 237 |
|
| 238 |
|
| 239 |
@dns.immutable.immutable |
| 240 |
class ALPNParam(Param): |
| 241 |
def __init__(self, ids): |
| 242 |
self.ids = dns.rdata.Rdata._as_tuple( |
| 243 |
ids, lambda x: dns.rdata.Rdata._as_bytes(x, True, 255, False) |
| 244 |
) |
| 245 |
|
| 246 |
@classmethod |
| 247 |
def from_value(cls, value): |
| 248 |
return cls(_split(_unescape(value))) |
| 249 |
|
| 250 |
def to_text(self): |
| 251 |
value = ",".join([_escapify(id) for id in self.ids]) |
| 252 |
return '"' + dns.rdata._escapify(value.encode()) + '"' |
| 253 |
|
| 254 |
@classmethod |
| 255 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 256 |
ids = [] |
| 257 |
while parser.remaining() > 0: |
| 258 |
id = parser.get_counted_bytes() |
| 259 |
ids.append(id) |
| 260 |
return cls(ids) |
| 261 |
|
| 262 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 263 |
for id in self.ids: |
| 264 |
file.write(struct.pack("!B", len(id))) |
| 265 |
file.write(id) |
| 266 |
|
| 267 |
|
| 268 |
@dns.immutable.immutable |
| 269 |
class NoDefaultALPNParam(Param): |
| 270 |
# We don't ever expect to instantiate this class, but we need |
| 271 |
# a from_value() and a from_wire_parser(), so we just return None |
| 272 |
# from the class methods when things are OK. |
| 273 |
|
| 274 |
@classmethod |
| 275 |
def emptiness(cls): |
| 276 |
return Emptiness.ALWAYS |
| 277 |
|
| 278 |
@classmethod |
| 279 |
def from_value(cls, value): |
| 280 |
if value is None or value == "": |
| 281 |
return None |
| 282 |
else: |
| 283 |
raise ValueError("no-default-alpn with non-empty value") |
| 284 |
|
| 285 |
def to_text(self): |
| 286 |
raise NotImplementedError # pragma: no cover |
| 287 |
|
| 288 |
@classmethod |
| 289 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 290 |
if parser.remaining() != 0: |
| 291 |
raise dns.exception.FormError |
| 292 |
return None |
| 293 |
|
| 294 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 295 |
raise NotImplementedError # pragma: no cover |
| 296 |
|
| 297 |
|
| 298 |
@dns.immutable.immutable |
| 299 |
class PortParam(Param): |
| 300 |
def __init__(self, port): |
| 301 |
self.port = dns.rdata.Rdata._as_uint16(port) |
| 302 |
|
| 303 |
@classmethod |
| 304 |
def from_value(cls, value): |
| 305 |
value = int(value) |
| 306 |
return cls(value) |
| 307 |
|
| 308 |
def to_text(self): |
| 309 |
return f'"{self.port}"' |
| 310 |
|
| 311 |
@classmethod |
| 312 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 313 |
port = parser.get_uint16() |
| 314 |
return cls(port) |
| 315 |
|
| 316 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 317 |
file.write(struct.pack("!H", self.port)) |
| 318 |
|
| 319 |
|
| 320 |
@dns.immutable.immutable |
| 321 |
class IPv4HintParam(Param): |
| 322 |
def __init__(self, addresses): |
| 323 |
self.addresses = dns.rdata.Rdata._as_tuple( |
| 324 |
addresses, dns.rdata.Rdata._as_ipv4_address |
| 325 |
) |
| 326 |
|
| 327 |
@classmethod |
| 328 |
def from_value(cls, value): |
| 329 |
addresses = value.split(",") |
| 330 |
return cls(addresses) |
| 331 |
|
| 332 |
def to_text(self): |
| 333 |
return '"' + ",".join(self.addresses) + '"' |
| 334 |
|
| 335 |
@classmethod |
| 336 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 337 |
addresses = [] |
| 338 |
while parser.remaining() > 0: |
| 339 |
ip = parser.get_bytes(4) |
| 340 |
addresses.append(dns.ipv4.inet_ntoa(ip)) |
| 341 |
return cls(addresses) |
| 342 |
|
| 343 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 344 |
for address in self.addresses: |
| 345 |
file.write(dns.ipv4.inet_aton(address)) |
| 346 |
|
| 347 |
|
| 348 |
@dns.immutable.immutable |
| 349 |
class IPv6HintParam(Param): |
| 350 |
def __init__(self, addresses): |
| 351 |
self.addresses = dns.rdata.Rdata._as_tuple( |
| 352 |
addresses, dns.rdata.Rdata._as_ipv6_address |
| 353 |
) |
| 354 |
|
| 355 |
@classmethod |
| 356 |
def from_value(cls, value): |
| 357 |
addresses = value.split(",") |
| 358 |
return cls(addresses) |
| 359 |
|
| 360 |
def to_text(self): |
| 361 |
return '"' + ",".join(self.addresses) + '"' |
| 362 |
|
| 363 |
@classmethod |
| 364 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 365 |
addresses = [] |
| 366 |
while parser.remaining() > 0: |
| 367 |
ip = parser.get_bytes(16) |
| 368 |
addresses.append(dns.ipv6.inet_ntoa(ip)) |
| 369 |
return cls(addresses) |
| 370 |
|
| 371 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 372 |
for address in self.addresses: |
| 373 |
file.write(dns.ipv6.inet_aton(address)) |
| 374 |
|
| 375 |
|
| 376 |
@dns.immutable.immutable |
| 377 |
class ECHParam(Param): |
| 378 |
def __init__(self, ech): |
| 379 |
self.ech = dns.rdata.Rdata._as_bytes(ech, True) |
| 380 |
|
| 381 |
@classmethod |
| 382 |
def from_value(cls, value): |
| 383 |
if "\\" in value: |
| 384 |
raise ValueError("escape in ECH value") |
| 385 |
value = base64.b64decode(value.encode()) |
| 386 |
return cls(value) |
| 387 |
|
| 388 |
def to_text(self): |
| 389 |
b64 = base64.b64encode(self.ech).decode("ascii") |
| 390 |
return f'"{b64}"' |
| 391 |
|
| 392 |
@classmethod |
| 393 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 394 |
value = parser.get_bytes(parser.remaining()) |
| 395 |
return cls(value) |
| 396 |
|
| 397 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 398 |
file.write(self.ech) |
| 399 |
|
| 400 |
|
| 401 |
@dns.immutable.immutable |
| 402 |
class OHTTPParam(Param): |
| 403 |
# We don't ever expect to instantiate this class, but we need |
| 404 |
# a from_value() and a from_wire_parser(), so we just return None |
| 405 |
# from the class methods when things are OK. |
| 406 |
|
| 407 |
@classmethod |
| 408 |
def emptiness(cls): |
| 409 |
return Emptiness.ALWAYS |
| 410 |
|
| 411 |
@classmethod |
| 412 |
def from_value(cls, value): |
| 413 |
if value is None or value == "": |
| 414 |
return None |
| 415 |
else: |
| 416 |
raise ValueError("ohttp with non-empty value") |
| 417 |
|
| 418 |
def to_text(self): |
| 419 |
raise NotImplementedError # pragma: no cover |
| 420 |
|
| 421 |
@classmethod |
| 422 |
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 |
| 423 |
if parser.remaining() != 0: |
| 424 |
raise dns.exception.FormError |
| 425 |
return None |
| 426 |
|
| 427 |
def to_wire(self, file, origin=None): # pylint: disable=W0613 |
| 428 |
raise NotImplementedError # pragma: no cover |
| 429 |
|
| 430 |
|
| 431 |
_class_for_key: Dict[ParamKey, Any] = { |
| 432 |
ParamKey.MANDATORY: MandatoryParam, |
| 433 |
ParamKey.ALPN: ALPNParam, |
| 434 |
ParamKey.NO_DEFAULT_ALPN: NoDefaultALPNParam, |
| 435 |
ParamKey.PORT: PortParam, |
| 436 |
ParamKey.IPV4HINT: IPv4HintParam, |
| 437 |
ParamKey.ECH: ECHParam, |
| 438 |
ParamKey.IPV6HINT: IPv6HintParam, |
| 439 |
ParamKey.OHTTP: OHTTPParam, |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
def _validate_and_define(params, key, value): |
| 444 |
(key, force_generic) = _validate_key(_unescape(key)) |
| 445 |
if key in params: |
| 446 |
raise SyntaxError(f'duplicate key "{key:d}"') |
| 447 |
cls = _class_for_key.get(key, GenericParam) |
| 448 |
emptiness = cls.emptiness() |
| 449 |
if value is None: |
| 450 |
if emptiness == Emptiness.NEVER: |
| 451 |
raise SyntaxError("value cannot be empty") |
| 452 |
value = cls.from_value(value) |
| 453 |
else: |
| 454 |
if force_generic: |
| 455 |
value = cls.from_wire_parser(dns.wire.Parser(_unescape(value))) |
| 456 |
else: |
| 457 |
value = cls.from_value(value) |
| 458 |
params[key] = value |
| 459 |
|
| 460 |
|
| 461 |
@dns.immutable.immutable |
| 462 |
class SVCBBase(dns.rdata.Rdata): |
| 463 |
"""Base class for SVCB-like records""" |
| 464 |
|
| 465 |
# see: draft-ietf-dnsop-svcb-https-11 |
| 466 |
|
| 467 |
__slots__ = ["priority", "target", "params"] |
| 468 |
|
| 469 |
def __init__(self, rdclass, rdtype, priority, target, params): |
| 470 |
super().__init__(rdclass, rdtype) |
| 471 |
self.priority = self._as_uint16(priority) |
| 472 |
self.target = self._as_name(target) |
| 473 |
for k, v in params.items(): |
| 474 |
k = ParamKey.make(k) |
| 475 |
if not isinstance(v, Param) and v is not None: |
| 476 |
raise ValueError(f"{k:d} not a Param") |
| 477 |
self.params = dns.immutable.Dict(params) |
| 478 |
# Make sure any parameter listed as mandatory is present in the |
| 479 |
# record. |
| 480 |
mandatory = params.get(ParamKey.MANDATORY) |
| 481 |
if mandatory: |
| 482 |
for key in mandatory.keys: |
| 483 |
# Note we have to say "not in" as we have None as a value |
| 484 |
# so a get() and a not None test would be wrong. |
| 485 |
if key not in params: |
| 486 |
raise ValueError(f"key {key:d} declared mandatory but not present") |
| 487 |
# The no-default-alpn parameter requires the alpn parameter. |
| 488 |
if ParamKey.NO_DEFAULT_ALPN in params: |
| 489 |
if ParamKey.ALPN not in params: |
| 490 |
raise ValueError("no-default-alpn present, but alpn missing") |
| 491 |
|
| 492 |
def to_text(self, origin=None, relativize=True, **kw): |
| 493 |
target = self.target.choose_relativity(origin, relativize) |
| 494 |
params = [] |
| 495 |
for key in sorted(self.params.keys()): |
| 496 |
value = self.params[key] |
| 497 |
if value is None: |
| 498 |
params.append(key_to_text(key)) |
| 499 |
else: |
| 500 |
kv = key_to_text(key) + "=" + value.to_text() |
| 501 |
params.append(kv) |
| 502 |
if len(params) > 0: |
| 503 |
space = " " |
| 504 |
else: |
| 505 |
space = "" |
| 506 |
return f"{self.priority} {target}{space}{' '.join(params)}" |
| 507 |
|
| 508 |
@classmethod |
| 509 |
def from_text( |
| 510 |
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None |
| 511 |
): |
| 512 |
priority = tok.get_uint16() |
| 513 |
target = tok.get_name(origin, relativize, relativize_to) |
| 514 |
if priority == 0: |
| 515 |
token = tok.get() |
| 516 |
if not token.is_eol_or_eof(): |
| 517 |
raise SyntaxError("parameters in AliasMode") |
| 518 |
tok.unget(token) |
| 519 |
params = {} |
| 520 |
while True: |
| 521 |
token = tok.get() |
| 522 |
if token.is_eol_or_eof(): |
| 523 |
tok.unget(token) |
| 524 |
break |
| 525 |
if token.ttype != dns.tokenizer.IDENTIFIER: |
| 526 |
raise SyntaxError("parameter is not an identifier") |
| 527 |
equals = token.value.find("=") |
| 528 |
if equals == len(token.value) - 1: |
| 529 |
# 'key=', so next token should be a quoted string without |
| 530 |
# any intervening whitespace. |
| 531 |
key = token.value[:-1] |
| 532 |
token = tok.get(want_leading=True) |
| 533 |
if token.ttype != dns.tokenizer.QUOTED_STRING: |
| 534 |
raise SyntaxError("whitespace after =") |
| 535 |
value = token.value |
| 536 |
elif equals > 0: |
| 537 |
# key=value |
| 538 |
key = token.value[:equals] |
| 539 |
value = token.value[equals + 1 :] |
| 540 |
elif equals == 0: |
| 541 |
# =key |
| 542 |
raise SyntaxError('parameter cannot start with "="') |
| 543 |
else: |
| 544 |
# key |
| 545 |
key = token.value |
| 546 |
value = None |
| 547 |
_validate_and_define(params, key, value) |
| 548 |
return cls(rdclass, rdtype, priority, target, params) |
| 549 |
|
| 550 |
def _to_wire(self, file, compress=None, origin=None, canonicalize=False): |
| 551 |
file.write(struct.pack("!H", self.priority)) |
| 552 |
self.target.to_wire(file, None, origin, False) |
| 553 |
for key in sorted(self.params): |
| 554 |
file.write(struct.pack("!H", key)) |
| 555 |
value = self.params[key] |
| 556 |
with dns.renderer.prefixed_length(file, 2): |
| 557 |
# Note that we're still writing a length of zero if the value is None |
| 558 |
if value is not None: |
| 559 |
value.to_wire(file, origin) |
| 560 |
|
| 561 |
@classmethod |
| 562 |
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): |
| 563 |
priority = parser.get_uint16() |
| 564 |
target = parser.get_name(origin) |
| 565 |
if priority == 0 and parser.remaining() != 0: |
| 566 |
raise dns.exception.FormError("parameters in AliasMode") |
| 567 |
params = {} |
| 568 |
prior_key = -1 |
| 569 |
while parser.remaining() > 0: |
| 570 |
key = parser.get_uint16() |
| 571 |
if key < prior_key: |
| 572 |
raise dns.exception.FormError("keys not in order") |
| 573 |
prior_key = key |
| 574 |
vlen = parser.get_uint16() |
| 575 |
pkey = ParamKey.make(key) |
| 576 |
pcls = _class_for_key.get(pkey, GenericParam) |
| 577 |
with parser.restrict_to(vlen): |
| 578 |
value = pcls.from_wire_parser(parser, origin) |
| 579 |
params[pkey] = value |
| 580 |
return cls(rdclass, rdtype, priority, target, params) |
| 581 |
|
| 582 |
def _processing_priority(self): |
| 583 |
return self.priority |
| 584 |
|
| 585 |
@classmethod |
| 586 |
def _processing_order(cls, iterable): |
| 587 |
return dns.rdtypes.util.priority_processing_order(iterable) |