@nictool/dns-resource-record 1.1.6 → 1.2.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.
Files changed (74) hide show
  1. package/.prettierrc.yml +3 -0
  2. package/CHANGELOG.md +17 -43
  3. package/README.md +56 -62
  4. package/index.js +77 -29
  5. package/lib/tinydns.js +68 -61
  6. package/package.json +10 -6
  7. package/rr/a.js +19 -20
  8. package/rr/aaaa.js +35 -31
  9. package/rr/caa.js +41 -39
  10. package/rr/cert.js +21 -19
  11. package/rr/cname.js +19 -20
  12. package/rr/dname.js +19 -19
  13. package/rr/dnskey.js +48 -41
  14. package/rr/ds.js +38 -36
  15. package/rr/hinfo.js +26 -25
  16. package/rr/ipseckey.js +53 -45
  17. package/rr/key.js +21 -21
  18. package/rr/loc.js +67 -54
  19. package/rr/mx.js +26 -24
  20. package/rr/naptr.js +51 -52
  21. package/rr/ns.js +25 -22
  22. package/rr/nsec.js +26 -20
  23. package/rr/nsec3.js +90 -30
  24. package/rr/nsec3param.js +29 -26
  25. package/rr/nxt.js +67 -0
  26. package/rr/openpgpkey.js +13 -14
  27. package/rr/ptr.js +20 -21
  28. package/rr/rrsig.js +27 -21
  29. package/rr/sig.js +24 -19
  30. package/rr/smimea.js +35 -28
  31. package/rr/soa.js +57 -42
  32. package/rr/spf.js +20 -17
  33. package/rr/srv.js +41 -41
  34. package/rr/sshfp.js +29 -30
  35. package/rr/tlsa.js +47 -40
  36. package/rr/tsig.js +48 -0
  37. package/rr/txt.js +40 -33
  38. package/rr/uri.js +31 -31
  39. package/rr/wks.js +44 -0
  40. package/rr.js +116 -79
  41. package/.codeclimate.yml +0 -25
  42. package/DEVELOP.md +0 -23
  43. package/test/a.js +0 -76
  44. package/test/aaaa.js +0 -79
  45. package/test/base.js +0 -138
  46. package/test/caa.js +0 -104
  47. package/test/cert.js +0 -48
  48. package/test/cname.js +0 -41
  49. package/test/dname.js +0 -53
  50. package/test/dnskey.js +0 -44
  51. package/test/ds.js +0 -44
  52. package/test/fake.js +0 -26
  53. package/test/hinfo.js +0 -75
  54. package/test/ipseckey.js +0 -115
  55. package/test/key.js +0 -37
  56. package/test/loc.js +0 -71
  57. package/test/mx.js +0 -75
  58. package/test/naptr.js +0 -40
  59. package/test/ns.js +0 -53
  60. package/test/nsec.js +0 -38
  61. package/test/nsec3.js +0 -26
  62. package/test/nsec3param.js +0 -26
  63. package/test/openpgpkey.js +0 -35
  64. package/test/ptr.js +0 -54
  65. package/test/rr.js +0 -196
  66. package/test/smimea.js +0 -45
  67. package/test/soa.js +0 -77
  68. package/test/spf.js +0 -48
  69. package/test/srv.js +0 -81
  70. package/test/sshfp.js +0 -62
  71. package/test/tinydns.js +0 -140
  72. package/test/tlsa.js +0 -54
  73. package/test/txt.js +0 -70
  74. package/test/uri.js +0 -61
package/rr/tlsa.js CHANGED
@@ -1,106 +1,113 @@
1
-
2
1
  import RR from '../rr.js'
3
2
 
4
3
  import * as TINYDNS from '../lib/tinydns.js'
5
4
 
6
5
  export default class TLSA extends RR {
7
- constructor (opts) {
6
+ constructor(opts) {
8
7
  super(opts)
9
8
  }
10
9
 
11
10
  /****** Resource record specific setters *******/
12
- setCertificateUsage (val) {
13
- if (![ 0,1,2,3 ].includes(val))
11
+ setCertificateUsage(val) {
12
+ if (![0, 1, 2, 3].includes(val))
14
13
  throw new Error(`TLSA: certificate usage invalid, ${this.citeRFC()}`)
15
14
 
16
15
  this.set('certificate usage', val)
17
16
  }
18
17
 
19
- setSelector (val) {
20
- if (![ 0,1 ].includes(val))
18
+ setSelector(val) {
19
+ if (![0, 1].includes(val))
21
20
  throw new Error(`TLSA: selector invalid, ${this.citeRFC()}`)
22
21
 
23
22
  this.set('selector', val)
24
23
  }
25
24
 
26
- setMatchingType (val) {
27
- if (![ 0,1,2 ].includes(val))
25
+ setMatchingType(val) {
26
+ if (![0, 1, 2].includes(val))
28
27
  throw new Error(`TLSA: matching type, ${this.citeRFC()}`)
29
28
 
30
29
  this.set('matching type', val)
31
30
  }
32
31
 
33
- setCertificateAssociationData (val) {
32
+ setCertificateAssociationData(val) {
34
33
  this.set('certificate association data', val)
35
34
  }
36
35
 
37
- getDescription () {
36
+ getDescription() {
38
37
  return 'TLSA certificate association'
39
38
  }
40
39
 
41
- getRdataFields (arg) {
42
- return [ 'certificate usage', 'selector', 'matching type', 'certificate association data' ]
40
+ getRdataFields(arg) {
41
+ return [
42
+ 'certificate usage',
43
+ 'selector',
44
+ 'matching type',
45
+ 'certificate association data',
46
+ ]
43
47
  }
44
48
 
45
- getRFCs () {
46
- return [ 6698 ]
49
+ getRFCs() {
50
+ return [6698]
47
51
  }
48
52
 
49
- getTypeId () {
53
+ getTypeId() {
50
54
  return 52
51
55
  }
52
56
 
53
- getQuotedFields () {
54
- return [ ]
57
+ getQuotedFields() {
58
+ return []
55
59
  }
56
60
 
57
61
  /****** IMPORTERS *******/
58
62
 
59
- fromBind (opts) {
63
+ fromBind(opts) {
60
64
  // test.example.com 3600 IN TLSA, usage, selector, match, data
61
- const match = opts.bindline.split(/^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+(.*?)\s*$/)
65
+ const match = opts.bindline.split(
66
+ /^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+(.*?)\s*$/,
67
+ )
62
68
  if (!match) throw new Error(`unable to parse TLSA: ${opts.bindline}`)
63
- const [ owner, ttl, c, type, usage, selector, matchtype, cad ] = match.slice(1)
69
+ const [owner, ttl, c, type, usage, selector, matchtype, cad] =
70
+ match.slice(1)
64
71
  return new TLSA({
65
- owner : this.fullyQualify(owner),
66
- ttl : parseInt(ttl, 10),
67
- class : c,
72
+ owner: this.fullyQualify(owner),
73
+ ttl: parseInt(ttl, 10),
74
+ class: c,
68
75
  type,
69
- 'certificate usage' : parseInt(usage, 10),
70
- selector : parseInt(selector, 10),
71
- 'matching type' : parseInt(matchtype, 10),
76
+ 'certificate usage': parseInt(usage, 10),
77
+ selector: parseInt(selector, 10),
78
+ 'matching type': parseInt(matchtype, 10),
72
79
  'certificate association data': cad,
73
80
  })
74
81
  }
75
82
 
76
- fromTinydns (opts) {
77
- const [ fqdn, n, rdata, ttl, ts, loc ] = opts.tinyline.substring(1).split(':')
83
+ fromTinydns(opts) {
84
+ const [fqdn, n, rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
78
85
  if (n != 52) throw new Error('TLSA fromTinydns, invalid n')
79
86
 
80
87
  const bytes = Buffer.from(TINYDNS.octalToChar(rdata), 'binary')
81
88
 
82
89
  return new TLSA({
83
- owner : this.fullyQualify(fqdn),
84
- ttl : parseInt(ttl, 10),
85
- type : 'TLSA',
86
- 'certificate usage' : bytes.readUInt8(0),
87
- selector : bytes.readUInt8(1),
88
- 'matching type' : bytes.readUInt8(2),
90
+ owner: this.fullyQualify(fqdn),
91
+ ttl: parseInt(ttl, 10),
92
+ type: 'TLSA',
93
+ 'certificate usage': bytes.readUInt8(0),
94
+ selector: bytes.readUInt8(1),
95
+ 'matching type': bytes.readUInt8(2),
89
96
  'certificate association data': bytes.slice(3).toString(),
90
- timestamp : ts,
91
- location : loc !== '' && loc !== '\n' ? loc : '',
97
+ timestamp: ts,
98
+ location: loc !== '' && loc !== '\n' ? loc : '',
92
99
  })
93
100
  }
94
101
 
95
102
  /****** EXPORTERS *******/
96
- toTinydns () {
103
+ toTinydns() {
97
104
  const dataRe = new RegExp(/[\r\n\t:\\/]/, 'g')
98
105
 
99
106
  return this.getTinydnsGeneric(
100
107
  TINYDNS.UInt8toOctal(this.get('certificate usage')) +
101
- TINYDNS.UInt8toOctal(this.get('selector')) +
102
- TINYDNS.UInt8toOctal(this.get('matching type')) +
103
- TINYDNS.escapeOctal(dataRe, this.get('certificate association data'))
108
+ TINYDNS.UInt8toOctal(this.get('selector')) +
109
+ TINYDNS.UInt8toOctal(this.get('matching type')) +
110
+ TINYDNS.escapeOctal(dataRe, this.get('certificate association data')),
104
111
  )
105
112
  }
106
113
  }
package/rr/tsig.js ADDED
@@ -0,0 +1,48 @@
1
+ import RR from '../rr.js'
2
+
3
+ export default class TSIG extends RR {
4
+ constructor(opts) {
5
+ super(opts)
6
+ if (opts === null) return
7
+ }
8
+
9
+ /****** Resource record specific setters *******/
10
+
11
+ getDescription() {
12
+ return 'Transaction Signature'
13
+ }
14
+
15
+ getRdataFields(arg) {
16
+ return ['algorithm name', 'time signed', 'fudge', 'mac', 'original id', 'error', 'other']
17
+ }
18
+
19
+ getRFCs() {
20
+ return [2845]
21
+ }
22
+
23
+ getTypeId() {
24
+ return 250
25
+ }
26
+
27
+ /****** IMPORTERS *******/
28
+
29
+ fromBind(opts) {
30
+ // test.example.com 3600 IN TSIG SAMPLE-ALG.EXAMPLE. 853804800 300 0 0 0
31
+ const [owner, ttl, c, type, algorithm] = opts.bindline.split(/\s+/)
32
+ return new TSIG({
33
+ owner,
34
+ ttl: parseInt(ttl, 10),
35
+ class: c,
36
+ type: type,
37
+ 'algorithm': algorithm,
38
+ // 'time signed': opts.bindline,
39
+ // fudge
40
+ // mac
41
+ // original id
42
+ // error
43
+ // other
44
+ })
45
+ }
46
+
47
+ /****** EXPORTERS *******/
48
+ }
package/rr/txt.js CHANGED
@@ -1,61 +1,59 @@
1
-
2
1
  import RR from '../rr.js'
3
2
 
4
3
  import * as TINYDNS from '../lib/tinydns.js'
5
4
 
6
5
  export default class TXT extends RR {
7
- constructor (opts) {
6
+ constructor(opts) {
8
7
  super(opts)
9
8
  }
10
9
 
11
10
  /****** Resource record specific setters *******/
12
- setData (val) {
11
+ setData(val) {
13
12
  this.set('data', val)
14
13
  }
15
14
 
16
- getDescription () {
15
+ getDescription() {
17
16
  return 'Text'
18
17
  }
19
18
 
20
- getRdataFields (arg) {
21
- return [ 'data' ]
19
+ getRdataFields(arg) {
20
+ return ['data']
22
21
  }
23
22
 
24
- getRFCs () {
25
- return [ 1035 ]
23
+ getRFCs() {
24
+ return [1035]
26
25
  }
27
26
 
28
- getTypeId () {
27
+ getTypeId() {
29
28
  return 16
30
29
  }
31
30
 
32
31
  /****** IMPORTERS *******/
33
- fromTinydns (opts) {
32
+ fromTinydns(opts) {
34
33
  const str = opts.tinyline
35
34
  let fqdn, rdata, s, ttl, ts, loc
36
35
  // 'fqdn:s:ttl:timestamp:lo
37
36
  if (str[0] === "'") {
38
- [ fqdn, s, ttl, ts, loc ] = str.substring(1).split(':')
37
+ ;[fqdn, s, ttl, ts, loc] = str.substring(1).split(':')
39
38
  rdata = TINYDNS.octalToChar(s)
40
- }
41
- else {
42
- [ fqdn, rdata, ttl, ts, loc ] = this.fromTinydnsGeneric(str)
39
+ } else {
40
+ ;[fqdn, rdata, ttl, ts, loc] = this.fromTinydnsGeneric(str)
43
41
  }
44
42
 
45
43
  return new this.constructor({
46
- owner : this.fullyQualify(fqdn),
47
- ttl : parseInt(ttl, 10),
48
- type : 'TXT',
49
- data : rdata,
44
+ owner: this.fullyQualify(fqdn),
45
+ ttl: parseInt(ttl, 10),
46
+ type: 'TXT',
47
+ data: rdata,
50
48
  timestamp: ts,
51
- location : loc !== '' && loc !== '\n' ? loc : '',
49
+ location: loc !== '' && loc !== '\n' ? loc : '',
52
50
  })
53
51
  }
54
52
 
55
- fromTinydnsGeneric (str) {
53
+ fromTinydnsGeneric(str) {
56
54
  // generic: :fqdn:n:rdata:ttl:timestamp:location
57
55
  // eslint-disable-next-line prefer-const
58
- let [ fqdn, n, rdata, ttl, ts, loc ] = str.substring(1).split(':')
56
+ let [fqdn, n, rdata, ttl, ts, loc] = str.substring(1).split(':')
59
57
  if (n != 16) throw new Error('TXT fromTinydns, invalid n')
60
58
 
61
59
  rdata = TINYDNS.octalToChar(rdata)
@@ -67,35 +65,40 @@ export default class TXT extends RR {
67
65
  pos = len + pos
68
66
  len = rdata.charCodeAt(pos + 1)
69
67
  }
70
- return [ fqdn, s, ttl, ts, loc ]
68
+ return [fqdn, s, ttl, ts, loc]
71
69
  }
72
70
 
73
- fromBind (opts) {
71
+ fromBind(opts) {
74
72
  // test.example.com 3600 IN TXT "..."
75
- const match = opts.bindline.split(/^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+?\s*(.*?)\s*$/)
73
+ const match = opts.bindline.split(
74
+ /^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+?\s*(.*?)\s*$/,
75
+ )
76
76
  if (!match) throw new Error(`unable to parse TXT: ${opts.bindline}`)
77
- const [ owner, ttl, c, type, rdata ] = match.slice(1)
77
+ const [owner, ttl, c, type, rdata] = match.slice(1)
78
78
 
79
79
  return new this.constructor({
80
80
  owner,
81
- ttl : parseInt(ttl, 10),
81
+ ttl: parseInt(ttl, 10),
82
82
  class: c,
83
83
  type,
84
- data : rdata.match(/"([^"]+?)"/g).map(s => s.replace(/^"|"$/g, '')).join(''),
84
+ data: rdata
85
+ .match(/"([^"]+?)"/g)
86
+ .map((s) => s.replace(/^"|"$/g, ''))
87
+ .join(''),
85
88
  })
86
89
  }
87
90
 
88
91
  /****** EXPORTERS *******/
89
- toBind (zone_opts) {
92
+ toBind(zone_opts) {
90
93
  return `${this.getPrefix(zone_opts)}\t"${asQuotedStrings(this.get('data'))}"\n`
91
94
  }
92
95
 
93
- toMaraDNS () {
96
+ toMaraDNS() {
94
97
  const data = asQuotedStrings(this.get('data')).replace(/"/g, "'")
95
98
  return `${this.get('owner')}\t+${this.get('ttl')}\t${this.get('type')}\t'${data}' ~\n`
96
99
  }
97
100
 
98
- toTinydns () {
101
+ toTinydns() {
99
102
  let data = this.get('data')
100
103
  if (Array.isArray(data)) data = data.join('')
101
104
  const rdata = TINYDNS.escapeOctal(new RegExp(/[\r\n\t:\\/]/, 'g'), data)
@@ -103,15 +106,19 @@ export default class TXT extends RR {
103
106
  }
104
107
  }
105
108
 
106
- function asQuotedStrings (data) {
107
-
109
+ function asQuotedStrings(data) {
108
110
  // BIND croaks when any string in the TXT RR data is longer than 255
109
111
  if (Array.isArray(data)) {
110
112
  let hasTooLong = false
111
113
  for (const str of data) {
112
114
  if (str.length > 255) hasTooLong = true
113
115
  }
114
- return hasTooLong ? data.join('').match(/(.{1,255})/g).join('" "') : data.join('" "')
116
+ return hasTooLong
117
+ ? data
118
+ .join('')
119
+ .match(/(.{1,255})/g)
120
+ .join('" "')
121
+ : data.join('" "')
115
122
  }
116
123
 
117
124
  if (data.length > 255) {
package/rr/uri.js CHANGED
@@ -1,91 +1,91 @@
1
-
2
1
  import RR from '../rr.js'
3
2
 
4
3
  import * as TINYDNS from '../lib/tinydns.js'
5
4
 
6
5
  export default class URI extends RR {
7
- constructor (opts) {
6
+ constructor(opts) {
8
7
  super(opts)
9
8
  }
10
9
 
11
10
  /****** Resource record specific setters *******/
12
- setPriority (val) {
11
+ setPriority(val) {
13
12
  this.is16bitInt('URI', 'priority', val)
14
13
 
15
14
  this.set('priority', val)
16
15
  }
17
16
 
18
- setWeight (val) {
17
+ setWeight(val) {
19
18
  this.is16bitInt('URI', 'weight', val)
20
19
 
21
20
  this.set('weight', val)
22
21
  }
23
22
 
24
- setTarget (val) {
23
+ setTarget(val) {
25
24
  if (!val) throw new Error(`URI: target is required, ${this.citeRFC()}`)
26
25
 
27
26
  this.set('target', val)
28
27
  }
29
28
 
30
29
  /****** IMPORTERS *******/
31
- fromTinydns (opts) {
30
+ fromTinydns(opts) {
32
31
  // URI via generic, :fqdn:n:rdata:ttl:timestamp:lo
33
- const [ fqdn, n, rdata, ttl, ts, loc ] = opts.tinyline.substring(1).split(':')
32
+ const [fqdn, n, rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
34
33
  if (n != 256) throw new Error('URI fromTinydns, invalid n')
35
34
 
36
35
  return new URI({
37
- type : 'URI',
38
- owner : this.fullyQualify(fqdn),
39
- priority : TINYDNS.octalToUInt16(rdata.substring(0, 8)),
40
- weight : TINYDNS.octalToUInt16(rdata.substring(8, 16)),
41
- target : TINYDNS.octalToChar(rdata.substring(16)),
42
- ttl : parseInt(ttl, 10),
36
+ type: 'URI',
37
+ owner: this.fullyQualify(fqdn),
38
+ priority: TINYDNS.octalToUInt16(rdata.substring(0, 8)),
39
+ weight: TINYDNS.octalToUInt16(rdata.substring(8, 16)),
40
+ target: TINYDNS.octalToChar(rdata.substring(16)),
41
+ ttl: parseInt(ttl, 10),
43
42
  timestamp: ts,
44
- location : loc !== '' && loc !== '\n' ? loc : '',
43
+ location: loc !== '' && loc !== '\n' ? loc : '',
45
44
  })
46
45
  }
47
46
 
48
- fromBind (opts) {
47
+ fromBind(opts) {
49
48
  // test.example.com 3600 IN URI priority, weight, target
50
- const [ owner, ttl, c, type, priority, weight, target ] = opts.bindline.split(/\s+/)
49
+ const [owner, ttl, c, type, priority, weight, target] =
50
+ opts.bindline.split(/\s+/)
51
51
  return new URI({
52
- class : c,
53
- type : type,
52
+ class: c,
53
+ type: type,
54
54
  owner,
55
55
  priority: parseInt(priority, 10),
56
- weight : parseInt(weight, 10),
57
- target : target.replace(/^"|"$/g, ''),
58
- ttl : parseInt(ttl, 10),
56
+ weight: parseInt(weight, 10),
57
+ target: target.replace(/^"|"$/g, ''),
58
+ ttl: parseInt(ttl, 10),
59
59
  })
60
60
  }
61
61
 
62
62
  /****** MISC *******/
63
- getDescription () {
63
+ getDescription() {
64
64
  return 'URI'
65
65
  }
66
66
 
67
- getRdataFields (arg) {
68
- return [ 'priority', 'weight', 'target' ]
67
+ getRdataFields(arg) {
68
+ return ['priority', 'weight', 'target']
69
69
  }
70
70
 
71
- getRFCs () {
72
- return [ 7553 ]
71
+ getRFCs() {
72
+ return [7553]
73
73
  }
74
74
 
75
- getTypeId () {
75
+ getTypeId() {
76
76
  return 256
77
77
  }
78
78
 
79
- getQuotedFields () {
80
- return [ 'target' ]
79
+ getQuotedFields() {
80
+ return ['target']
81
81
  }
82
82
 
83
83
  /****** EXPORTERS *******/
84
- toTinydns () {
84
+ toTinydns() {
85
85
  const dataRe = new RegExp(/[\r\n\t:\\/]/, 'g')
86
86
  let rdata = ''
87
87
 
88
- for (const e of [ 'priority', 'weight' ]) {
88
+ for (const e of ['priority', 'weight']) {
89
89
  rdata += TINYDNS.UInt16toOctal(this.get(e))
90
90
  }
91
91
 
package/rr/wks.js ADDED
@@ -0,0 +1,44 @@
1
+ import RR from '../rr.js'
2
+
3
+ export default class WKS extends RR {
4
+ constructor(opts) {
5
+ super(opts)
6
+ if (opts === null) return
7
+ }
8
+
9
+ /****** Resource record specific setters *******/
10
+
11
+ getDescription() {
12
+ return 'Well Known Service'
13
+ }
14
+
15
+ getRdataFields(arg) {
16
+ return ['bit map']
17
+ }
18
+
19
+ getRFCs() {
20
+ return [883, 1035]
21
+ }
22
+
23
+ getTypeId() {
24
+ return 11
25
+ }
26
+
27
+ /****** IMPORTERS *******/
28
+
29
+ fromBind(opts) {
30
+ // test.example.com 3600 IN WKS 192.168.1.1 TCP 25
31
+ const [owner, ttl, c, type, address, protocol, bitmap] = opts.bindline.split(/\s+/)
32
+ return new WKS({
33
+ owner,
34
+ ttl: parseInt(ttl, 10),
35
+ class: c,
36
+ type,
37
+ address, // 32-bit int
38
+ protocol, // 8-bit int, 6=TCP, 17=UDP
39
+ bitmap, // var len bit map, must be multiple of 8
40
+ })
41
+ }
42
+
43
+ /****** EXPORTERS *******/
44
+ }