@nictool/dns-resource-record 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +48 -42
- package/lib/readme.js +84 -0
- package/lib/tinydns.js +10 -0
- package/package.json +2 -1
- package/rr/a.js +8 -0
- package/rr/aaaa.js +10 -2
- package/rr/caa.js +4 -0
- package/rr/cert.js +13 -0
- package/rr/cname.js +17 -0
- package/rr/dname.js +10 -0
- package/rr/dnskey.js +17 -0
- package/rr/ds.js +17 -0
- package/rr/hinfo.js +15 -0
- package/rr/https.js +16 -0
- package/rr/ipseckey.js +5 -1
- package/rr/key.js +13 -0
- package/rr/loc.js +10 -0
- package/rr/mx.js +11 -1
- package/rr/naptr.js +16 -1
- package/rr/ns.js +18 -0
- package/rr/nsec.js +15 -0
- package/rr/nsec3.js +19 -0
- package/rr/nsec3param.js +17 -0
- package/rr/nxt.js +15 -0
- package/rr/openpgpkey.js +14 -0
- package/rr/ptr.js +18 -0
- package/rr/rp.js +4 -0
- package/rr/rrsig.js +22 -0
- package/rr/sig.js +23 -1
- package/rr/smimea.js +17 -0
- package/rr/soa.js +30 -0
- package/rr/spf.js +14 -0
- package/rr/srv.js +17 -0
- package/rr/sshfp.js +16 -0
- package/rr/svcb.js +12 -0
- package/rr/tlsa.js +18 -1
- package/rr/tsig.js +16 -0
- package/rr/txt.js +36 -1
- package/rr/uri.js +12 -0
- package/rr/wks.js +16 -0
- package/rr.js +57 -0
package/rr.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as TINYDNS from './lib/tinydns.js'
|
|
2
|
+
|
|
1
3
|
export default class RR extends Map {
|
|
2
4
|
constructor(opts) {
|
|
3
5
|
super()
|
|
@@ -184,6 +186,10 @@ export default class RR extends Map {
|
|
|
184
186
|
return []
|
|
185
187
|
}
|
|
186
188
|
|
|
189
|
+
getTags() {
|
|
190
|
+
return []
|
|
191
|
+
}
|
|
192
|
+
|
|
187
193
|
getFields(arg) {
|
|
188
194
|
const commonFields = ['owner', 'ttl', 'class', 'type']
|
|
189
195
|
Object.freeze(commonFields)
|
|
@@ -352,6 +358,35 @@ export default class RR extends Map {
|
|
|
352
358
|
return `${head}::${tail}`
|
|
353
359
|
}
|
|
354
360
|
|
|
361
|
+
octalToBuffer(octalStr) {
|
|
362
|
+
return Buffer.from(TINYDNS.octalToChar(octalStr), 'binary')
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
wirePackDomain(fqdn) {
|
|
366
|
+
return packDomainNameWire(fqdn)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
getWireRdata() {
|
|
370
|
+
const line = this.toTinydns()
|
|
371
|
+
if (!line.startsWith(':'))
|
|
372
|
+
throw new Error(`${this.get('type')}: override getWireRdata() — non-generic tinydns format`)
|
|
373
|
+
// line: :fqdn:typeId:rdata:ttl:ts:loc\n
|
|
374
|
+
const rdata = line.split(':')[3]
|
|
375
|
+
return this.octalToBuffer(rdata ?? '')
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
toWire() {
|
|
379
|
+
const rdata = this.getWireRdata()
|
|
380
|
+
const owner = this.wirePackDomain(this.get('owner'))
|
|
381
|
+
const classMap = { IN: 1, CS: 2, CH: 3, HS: 4, NONE: 254, ANY: 255 }
|
|
382
|
+
const meta = Buffer.alloc(10)
|
|
383
|
+
meta.writeUInt16BE(this.getTypeId(), 0)
|
|
384
|
+
meta.writeUInt16BE(classMap[this.get('class')] ?? 1, 2)
|
|
385
|
+
meta.writeUInt32BE(this.get('ttl'), 4)
|
|
386
|
+
meta.writeUInt16BE(rdata.length, 8)
|
|
387
|
+
return Buffer.concat([owner, meta, rdata])
|
|
388
|
+
}
|
|
389
|
+
|
|
355
390
|
toBind(zone_opts) {
|
|
356
391
|
return `${this.getPrefix(zone_opts)}\t${this.getRdataFields()
|
|
357
392
|
.map((f) => this.getQuoted(f))
|
|
@@ -376,3 +411,25 @@ export default class RR extends Map {
|
|
|
376
411
|
.join(' ')}' ~\n`
|
|
377
412
|
}
|
|
378
413
|
}
|
|
414
|
+
|
|
415
|
+
function packDomainNameWire(fqdn) {
|
|
416
|
+
if (fqdn === '.') return Buffer.from([0])
|
|
417
|
+
const parts = fqdn.split('.')
|
|
418
|
+
let len = 0
|
|
419
|
+
for (const part of parts) {
|
|
420
|
+
if (part.length > 0) len += part.length + 1
|
|
421
|
+
}
|
|
422
|
+
len += 1 // for the final \0
|
|
423
|
+
|
|
424
|
+
const buf = Buffer.allocUnsafe(len)
|
|
425
|
+
let offset = 0
|
|
426
|
+
for (const part of parts) {
|
|
427
|
+
if (part.length > 0) {
|
|
428
|
+
buf.writeUInt8(part.length, offset++)
|
|
429
|
+
buf.write(part, offset, 'ascii')
|
|
430
|
+
offset += part.length
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
buf.writeUInt8(0, offset)
|
|
434
|
+
return buf
|
|
435
|
+
}
|