-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrr.js
More file actions
643 lines (534 loc) · 19.5 KB
/
Copy pathrr.js
File metadata and controls
643 lines (534 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
import * as TINYDNS from './lib/tinydns.js'
const customInspect = Symbol.for('nodejs.util.inspect.custom')
import {
wireUnpackDomain,
wirePackDomain,
getWireRdata as wireGetRdata,
toWire as wireToWire,
fromWireBytes,
fromWireGeneric,
} from './lib/wire.js'
import {
parseBindLine as bindParseLine,
fromBind as bindFromGeneric,
fromBind3597 as bindFrom3597,
toBind as bindToGeneric,
} from './lib/bind.js'
export default class RR {
static CLASSES = { IN: 1, CS: 2, CH: 3, HS: 4, NONE: 254, ANY: 255 }
static typeId
static RFCs = []
static tags = []
constructor(opts) {
if (opts === null) return
if (opts?.default) this.default = opts.default
// tinydns specific
this.setLocation(opts?.location)
this.setTimestamp(opts?.timestamp)
this.setOwner(opts?.owner)
this.setType(opts?.type)
this.setTtl(opts?.ttl)
this.setClass(opts?.class)
for (const entry of this.constructor.rdataFields ?? []) {
const f = RR.fieldName(entry)
const fieldType = Array.isArray(entry) ? entry[1] : null
const fnName = `set${this.ucFirst(f)}`
if (typeof this[fnName] === 'function') {
this[fnName](opts?.[f])
} else if (fieldType) {
this.setTypedValue(fieldType, f, opts?.[f])
} else {
this.set(f, opts?.[f])
}
}
if (opts?.comment) this.set('comment', opts.comment)
}
static fromBind(line, opts = {}) {
const instance = new this(null)
if (opts.default !== undefined) instance.default = opts.default
const parsed = this.parseBindLine(line)
if (!parsed) return null
if (parsed.rdata?.[0] === '\\#') return bindFrom3597(instance, parsed) // RFC 3597 §5
return instance.fromBind({ ...opts, ...parsed, bindline: line })
}
fromBind(opts) {
return bindFromGeneric(this, opts)
}
static parseBindLine(line) {
return bindParseLine(line, RR.CLASSES)
}
static fromTinydns(line, opts = {}) {
const instance = new this(null)
if (opts.default !== undefined) instance.default = opts.default
return instance.fromTinydns({ ...opts, tinyline: line })
}
fromTinydns(opts) {
return TINYDNS.fromGeneric(this, opts)
}
static fromWire(wireBytes) {
return fromWireBytes(this, wireBytes, wireUnpackDomain)
}
fromWire(opts) {
return fromWireGeneric(this, opts)
}
static #reserved = ['__proto__', 'constructor', 'prototype']
get(key) {
if (RR.#reserved.includes(key)) throw new Error(`Invalid field name: ${key}`)
return this[key]
}
set(key, value) {
if (RR.#reserved.includes(key)) throw new Error(`Invalid field name: ${key}`)
this[key] = value
return this
}
toJSON() {
const fields = [...this.getFields(), 'location', 'timestamp', 'comment']
const obj = {}
for (const f of fields) {
const v = this.get(f)
if (v !== undefined) obj[f] = v
}
return obj
}
[customInspect](depth, options, nextInspect) {
// Returns a formatted string that looks like: A { ... }
return `${this.type} ${nextInspect(this.toJSON(), options)}`
}
ucFirst(str) {
if (!str) return str
return str
.split(/\s/)
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
.join('')
}
setClass(c) {
if ([undefined, null, ''].includes(c)) {
this.set('class', 'IN')
return
}
if (RR.CLASSES[c.toUpperCase()]) {
this.set('class', c.toUpperCase())
return
}
const generic = c.toUpperCase().match(/^CLASS(\d+)$/) // RFC 3597 §5
if (generic && parseInt(generic[1], 10) <= 65535) {
const id = parseInt(generic[1], 10)
const known = Object.keys(RR.CLASSES).find((k) => RR.CLASSES[k] === id)
this.set('class', known ?? `CLASS${id}`)
return
}
this.throwHelp(`invalid class ${c}`)
}
setLocation(l) {
switch (l) {
case undefined:
return
default:
this.set('location', l)
}
}
setTimestamp(l) {
switch (l) {
case undefined:
return
default:
this.set('timestamp', l)
}
}
setOwner(n) {
if (n === undefined) this.throwHelp(`owner is required`)
if (n.length < 1 || n.length > 255)
this.throwHelp('Domain names must have 1-255 octets (characters): RFC 2181')
this.isFullyQualified(this.constructor.typeName ?? this.constructor.name, 'owner', n)
this.hasValidLabels(n)
// wildcard records: RFC 1034, 4592
if (/\*/.test(n)) {
if (!/^\*\./.test(n) && !/\.\*\./.test(n))
this.throwHelp('only *.something or * (by itself) is a valid wildcard')
}
this.set('owner', n.toLowerCase())
}
setTtl(t) {
t = t ?? this.default?.ttl
if (t === undefined) {
if (['SOA', 'SSHFP', 'RRSIG'].includes(this.get('type'))) return
this.throwHelp('TTL is required, no default available')
}
if (typeof t !== 'number') this.throwHelp(`TTL must be numeric (${typeof t})`)
// RFC 1035, 2181
this.is32bitInt(this.get('type'), 'TTL', t)
this.set('ttl', t)
}
setType(t) {
if ([undefined, ''].includes(t)) t = this.constructor.typeName
if (t === undefined) this.throwHelp(`type is required`)
if (t.toUpperCase() !== this.constructor.typeName)
this.throwHelp(`type ${t} doesn't match ${this.constructor.typeName}`)
this.set('type', t.toUpperCase())
}
throwHelp(e) {
if (!this.constructor.typeName) throw new Error(e)
const typeName = this.constructor.typeName
const example = this.getCanonical
? `Example ${typeName}:\n${JSON.stringify(this.getCanonical(), null, '\t')}\n\n`
: `${typeName} records have the fields: ${this.getFields().join(', ')}\n\n`
throw new Error(`${e}\n\n${example}${this.citeRFC()}\n`)
}
citeRFC() {
return `see RFC${this.getRFCs().length > 1 ? 's' : ''} ${this.getRFCs()}`
}
fullyQualify(hostname, origin) {
if (!hostname) return hostname
if (hostname === '@' && origin) hostname = origin
if (hostname.endsWith('.')) return hostname.toLowerCase()
if (origin) return `${hostname}.${origin}`.toLowerCase()
return `${hostname}.`
}
getPrefix(zone_opts = {}) {
const classVal = zone_opts.hide?.class ? '' : this.get('class')
let rrTTL = this.get('ttl')
if (zone_opts.hide?.ttl && rrTTL === zone_opts.ttl) rrTTL = ''
let owner = this.get('owner')
if (zone_opts.hide?.sameOwner && zone_opts.previousOwner === owner) {
owner = ''
} else {
owner = this.getFQDN('owner', zone_opts)
}
return `${owner}\t${rrTTL}\t${classVal}\t${this.get('type')}`
}
getEmpty(prop) {
return this.get(prop) ?? ''
}
getComment(prop) {
const c = this.get('comment')
if (!c || !c[prop]) return ''
return c[prop]
}
getQuoted(prop) {
// if prop is not a quoted string field, return bare
if (!this.isQuotedField(prop)) return this.get(prop)
// if it's already quoted, return as-is
if (/['"]/.test(this.get(prop)[0])) return this.get(prop)
return `"${this.get(prop)}"` // add double quotes
}
static fieldName(entry) {
return Array.isArray(entry) ? entry[0] : entry
}
static fieldType(entry) {
return Array.isArray(entry) ? entry[1] : null
}
getRdataFields() {
return (this.constructor.rdataFields ?? []).map((e) => RR.fieldName(e))
}
getTags() {
return this.constructor.tags ?? []
}
getRFCs() {
return this.constructor.RFCs ?? []
}
getTypeId() {
const typeId = this.constructor.typeId
if (typeId === undefined) this.throwHelp(`${this.constructor.typeName}: missing static typeId`)
return typeId
}
static getTypeId() {
return this.typeId
}
getClassId() {
const c = this.get('class')
return RR.CLASSES[c] ?? parseInt(c.slice(5), 10) // 'CLASS32' -> 32
}
getFields(arg) {
const commonFields = ['owner', 'ttl', 'class', 'type']
Object.freeze(commonFields)
const rdataFields = this.getRdataFields()
switch (arg) {
case 'common':
return commonFields
case 'rdata':
return rdataFields
default:
return commonFields.concat(rdataFields)
}
}
getFQDN(field, zone_opts = {}) {
let fqdn = this.get(field)
if (!fqdn) this.throwHelp(`empty value for field ${field}`)
if (!fqdn.endsWith('.')) fqdn += '.'
if (zone_opts.hide?.origin && zone_opts.origin) {
if (fqdn === zone_opts.origin) return '@'
if (fqdn.endsWith(zone_opts.origin)) return fqdn.slice(0, fqdn.length - zone_opts.origin.length - 1)
}
return fqdn
}
getTinyFQDN(field) {
const val = this.get(field)
if (val === '') return val // empty
if (val === '.') return val // null MX
// strip off trailing ., tinydns doesn't require it for FQDN
if (val.endsWith('.')) return val.slice(0, -1)
return val
}
getTinydnsGeneric(rdata) {
return `:${this.getTinyFQDN('owner')}:${this.getTypeId()}:${rdata}:${this.getTinydnsPostamble()}\n`
}
getTinydnsPostamble() {
// every tinydns line ends with this, making it the choke point for the
// class guard: tinydns data files have no class field
this.assertClassIN('tinydns')
return ['ttl', 'timestamp', 'location'].map((f) => this.getEmpty(f)).join(':')
}
assertClassIN(format) {
if (this.get('class') !== 'IN')
this.throwHelp(`${format} supports only class IN, got ${this.get('class')}`)
}
hasValidLabels(hostname) {
// RFC 952 defined valid hostnames
// RFC 1035 limited domain label chars to letters, digits, and hyphen
// RFC 1123 allowed hostnames to start with a digit
// RFC 2181 'any binary string can be used as the label'
const fq = hostname.endsWith('.') ? hostname.slice(0, -1) : hostname
for (const label of fq.split('.')) {
if (label.length < 1 || label.length > 63)
this.throwHelp('Labels must have 1-63 octets (characters), RFC 2181')
}
}
is8bitInt(type, field, value) {
if (Number.isInteger(value) && value >= 0 && value <= 255) return true
this.throwHelp(`${type} ${field} must be a 8-bit integer (in the range 0-255)`)
}
is16bitInt(type, field, value) {
if (Number.isInteger(value) && value >= 0 && value <= 65535) return true
this.throwHelp(`${type} ${field} must be a 16-bit integer (in the range 0-65535)`)
}
is32bitInt(type, field, value) {
if (Number.isInteger(value) && value >= 0 && value <= 4294967295) return true
this.throwHelp(`${type} ${field} must be a 32-bit integer (in the range 0-4294967295)`)
}
isBase64(type, field, value) {
if (
typeof value === 'string' &&
value.length > 0 &&
value.length % 4 === 0 &&
/^[A-Za-z0-9+/]*={0,2}$/.test(value)
)
return true
this.throwHelp(`${type} ${field} must be a valid base64 string`)
}
isQuoted(val) {
return /^["']/.test(val) && /["']$/.test(val)
}
setFqdnValue(typeName, fieldName, val) {
if (!val) this.throwHelp(`${typeName}: ${fieldName} is required`)
if (this.isIPv4(val) || this.isIPv6(val))
this.throwHelp(`${typeName}: ${fieldName} must be a domain name`)
this.isFullyQualified(typeName, fieldName, val)
this.isValidHostname(typeName, fieldName, val)
this.set(fieldName, val.toLowerCase())
}
setTypedValue(type, fieldName, val) {
const typeName = this.constructor.typeName
switch (type) {
case 'u8':
this.is8bitInt(typeName, fieldName, val)
this.set(fieldName, parseInt(val, 10))
break
case 'u16':
this.is16bitInt(typeName, fieldName, val)
this.set(fieldName, parseInt(val, 10))
break
case 'certtype': {
if (val === undefined || val === null || val === '')
this.throwHelp(`${typeName}: ${fieldName} is required`)
if (typeof val === 'string' && !/^[0-9]+$/.test(val)) {
const certTypes = this.constructor.CERT_TYPES
if (!certTypes || !Object.hasOwn(certTypes, val)) {
this.throwHelp(`${typeName}: unknown cert type mnemonic: ${val}`)
}
this.set(fieldName, val)
break
}
this.is16bitInt(typeName, fieldName, val)
this.set(fieldName, parseInt(val, 10))
break
}
case 'u32':
this.is32bitInt(typeName, fieldName, val)
this.set(fieldName, parseInt(val, 10))
break
case 'fqdn':
this.setFqdnValue(typeName, fieldName, val)
break
case 'base64':
this.isBase64(typeName, fieldName, val)
this.set(fieldName, val)
break
case 'hex':
if (!/^[0-9a-fA-F]*$/.test(val)) this.throwHelp(`${typeName}: ${fieldName} must be hexadecimal`)
this.set(fieldName, val)
break
case 'str':
if (!val) this.throwHelp(`${typeName}: ${fieldName} is required`)
this.set(fieldName, val)
break
case 'qstr':
if (val === undefined || val === null) this.throwHelp(`${typeName}: ${fieldName} is required`)
this.set(fieldName, val)
break
case 'charstr': {
if (val === undefined || val === null) this.throwHelp(`${typeName}: ${fieldName} is required`)
const value = String(val)
const byteLen = new TextEncoder().encode(value).length
if (byteLen > 255) this.throwHelp(`${typeName}: ${fieldName} must be <=255 bytes`)
this.set(fieldName, value)
break
}
case 'qcharstr': {
if (val === undefined || val === null) this.throwHelp(`${typeName}: ${fieldName} is required`)
const value = String(val)
const byteLen = new TextEncoder().encode(value).length
if (byteLen > 255) this.throwHelp(`${typeName}: ${fieldName} must be <=255 bytes`)
this.set(fieldName, value)
break
}
case 'charstrs':
if (val === undefined || val === null) this.throwHelp(`${typeName}: ${fieldName} is required`)
this.set(fieldName, val)
break
case 'svcparams':
if (val === undefined || val === null) this.throwHelp(`${typeName}: ${fieldName} is required`)
this.set(fieldName, val)
break
case 'ipv4':
if (!this.isIPv4(val)) this.throwHelp(`${typeName}: ${fieldName} must be a valid IPv4 address`)
this.set(fieldName, val)
break
case 'ipv6':
if (!this.isIPv6(val)) this.throwHelp(`${typeName}: ${fieldName} must be a valid IPv6 address`)
this.set(fieldName, this.expandIPv6(val.toLowerCase())) // lower case: RFC 5952
break
}
}
isFullyQualified(type, field, hostname) {
if (hostname.endsWith('.')) return true
this.throwHelp(`${type}: ${field} must be fully qualified`)
}
isValidHostname(type, field, hostname) {
const allowed = new RegExp(/[^a-zA-Z0-9\-._/\\]/)
if (!allowed.test(hostname)) return true
const matches = allowed.exec(hostname)
this.throwHelp(`${type}, ${field} has invalid hostname character (${matches[0]})`)
}
isIPv4(string) {
// https://stackoverflow.com/questions/5284147/validating-ipv4-addresses-with-regexp
return /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/.test(string)
}
isIPv6(string) {
return /^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(?::[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(?::[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(?::[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(?::[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/gm.test(
string,
)
}
expandIPv6(val, delimiter) {
return TINYDNS.expandIPv6(val, delimiter)
}
compressIPv6(val) {
// * RFC 5952
// * 4.1. Leading zeros MUST be suppressed...A single 16-bit 0000 field MUST be represented as 0.
// * 4.2.1 The use of the symbol "::" MUST be used to its maximum capability.
// * 4.2.2 The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field.
// * 4.2.3 When choosing placement of a "::", the longest run...MUST be shortened
// * 4.3 The characters a-f in an IPv6 address MUST be represented in lowercase.
// 4.3 Lowercase and 4.1 remove leading zeros per segment
const segments = val
.toLowerCase()
.split(':')
.map((s) => s.replace(/^0+/, '') || '0')
let bestStart = -1
let bestLen = 0
let curStart = -1
let curLen = 0
// 4.2.1 & 4.2.3 Find the longest consecutive run of '0'
for (let i = 0; i < segments.length; i++) {
if (segments[i] === '0') {
if (curStart === -1) curStart = i
curLen++
if (curLen > bestLen) {
bestLen = curLen
bestStart = curStart
}
} else {
curStart = -1
curLen = 0
}
}
// 4.2.2 Don't shorten a single 16-bit 0 field
if (bestLen < 2) {
return segments.join(':')
}
const head = segments.slice(0, bestStart).join(':')
const tail = segments.slice(bestStart + bestLen).join(':')
return `${head}::${tail}`
}
octalToUint8Array(octalStr) {
const str = TINYDNS.octalToChar(octalStr)
return Uint8Array.from(str, (c) => c.charCodeAt(0))
}
wireUnpackDomain(bytes, offset = 0) {
return wireUnpackDomain(bytes, offset)
}
wirePackDomain(fqdn) {
return wirePackDomain(fqdn)
}
getWireRdata() {
return wireGetRdata(this)
}
toWire() {
return wireToWire(this)
}
toBind(zone_opts) {
return bindToGeneric(this, zone_opts)
}
parseTinydnsLine(tinyline) {
const parsed = TINYDNS.parseGenericLine(tinyline)
return { ...parsed, owner: this.fullyQualify(parsed.owner) }
}
toTinydns() {
return TINYDNS.to(this)
}
isFqdnField(field) {
return (
(this.constructor.rdataFields ?? []).some(
(entry) => RR.fieldName(entry) === field && RR.fieldType(entry) === 'fqdn',
) || false
)
}
isQuotedField(field) {
const quotedTypes = new Set(['qstr', 'qcharstr', 'charstrs'])
return (
(this.constructor.rdataFields ?? []).some(
(entry) => RR.fieldName(entry) === field && quotedTypes.has(RR.fieldType(entry)),
) || false
)
}
toMaraDNS() {
// MaraDNS csv2 zone files have no class field either
this.assertClassIN('MaraDNS')
const type = this.get('type')
const supportedTypes = 'A PTR MX AAAA SRV NAPTR NS SOA TXT SPF RAW FQDN4 FQDN6 CNAME HINFO WKS LOC'.split(
/\s+/g,
)
if (!supportedTypes.includes(type)) return this.toMaraGeneric()
return `${this.get('owner')}\t+${this.get('ttl')}\t${type}\t${this.getFields('rdata')
.map((f) => this.getQuoted(f))
.join('\t')} ~\n`
}
toMaraGeneric() {
// MaraDNS csv2 interprets \xNN escapes only outside quoted text, so every
// rdata byte is emitted as an unquoted escape. '' is zero-length rdata.
const bytes = this.getWireRdata()
const rdata = bytes.length
? [...bytes].map((b) => `\\x${b.toString(16).padStart(2, '0')}`).join('')
: `''`
return `${this.get('owner')}\t+${this.get('ttl')}\tRAW ${this.getTypeId()}\t${rdata} ~\n`
}
}