@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.
- package/CHANGELOG.md +26 -43
- package/README.md +48 -48
- package/index.js +83 -29
- package/lib/tinydns.js +68 -61
- package/package.json +1 -2
- package/rr/a.js +32 -23
- package/rr/aaaa.js +49 -35
- package/rr/caa.js +56 -44
- package/rr/cert.js +21 -19
- package/rr/cname.js +22 -23
- package/rr/dname.js +23 -23
- package/rr/dnskey.js +45 -43
- package/rr/ds.js +40 -40
- package/rr/hinfo.js +29 -28
- package/rr/https.js +62 -0
- package/rr/ipseckey.js +69 -50
- package/rr/key.js +23 -23
- package/rr/loc.js +71 -58
- package/rr/mx.js +41 -27
- package/rr/naptr.js +52 -53
- package/rr/ns.js +26 -23
- package/rr/nsec.js +24 -20
- package/rr/nsec3.js +59 -46
- package/rr/nsec3param.js +24 -26
- package/rr/nxt.js +65 -0
- package/rr/openpgpkey.js +18 -15
- package/rr/ptr.js +20 -21
- package/rr/rrsig.js +28 -23
- package/rr/sig.js +25 -20
- package/rr/smimea.js +36 -31
- package/rr/soa.js +56 -42
- package/rr/spf.js +21 -18
- package/rr/srv.js +45 -45
- package/rr/sshfp.js +30 -31
- package/rr/svcb.js +64 -0
- package/rr/tlsa.js +50 -45
- package/rr/tsig.js +56 -0
- package/rr/txt.js +42 -35
- package/rr/uri.js +33 -33
- package/rr/wks.js +45 -0
- package/rr.js +133 -87
- package/.codeclimate.yml +0 -25
- package/DEVELOP.md +0 -23
- package/test/a.js +0 -76
- package/test/aaaa.js +0 -79
- package/test/base.js +0 -138
- package/test/caa.js +0 -104
- package/test/cert.js +0 -48
- package/test/cname.js +0 -41
- package/test/dname.js +0 -53
- package/test/dnskey.js +0 -44
- package/test/ds.js +0 -44
- package/test/fake.js +0 -26
- package/test/hinfo.js +0 -75
- package/test/ipseckey.js +0 -115
- package/test/key.js +0 -37
- package/test/loc.js +0 -71
- package/test/mx.js +0 -75
- package/test/naptr.js +0 -40
- package/test/ns.js +0 -53
- package/test/nsec.js +0 -38
- package/test/nsec3.js +0 -40
- package/test/nsec3param.js +0 -26
- package/test/openpgpkey.js +0 -35
- package/test/ptr.js +0 -54
- package/test/rr.js +0 -196
- package/test/smimea.js +0 -45
- package/test/soa.js +0 -77
- package/test/spf.js +0 -48
- package/test/srv.js +0 -81
- package/test/sshfp.js +0 -62
- package/test/tinydns.js +0 -140
- package/test/tlsa.js +0 -54
- package/test/txt.js +0 -70
- 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
|
|
6
|
+
constructor(opts) {
|
|
8
7
|
super(opts)
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
/****** Resource record specific setters *******/
|
|
12
|
-
setData
|
|
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
|
|
21
|
-
return [
|
|
19
|
+
getRdataFields(arg) {
|
|
20
|
+
return ['data']
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
getRFCs
|
|
25
|
-
return [
|
|
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
|
|
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
|
-
[
|
|
37
|
+
;[fqdn, s, ttl, ts, loc] = str.substring(1).split(':')
|
|
39
38
|
rdata = TINYDNS.octalToChar(s)
|
|
40
|
-
}
|
|
41
|
-
|
|
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
|
|
47
|
-
ttl
|
|
48
|
-
type
|
|
49
|
-
data
|
|
44
|
+
owner: this.fullyQualify(fqdn),
|
|
45
|
+
ttl: parseInt(ttl, 10),
|
|
46
|
+
type: 'TXT',
|
|
47
|
+
data: rdata,
|
|
50
48
|
timestamp: ts,
|
|
51
|
-
location
|
|
49
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
52
50
|
})
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
fromTinydnsGeneric
|
|
53
|
+
fromTinydnsGeneric(str) {
|
|
56
54
|
// generic: :fqdn:n:rdata:ttl:timestamp:location
|
|
57
55
|
// eslint-disable-next-line prefer-const
|
|
58
|
-
let [
|
|
59
|
-
if (n != 16)
|
|
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 [
|
|
68
|
+
return [fqdn, s, ttl, ts, loc]
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
fromBind
|
|
71
|
+
fromBind(opts) {
|
|
74
72
|
// test.example.com 3600 IN TXT "..."
|
|
75
|
-
const match = opts.bindline.split(
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
81
|
+
ttl: parseInt(ttl, 10),
|
|
82
82
|
class: c,
|
|
83
83
|
type,
|
|
84
|
-
data
|
|
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
|
|
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
|
|
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
|
|
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
|
|
6
|
+
constructor(opts) {
|
|
8
7
|
super(opts)
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
/****** Resource record specific setters *******/
|
|
12
|
-
setPriority
|
|
11
|
+
setPriority(val) {
|
|
13
12
|
this.is16bitInt('URI', 'priority', val)
|
|
14
13
|
|
|
15
14
|
this.set('priority', val)
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
setWeight
|
|
17
|
+
setWeight(val) {
|
|
19
18
|
this.is16bitInt('URI', 'weight', val)
|
|
20
19
|
|
|
21
20
|
this.set('weight', val)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
setTarget
|
|
25
|
-
if (!val)
|
|
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
|
|
30
|
+
fromTinydns(opts) {
|
|
32
31
|
// URI via generic, :fqdn:n:rdata:ttl:timestamp:lo
|
|
33
|
-
const [
|
|
34
|
-
if (n != 256)
|
|
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
|
|
38
|
-
owner
|
|
39
|
-
priority
|
|
40
|
-
weight
|
|
41
|
-
target
|
|
42
|
-
ttl
|
|
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
|
|
43
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
45
44
|
})
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
fromBind
|
|
47
|
+
fromBind(opts) {
|
|
49
48
|
// test.example.com 3600 IN URI priority, weight, target
|
|
50
|
-
const [
|
|
49
|
+
const [owner, ttl, c, type, priority, weight, target] =
|
|
50
|
+
opts.bindline.split(/\s+/)
|
|
51
51
|
return new URI({
|
|
52
|
-
class
|
|
53
|
-
type
|
|
52
|
+
class: c,
|
|
53
|
+
type: type,
|
|
54
54
|
owner,
|
|
55
55
|
priority: parseInt(priority, 10),
|
|
56
|
-
weight
|
|
57
|
-
target
|
|
58
|
-
ttl
|
|
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
|
|
68
|
-
return [
|
|
67
|
+
getRdataFields(arg) {
|
|
68
|
+
return ['priority', 'weight', 'target']
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
getRFCs
|
|
72
|
-
return [
|
|
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 [
|
|
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 [
|
|
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
|
+
}
|