Encodes a bytes string into the DNS format :param x: the string :param check_built: detect already-built strings and ignore them :returns: the encoded bytes string
(x, check_built=False)
| 209 | |
| 210 | |
| 211 | def dns_encode(x, check_built=False): |
| 212 | """Encodes a bytes string into the DNS format |
| 213 | |
| 214 | :param x: the string |
| 215 | :param check_built: detect already-built strings and ignore them |
| 216 | :returns: the encoded bytes string |
| 217 | """ |
| 218 | if not x or x == b".": |
| 219 | return b"\x00" |
| 220 | |
| 221 | if check_built and _is_ptr(x): |
| 222 | # The value has already been processed. Do not process it again |
| 223 | return x |
| 224 | |
| 225 | # Truncate chunks that cannot be encoded (more than 63 bytes..) |
| 226 | x = b"".join(chb(len(y)) + y for y in (k[:63] for k in x.split(b"."))) |
| 227 | if x[-1:] != b"\x00": |
| 228 | x += b"\x00" |
| 229 | return x |
| 230 | |
| 231 | |
| 232 | def DNSgetstr(*args, **kwargs): |
no test coverage detected
searching dependent graphs…