Check for empty labels in the middle of a label sequence, labels that are too long, and for too many labels. Raises ``dns.name.NameTooLong`` if the name as a whole is too long. Raises ``dns.name.EmptyLabel`` if a label is empty (i.e. the root label) and appears in a position other
(labels: Tuple[bytes, ...])
| 318 | |
| 319 | |
| 320 | def _validate_labels(labels: Tuple[bytes, ...]) -> None: |
| 321 | """Check for empty labels in the middle of a label sequence, |
| 322 | labels that are too long, and for too many labels. |
| 323 | |
| 324 | Raises ``dns.name.NameTooLong`` if the name as a whole is too long. |
| 325 | |
| 326 | Raises ``dns.name.EmptyLabel`` if a label is empty (i.e. the root |
| 327 | label) and appears in a position other than the end of the label |
| 328 | sequence |
| 329 | |
| 330 | """ |
| 331 | |
| 332 | l = len(labels) |
| 333 | total = 0 |
| 334 | i = -1 |
| 335 | j = 0 |
| 336 | for label in labels: |
| 337 | ll = len(label) |
| 338 | total += ll + 1 |
| 339 | if ll > 63: |
| 340 | raise LabelTooLong |
| 341 | if i < 0 and label == b"": |
| 342 | i = j |
| 343 | j += 1 |
| 344 | if total > 255: |
| 345 | raise NameTooLong |
| 346 | if i >= 0 and i != l - 1: |
| 347 | raise EmptyLabel |
| 348 | |
| 349 | |
| 350 | def _maybe_convert_to_binary(label: bytes | str) -> bytes: |
no outgoing calls
no test coverage detected
searching dependent graphs…