@nictool/dns-resource-record 1.5.0 → 1.6.1

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/rr/tsig.js CHANGED
@@ -25,6 +25,22 @@ export default class TSIG extends RR {
25
25
  return 250
26
26
  }
27
27
 
28
+ getCanonical() {
29
+ return {
30
+ owner: 'test.example.',
31
+ ttl: 0,
32
+ class: 'ANY',
33
+ type: 'TSIG',
34
+ 'algorithm name': 'hmac-sha256.',
35
+ 'time signed': 1620650000,
36
+ fudge: 300,
37
+ mac: 'ABCDEF...',
38
+ 'original id': 12345,
39
+ error: 0,
40
+ other: '',
41
+ }
42
+ }
43
+
28
44
  setClass(t) {
29
45
  if (t !== 'ANY') this.throwHelp('TSIG: Class is required to be ANY')
30
46
  this.set('class', t)
package/rr/txt.js CHANGED
@@ -16,18 +16,32 @@ export default class TXT extends RR {
16
16
  return 'Text'
17
17
  }
18
18
 
19
+ getTags() {
20
+ return ['common']
21
+ }
22
+
19
23
  getRdataFields(arg) {
20
24
  return ['data']
21
25
  }
22
26
 
23
27
  getRFCs() {
24
- return [1035]
28
+ return [1035, 4408, 7208, 6376]
25
29
  }
26
30
 
27
31
  getTypeId() {
28
32
  return 16
29
33
  }
30
34
 
35
+ getCanonical() {
36
+ return {
37
+ owner: 'example.com.',
38
+ ttl: 3600,
39
+ class: 'IN',
40
+ type: 'TXT',
41
+ data: 'v=spf1 mx -all',
42
+ }
43
+ }
44
+
31
45
  /****** IMPORTERS *******/
32
46
  fromTinydns({ tinyline }) {
33
47
  const str = tinyline
@@ -98,6 +112,12 @@ export default class TXT extends RR {
98
112
  return `${this.get('owner')}\t+${this.get('ttl')}\t${this.get('type')}\t'${data}' ~\n`
99
113
  }
100
114
 
115
+ getWireRdata() {
116
+ let data = this.get('data')
117
+ if (Array.isArray(data)) data = data.join('')
118
+ return packStringWire(data)
119
+ }
120
+
101
121
  toTinydns() {
102
122
  let data = this.get('data')
103
123
  if (Array.isArray(data)) data = data.join('')
@@ -127,3 +147,18 @@ function asQuotedStrings(data) {
127
147
 
128
148
  return data
129
149
  }
150
+
151
+ function packStringWire(str) {
152
+ const parts = str.match(/(.{1,255})/g)
153
+ let len = 0
154
+ for (const part of parts) len += part.length + 1
155
+
156
+ const buf = Buffer.allocUnsafe(len)
157
+ let offset = 0
158
+ for (const part of parts) {
159
+ buf.writeUInt8(part.length, offset++)
160
+ buf.write(part, offset, 'ascii')
161
+ offset += part.length
162
+ }
163
+ return buf
164
+ }
package/rr/uri.js CHANGED
@@ -75,6 +75,18 @@ export default class URI extends RR {
75
75
  return 256
76
76
  }
77
77
 
78
+ getCanonical() {
79
+ return {
80
+ owner: 'www.example.com.',
81
+ ttl: 3600,
82
+ class: 'IN',
83
+ type: 'URI',
84
+ priority: 10,
85
+ weight: 10,
86
+ target: 'http://www.example.com/',
87
+ }
88
+ }
89
+
78
90
  getQuotedFields() {
79
91
  return ['target']
80
92
  }
package/rr/wks.js CHANGED
@@ -29,6 +29,10 @@ export default class WKS extends RR {
29
29
  return 'Well Known Service'
30
30
  }
31
31
 
32
+ getTags() {
33
+ return ['obsolete']
34
+ }
35
+
32
36
  getRdataFields(arg) {
33
37
  return ['address', 'protocol', 'bit map']
34
38
  }
@@ -41,6 +45,18 @@ export default class WKS extends RR {
41
45
  return 11
42
46
  }
43
47
 
48
+ getCanonical() {
49
+ return {
50
+ owner: 'host.example.com.',
51
+ ttl: 3600,
52
+ class: 'IN',
53
+ type: 'WKS',
54
+ address: '192.0.2.1',
55
+ protocol: 'TCP',
56
+ 'bit map': 'ftp smtp',
57
+ }
58
+ }
59
+
44
60
  /****** IMPORTERS *******/
45
61
 
46
62
  fromBind({ bindline }) {
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
+ }