@nictool/dns-resource-record 1.1.7 → 1.2.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +26 -43
  2. package/README.md +48 -48
  3. package/index.js +83 -29
  4. package/lib/tinydns.js +68 -61
  5. package/package.json +1 -2
  6. package/rr/a.js +32 -23
  7. package/rr/aaaa.js +49 -35
  8. package/rr/caa.js +56 -44
  9. package/rr/cert.js +21 -19
  10. package/rr/cname.js +22 -23
  11. package/rr/dname.js +23 -23
  12. package/rr/dnskey.js +45 -43
  13. package/rr/ds.js +40 -40
  14. package/rr/hinfo.js +29 -28
  15. package/rr/https.js +62 -0
  16. package/rr/ipseckey.js +69 -50
  17. package/rr/key.js +23 -23
  18. package/rr/loc.js +71 -58
  19. package/rr/mx.js +41 -27
  20. package/rr/naptr.js +52 -53
  21. package/rr/ns.js +26 -23
  22. package/rr/nsec.js +24 -20
  23. package/rr/nsec3.js +59 -46
  24. package/rr/nsec3param.js +24 -26
  25. package/rr/nxt.js +65 -0
  26. package/rr/openpgpkey.js +18 -15
  27. package/rr/ptr.js +20 -21
  28. package/rr/rrsig.js +28 -23
  29. package/rr/sig.js +25 -20
  30. package/rr/smimea.js +36 -31
  31. package/rr/soa.js +56 -42
  32. package/rr/spf.js +21 -18
  33. package/rr/srv.js +45 -45
  34. package/rr/sshfp.js +30 -31
  35. package/rr/svcb.js +64 -0
  36. package/rr/tlsa.js +50 -45
  37. package/rr/tsig.js +56 -0
  38. package/rr/txt.js +42 -35
  39. package/rr/uri.js +33 -33
  40. package/rr/wks.js +45 -0
  41. package/rr.js +133 -87
  42. package/.codeclimate.yml +0 -25
  43. package/DEVELOP.md +0 -23
  44. package/test/a.js +0 -76
  45. package/test/aaaa.js +0 -79
  46. package/test/base.js +0 -138
  47. package/test/caa.js +0 -104
  48. package/test/cert.js +0 -48
  49. package/test/cname.js +0 -41
  50. package/test/dname.js +0 -53
  51. package/test/dnskey.js +0 -44
  52. package/test/ds.js +0 -44
  53. package/test/fake.js +0 -26
  54. package/test/hinfo.js +0 -75
  55. package/test/ipseckey.js +0 -115
  56. package/test/key.js +0 -37
  57. package/test/loc.js +0 -71
  58. package/test/mx.js +0 -75
  59. package/test/naptr.js +0 -40
  60. package/test/ns.js +0 -53
  61. package/test/nsec.js +0 -38
  62. package/test/nsec3.js +0 -40
  63. package/test/nsec3param.js +0 -26
  64. package/test/openpgpkey.js +0 -35
  65. package/test/ptr.js +0 -54
  66. package/test/rr.js +0 -196
  67. package/test/smimea.js +0 -45
  68. package/test/soa.js +0 -77
  69. package/test/spf.js +0 -48
  70. package/test/srv.js +0 -81
  71. package/test/sshfp.js +0 -62
  72. package/test/tinydns.js +0 -140
  73. package/test/tlsa.js +0 -54
  74. package/test/txt.js +0 -70
  75. package/test/uri.js +0 -61
package/rr/txt.js CHANGED
@@ -1,62 +1,60 @@
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(':')
59
- if (n != 16) throw new Error('TXT fromTinydns, invalid n')
56
+ let [fqdn, n, rdata, ttl, ts, loc] = str.substring(1).split(':')
57
+ if (n != 16) this.throwHelp('TXT fromTinydns, invalid n')
60
58
 
61
59
  rdata = TINYDNS.octalToChar(rdata)
62
60
  let s = ''
@@ -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*$/)
76
- if (!match) throw new Error(`unable to parse TXT: ${opts.bindline}`)
77
- const [ owner, ttl, c, type, rdata ] = match.slice(1)
73
+ const match = opts.bindline.split(
74
+ /^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+?\s*(.*?)\s*$/,
75
+ )
76
+ if (!match) this.throwHelp(`unable to parse TXT: ${opts.bindline}`)
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) {
25
- if (!val) throw new Error(`URI: target is required, ${this.citeRFC()}`)
23
+ setTarget(val) {
24
+ if (!val) this.throwHelp(`URI: target is required`)
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(':')
34
- if (n != 256) throw new Error('URI fromTinydns, invalid n')
32
+ const [fqdn, n, rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
33
+ if (n != 256) this.throwHelp('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,45 @@
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] =
32
+ opts.bindline.split(/\s+/)
33
+ return new WKS({
34
+ owner,
35
+ ttl: parseInt(ttl, 10),
36
+ class: c,
37
+ type,
38
+ address, // 32-bit int
39
+ protocol, // 8-bit int, 6=TCP, 17=UDP
40
+ bitmap, // var len bit map, must be multiple of 8
41
+ })
42
+ }
43
+
44
+ /****** EXPORTERS *******/
45
+ }