@nictool/dns-resource-record 1.6.1 → 1.7.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 +33 -0
- package/README.md +323 -199
- package/dist/dns-rr.min.js +26 -0
- package/dist/dns-rr.min.js.map +7 -0
- package/index.js +12 -11
- package/lib/binary.js +108 -0
- package/lib/bind.js +94 -0
- package/lib/dns-query.js +67 -0
- package/lib/tinydns.js +128 -44
- package/lib/wire.js +519 -0
- package/package.json +23 -6
- package/rr/TEMPLATE.js +124 -0
- package/rr/a.js +8 -48
- package/rr/aaaa.js +13 -80
- package/rr/apl.js +123 -27
- package/rr/caa.js +27 -50
- package/rr/cert.js +58 -87
- package/rr/cname.js +7 -63
- package/rr/dhcid.js +20 -30
- package/rr/dname.js +9 -36
- package/rr/dnskey.js +38 -32
- package/rr/ds.js +43 -57
- package/rr/hinfo.js +21 -40
- package/rr/hip.js +88 -26
- package/rr/https.js +28 -40
- package/rr/ipseckey.js +97 -18
- package/rr/key.js +39 -29
- package/rr/kx.js +16 -27
- package/rr/loc.js +42 -12
- package/rr/mx.js +16 -51
- package/rr/naptr.js +58 -33
- package/rr/ns.js +8 -36
- package/rr/nsec.js +89 -18
- package/rr/nsec3.js +62 -26
- package/rr/nsec3param.js +56 -53
- package/rr/nxt.js +57 -18
- package/rr/openpgpkey.js +24 -30
- package/rr/ptr.js +7 -47
- package/rr/rp.js +17 -32
- package/rr/rrsig.js +80 -85
- package/rr/sig.js +70 -45
- package/rr/smimea.js +33 -33
- package/rr/soa.js +31 -49
- package/rr/spf.js +10 -17
- package/rr/srv.js +22 -62
- package/rr/sshfp.js +25 -53
- package/rr/svcb.js +27 -40
- package/rr/tlsa.js +34 -34
- package/rr/tsig.js +87 -24
- package/rr/txt.js +40 -59
- package/rr/uri.js +19 -29
- package/rr/wks.js +154 -22
- package/rr.js +290 -109
- package/lib/readme.js +0 -84
package/rr/key.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import RR from '../rr.js'
|
|
2
2
|
import * as TINYDNS from '../lib/tinydns.js'
|
|
3
|
+
import * as BINARY from '../lib/binary.js'
|
|
3
4
|
|
|
4
5
|
export default class KEY extends RR {
|
|
6
|
+
static typeName = 'KEY'
|
|
7
|
+
static typeId = 25
|
|
8
|
+
static RFCs = [2535, 3445, 4034, 6840]
|
|
9
|
+
static rdataFields = [
|
|
10
|
+
['flags', 'u16'],
|
|
11
|
+
['protocol', 'u8'],
|
|
12
|
+
['algorithm', 'u8'],
|
|
13
|
+
['publickey', 'base64'],
|
|
14
|
+
]
|
|
15
|
+
static tags = ['obsolete']
|
|
16
|
+
|
|
5
17
|
constructor(opts) {
|
|
6
18
|
super(opts)
|
|
7
19
|
}
|
|
@@ -43,7 +55,7 @@ export default class KEY extends RR {
|
|
|
43
55
|
|
|
44
56
|
setPublickey(val) {
|
|
45
57
|
if (!val) this.throwHelp(`KEY: publickey is required`)
|
|
46
|
-
|
|
58
|
+
this.isBase64('KEY', 'publickey', val.replace(/[\s()]/g, ''))
|
|
47
59
|
this.set('publickey', val)
|
|
48
60
|
}
|
|
49
61
|
|
|
@@ -51,18 +63,6 @@ export default class KEY extends RR {
|
|
|
51
63
|
return 'DNS Public Key'
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
getRdataFields(arg) {
|
|
55
|
-
return ['flags', 'protocol', 'algorithm', 'publickey']
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getRFCs() {
|
|
59
|
-
return [2535, 3445]
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
getTypeId() {
|
|
63
|
-
return 25
|
|
64
|
-
}
|
|
65
|
-
|
|
66
66
|
getCanonical() {
|
|
67
67
|
return {
|
|
68
68
|
owner: 'example.com.',
|
|
@@ -72,7 +72,8 @@ export default class KEY extends RR {
|
|
|
72
72
|
flags: 256,
|
|
73
73
|
protocol: 3,
|
|
74
74
|
algorithm: 5,
|
|
75
|
-
publickey:
|
|
75
|
+
publickey:
|
|
76
|
+
'AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwIXAqcOTiW7iHnQt5hwVAAAAA==',
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -94,34 +95,43 @@ export default class KEY extends RR {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
fromTinydns({ tinyline }) {
|
|
97
|
-
// RDATA format: Flags (
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
this.throwHelp(`KEY: RDATA too short: ${
|
|
98
|
+
// RDATA format: Flags (8 octal chars) + Protocol (4 octal chars) + Algorithm (4 octal chars) + Public Key (escaped data)
|
|
99
|
+
const { owner, rdata, ttl, timestamp, location } = this.parseTinydnsLine(tinyline)
|
|
100
|
+
if (rdata.length < 16) {
|
|
101
|
+
this.throwHelp(`KEY: RDATA too short: ${rdata}`)
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
return new KEY({
|
|
104
|
-
owner
|
|
105
|
-
ttl
|
|
105
|
+
owner,
|
|
106
|
+
ttl,
|
|
106
107
|
type: 'KEY',
|
|
107
|
-
flags: TINYDNS.octalToUInt16(
|
|
108
|
-
protocol: TINYDNS.octalToUInt8(
|
|
109
|
-
algorithm: TINYDNS.octalToUInt8(
|
|
110
|
-
publickey: TINYDNS.
|
|
111
|
-
timestamp
|
|
112
|
-
location
|
|
108
|
+
flags: TINYDNS.octalToUInt16(rdata.slice(0, 8)),
|
|
109
|
+
protocol: TINYDNS.octalToUInt8(rdata.slice(8, 12)),
|
|
110
|
+
algorithm: TINYDNS.octalToUInt8(rdata.slice(12, 16)),
|
|
111
|
+
publickey: TINYDNS.octalToBase64(rdata.slice(16)),
|
|
112
|
+
timestamp,
|
|
113
|
+
location,
|
|
113
114
|
})
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
/****** EXPORTERS *******/
|
|
117
118
|
toTinydns() {
|
|
118
|
-
const dataRe = new RegExp(/[\r\n\t:\\/]/, 'g')
|
|
119
|
-
|
|
120
119
|
return this.getTinydnsGeneric(
|
|
121
120
|
TINYDNS.UInt16toOctal(this.get('flags')) +
|
|
122
121
|
TINYDNS.UInt8toOctal(this.get('protocol')) +
|
|
123
122
|
TINYDNS.UInt8toOctal(this.get('algorithm')) +
|
|
124
|
-
TINYDNS.
|
|
123
|
+
TINYDNS.base64toOctal(this.get('publickey').replace(/[\s()]/g, '')),
|
|
125
124
|
)
|
|
126
125
|
}
|
|
126
|
+
|
|
127
|
+
getWireRdata() {
|
|
128
|
+
const keyBytes = BINARY.base64ToBytes(this.get('publickey').replace(/[\s()]/g, ''))
|
|
129
|
+
const bytes = new Uint8Array(4 + keyBytes.length)
|
|
130
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset)
|
|
131
|
+
dv.setUint16(0, this.get('flags'))
|
|
132
|
+
bytes[2] = this.get('protocol')
|
|
133
|
+
bytes[3] = this.get('algorithm')
|
|
134
|
+
bytes.set(keyBytes, 4)
|
|
135
|
+
return bytes
|
|
136
|
+
}
|
|
127
137
|
}
|
package/rr/kx.js
CHANGED
|
@@ -3,6 +3,14 @@ import RR from '../rr.js'
|
|
|
3
3
|
import * as TINYDNS from '../lib/tinydns.js'
|
|
4
4
|
|
|
5
5
|
export default class KX extends RR {
|
|
6
|
+
static typeName = 'KX'
|
|
7
|
+
static typeId = 36
|
|
8
|
+
static RFCs = [2230]
|
|
9
|
+
static rdataFields = [
|
|
10
|
+
['preference', 'u16'],
|
|
11
|
+
['exchanger', 'fqdn'],
|
|
12
|
+
]
|
|
13
|
+
|
|
6
14
|
constructor(opts) {
|
|
7
15
|
super(opts)
|
|
8
16
|
}
|
|
@@ -27,18 +35,6 @@ export default class KX extends RR {
|
|
|
27
35
|
return 'Key Exchanger'
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
getRdataFields(arg) {
|
|
31
|
-
return ['preference', 'exchanger']
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getRFCs() {
|
|
35
|
-
return [2230]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getTypeId() {
|
|
39
|
-
return 36
|
|
40
|
-
}
|
|
41
|
-
|
|
42
38
|
getCanonical() {
|
|
43
39
|
return {
|
|
44
40
|
owner: 'example.com.',
|
|
@@ -67,22 +63,15 @@ export default class KX extends RR {
|
|
|
67
63
|
})
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
fromBind({ bindline }) {
|
|
71
|
-
// test.example.com 3600 IN KX preference exchanger
|
|
72
|
-
const [owner, ttl, c, type, preference, exchanger] = bindline.split(/\s+/)
|
|
73
|
-
return new KX({
|
|
74
|
-
owner,
|
|
75
|
-
ttl: parseInt(ttl, 10),
|
|
76
|
-
class: c,
|
|
77
|
-
type,
|
|
78
|
-
preference: parseInt(preference, 10),
|
|
79
|
-
exchanger,
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
66
|
/****** EXPORTERS *******/
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
|
|
68
|
+
getWireRdata() {
|
|
69
|
+
const exchanger = this.wirePackDomain(this.get('exchanger'))
|
|
70
|
+
const result = new Uint8Array(2 + exchanger.length)
|
|
71
|
+
const dv = new DataView(result.buffer)
|
|
72
|
+
dv.setUint16(0, this.get('preference'))
|
|
73
|
+
result.set(exchanger, 2)
|
|
74
|
+
return result
|
|
86
75
|
}
|
|
87
76
|
|
|
88
77
|
toTinydns() {
|
package/rr/loc.js
CHANGED
|
@@ -14,6 +14,11 @@ const CONV = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export default class LOC extends RR {
|
|
17
|
+
static typeName = 'LOC'
|
|
18
|
+
static typeId = 29
|
|
19
|
+
static RFCs = [1876]
|
|
20
|
+
static rdataFields = ['address']
|
|
21
|
+
|
|
17
22
|
constructor(opts) {
|
|
18
23
|
super(opts)
|
|
19
24
|
}
|
|
@@ -36,18 +41,6 @@ export default class LOC extends RR {
|
|
|
36
41
|
return 'Location'
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
getRdataFields(arg) {
|
|
40
|
-
return ['address']
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getRFCs() {
|
|
44
|
-
return [1876]
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getTypeId() {
|
|
48
|
-
return 29
|
|
49
|
-
}
|
|
50
|
-
|
|
51
44
|
getCanonical() {
|
|
52
45
|
return {
|
|
53
46
|
owner: 'example.com.',
|
|
@@ -205,6 +198,27 @@ export default class LOC extends RR {
|
|
|
205
198
|
return r
|
|
206
199
|
}
|
|
207
200
|
|
|
201
|
+
fromWire({ owner, cls, ttl, rdata }) {
|
|
202
|
+
const dv = new DataView(rdata.buffer, rdata.byteOffset)
|
|
203
|
+
const l = {
|
|
204
|
+
size: this.fromExponent(rdata[1]),
|
|
205
|
+
precision: {
|
|
206
|
+
horizontal: this.fromExponent(rdata[2]),
|
|
207
|
+
vertical: this.fromExponent(rdata[3]),
|
|
208
|
+
},
|
|
209
|
+
latitude: this.arcSecToDMS(dv.getUint32(4), 'lat'),
|
|
210
|
+
longitude: this.arcSecToDMS(dv.getUint32(8), 'lon'),
|
|
211
|
+
altitude: dv.getUint32(12) - REF.ALTITUDE,
|
|
212
|
+
}
|
|
213
|
+
return new LOC({
|
|
214
|
+
owner,
|
|
215
|
+
ttl,
|
|
216
|
+
class: cls,
|
|
217
|
+
type: 'LOC',
|
|
218
|
+
address: this.toHuman(l),
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
208
222
|
/****** EXPORTERS *******/
|
|
209
223
|
|
|
210
224
|
toTinydns() {
|
|
@@ -222,4 +236,20 @@ export default class LOC extends RR {
|
|
|
222
236
|
|
|
223
237
|
return this.getTinydnsGeneric(rdata)
|
|
224
238
|
}
|
|
239
|
+
|
|
240
|
+
getWireRdata() {
|
|
241
|
+
const loc = this.parseLoc(this.get('address'))
|
|
242
|
+
const bytes = new Uint8Array(16)
|
|
243
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset)
|
|
244
|
+
|
|
245
|
+
bytes[0] = 0 // version
|
|
246
|
+
bytes[1] = this.toExponent(loc.size)
|
|
247
|
+
bytes[2] = this.toExponent(loc.precision.horizontal)
|
|
248
|
+
bytes[3] = this.toExponent(loc.precision.vertical)
|
|
249
|
+
dv.setUint32(4, this.dmsToArcSec(loc.latitude))
|
|
250
|
+
dv.setUint32(8, this.dmsToArcSec(loc.longitude))
|
|
251
|
+
dv.setUint32(12, loc.altitude + REF.ALTITUDE)
|
|
252
|
+
|
|
253
|
+
return bytes
|
|
254
|
+
}
|
|
225
255
|
}
|
package/rr/mx.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import RR from '../rr.js'
|
|
2
2
|
|
|
3
3
|
export default class MX extends RR {
|
|
4
|
+
static typeName = 'MX'
|
|
5
|
+
static typeId = 15
|
|
6
|
+
static RFCs = [1035, 2181, 7505]
|
|
7
|
+
static tinydnsType = '@'
|
|
8
|
+
static rdataFields = [
|
|
9
|
+
['preference', 'u16'],
|
|
10
|
+
['exchange', 'fqdn'],
|
|
11
|
+
]
|
|
12
|
+
static tags = ['common']
|
|
13
|
+
|
|
4
14
|
constructor(opts) {
|
|
5
15
|
super(opts)
|
|
6
16
|
}
|
|
@@ -13,38 +23,10 @@ export default class MX extends RR {
|
|
|
13
23
|
this.set('preference', val)
|
|
14
24
|
}
|
|
15
25
|
|
|
16
|
-
setExchange(val) {
|
|
17
|
-
if (!val) this.throwHelp('MX: exchange is required')
|
|
18
|
-
|
|
19
|
-
if (this.isIPv4(val) || this.isIPv6(val)) this.throwHelp(`MX: exchange must be a FQDN`)
|
|
20
|
-
|
|
21
|
-
this.isFullyQualified('MX', 'exchange', val)
|
|
22
|
-
this.isValidHostname('MX', 'exchange', val)
|
|
23
|
-
|
|
24
|
-
// RFC 4034: letters in the DNS names ... are lower cased
|
|
25
|
-
this.set('exchange', val.toLowerCase())
|
|
26
|
-
}
|
|
27
|
-
|
|
28
26
|
getDescription() {
|
|
29
27
|
return 'Mail Exchanger'
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
getTags() {
|
|
33
|
-
return ['common']
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getRdataFields(arg) {
|
|
37
|
-
return ['preference', 'exchange']
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getRFCs() {
|
|
41
|
-
return [1035, 2181, 7505]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getTypeId() {
|
|
45
|
-
return 15
|
|
46
|
-
}
|
|
47
|
-
|
|
48
30
|
getCanonical() {
|
|
49
31
|
return {
|
|
50
32
|
owner: 'example.com.',
|
|
@@ -59,8 +41,7 @@ export default class MX extends RR {
|
|
|
59
41
|
/****** IMPORTERS *******/
|
|
60
42
|
fromTinydns({ tinyline }) {
|
|
61
43
|
// @fqdn:ip:x:dist:ttl:timestamp:lo
|
|
62
|
-
|
|
63
|
-
const [owner, ip, x, preference, ttl, ts, loc] = tinyline.slice(1).split(':')
|
|
44
|
+
const [owner, _ip, x, preference, ttl, ts, loc] = tinyline.slice(1).split(':')
|
|
64
45
|
|
|
65
46
|
return new MX({
|
|
66
47
|
type: 'MX',
|
|
@@ -73,29 +54,13 @@ export default class MX extends RR {
|
|
|
73
54
|
})
|
|
74
55
|
}
|
|
75
56
|
|
|
76
|
-
fromBind({ bindline }) {
|
|
77
|
-
// test.example.com 3600 IN MX preference exchange
|
|
78
|
-
const [owner, ttl, c, type, preference, exchange] = bindline.split(/\s+/)
|
|
79
|
-
|
|
80
|
-
return new MX({
|
|
81
|
-
owner,
|
|
82
|
-
ttl: parseInt(ttl, 10),
|
|
83
|
-
class: c,
|
|
84
|
-
type,
|
|
85
|
-
preference: parseInt(preference),
|
|
86
|
-
exchange,
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
|
|
90
57
|
/****** EXPORTERS *******/
|
|
91
58
|
getWireRdata() {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
toBind(zone_opts) {
|
|
98
|
-
return `${this.getPrefix(zone_opts)}\t${this.get('preference')}\t${this.getFQDN('exchange', zone_opts)}\n`
|
|
59
|
+
const domain = this.wirePackDomain(this.get('exchange'))
|
|
60
|
+
const result = new Uint8Array(2 + domain.length)
|
|
61
|
+
new DataView(result.buffer).setUint16(0, this.get('preference'))
|
|
62
|
+
result.set(domain, 2)
|
|
63
|
+
return result
|
|
99
64
|
}
|
|
100
65
|
|
|
101
66
|
toTinydns() {
|
package/rr/naptr.js
CHANGED
|
@@ -4,6 +4,18 @@ import * as TINYDNS from '../lib/tinydns.js'
|
|
|
4
4
|
const rdataRe = /[\r\n\t:\\/]/
|
|
5
5
|
|
|
6
6
|
export default class NAPTR extends RR {
|
|
7
|
+
static typeName = 'NAPTR'
|
|
8
|
+
static typeId = 35
|
|
9
|
+
static RFCs = [2915, 3403, 4848]
|
|
10
|
+
static rdataFields = [
|
|
11
|
+
['order', 'u16'],
|
|
12
|
+
['preference', 'u16'],
|
|
13
|
+
['flags', 'qcharstr'],
|
|
14
|
+
['service', 'qcharstr'],
|
|
15
|
+
['regexp', 'qcharstr'],
|
|
16
|
+
['replacement', 'fqdn'],
|
|
17
|
+
]
|
|
18
|
+
|
|
7
19
|
constructor(opts) {
|
|
8
20
|
super(opts)
|
|
9
21
|
}
|
|
@@ -12,22 +24,6 @@ export default class NAPTR extends RR {
|
|
|
12
24
|
return 'Naming Authority Pointer'
|
|
13
25
|
}
|
|
14
26
|
|
|
15
|
-
getQuotedFields() {
|
|
16
|
-
return ['flags', 'service', 'regexp']
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getRdataFields(arg) {
|
|
20
|
-
return ['order', 'preference', 'flags', 'service', 'regexp', 'replacement']
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getRFCs() {
|
|
24
|
-
return [2915, 3403, 4848]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getTypeId() {
|
|
28
|
-
return 35
|
|
29
|
-
}
|
|
30
|
-
|
|
31
27
|
getCanonical() {
|
|
32
28
|
return {
|
|
33
29
|
owner: 'cid.urn.arpa.',
|
|
@@ -79,40 +75,41 @@ export default class NAPTR extends RR {
|
|
|
79
75
|
/****** IMPORTERS *******/
|
|
80
76
|
fromTinydns({ tinyline }) {
|
|
81
77
|
// NAPTR via generic, :fqdn:n:rdata:ttl:timestamp:lo
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
78
|
+
const { owner, typeId, rdata, ttl, timestamp, location } = this.parseTinydnsLine(tinyline)
|
|
79
|
+
if (typeId != this.getTypeId()) this.throwHelp('NAPTR fromTinydns, invalid n')
|
|
84
80
|
|
|
85
|
-
const binRdata =
|
|
81
|
+
const binRdata = TINYDNS.octalRdataToBytes(rdata)
|
|
82
|
+
const dv = new DataView(binRdata.buffer, binRdata.byteOffset, binRdata.byteLength)
|
|
86
83
|
|
|
87
84
|
const rec = {
|
|
88
85
|
type: 'NAPTR',
|
|
89
|
-
owner
|
|
90
|
-
ttl
|
|
91
|
-
timestamp
|
|
92
|
-
location
|
|
93
|
-
order:
|
|
94
|
-
preference:
|
|
86
|
+
owner,
|
|
87
|
+
ttl,
|
|
88
|
+
timestamp,
|
|
89
|
+
location,
|
|
90
|
+
order: dv.getUint16(0),
|
|
91
|
+
preference: dv.getUint16(2),
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
let idx = 4
|
|
98
|
-
const flagsLength = binRdata
|
|
95
|
+
const flagsLength = binRdata[idx]
|
|
99
96
|
idx++
|
|
100
|
-
rec.flags = binRdata.
|
|
97
|
+
rec.flags = new TextDecoder().decode(binRdata.subarray(idx, idx + flagsLength))
|
|
101
98
|
idx += flagsLength
|
|
102
99
|
|
|
103
|
-
const serviceLen = binRdata
|
|
100
|
+
const serviceLen = binRdata[idx]
|
|
104
101
|
idx++
|
|
105
|
-
rec.service = binRdata.
|
|
102
|
+
rec.service = new TextDecoder().decode(binRdata.subarray(idx, idx + serviceLen))
|
|
106
103
|
idx += serviceLen
|
|
107
104
|
|
|
108
|
-
const regexpLen = binRdata
|
|
105
|
+
const regexpLen = binRdata[idx]
|
|
109
106
|
idx++
|
|
110
|
-
rec.regexp = binRdata.
|
|
107
|
+
rec.regexp = new TextDecoder().decode(binRdata.subarray(idx, idx + regexpLen))
|
|
111
108
|
idx += regexpLen
|
|
112
109
|
|
|
113
|
-
const replaceLen = binRdata
|
|
110
|
+
const replaceLen = binRdata[idx]
|
|
114
111
|
idx++
|
|
115
|
-
rec.replacement = binRdata.
|
|
112
|
+
rec.replacement = new TextDecoder().decode(binRdata.subarray(idx, idx + replaceLen))
|
|
116
113
|
|
|
117
114
|
return new NAPTR(rec)
|
|
118
115
|
}
|
|
@@ -164,4 +161,32 @@ export default class NAPTR extends RR {
|
|
|
164
161
|
|
|
165
162
|
return this.getTinydnsGeneric(rdata)
|
|
166
163
|
}
|
|
164
|
+
|
|
165
|
+
getWireRdata() {
|
|
166
|
+
const enc = new TextEncoder()
|
|
167
|
+
const flags = enc.encode(this.get('flags'))
|
|
168
|
+
const service = enc.encode(this.get('service'))
|
|
169
|
+
const regexp = enc.encode(this.get('regexp'))
|
|
170
|
+
const replacementBytes = this.wirePackDomain(this.get('replacement'))
|
|
171
|
+
|
|
172
|
+
const len = 4 + 1 + flags.length + 1 + service.length + 1 + regexp.length + replacementBytes.length
|
|
173
|
+
const buf = new Uint8Array(len)
|
|
174
|
+
const view = new DataView(buf.buffer)
|
|
175
|
+
let pos = 0
|
|
176
|
+
view.setUint16(pos, this.get('order'))
|
|
177
|
+
pos += 2
|
|
178
|
+
view.setUint16(pos, this.get('preference'))
|
|
179
|
+
pos += 2
|
|
180
|
+
buf[pos++] = flags.length
|
|
181
|
+
buf.set(flags, pos)
|
|
182
|
+
pos += flags.length
|
|
183
|
+
buf[pos++] = service.length
|
|
184
|
+
buf.set(service, pos)
|
|
185
|
+
pos += service.length
|
|
186
|
+
buf[pos++] = regexp.length
|
|
187
|
+
buf.set(regexp, pos)
|
|
188
|
+
pos += regexp.length
|
|
189
|
+
buf.set(replacementBytes, pos)
|
|
190
|
+
return buf
|
|
191
|
+
}
|
|
167
192
|
}
|
package/rr/ns.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import RR from '../rr.js'
|
|
2
2
|
|
|
3
3
|
export default class NS extends RR {
|
|
4
|
+
static typeName = 'NS'
|
|
5
|
+
static typeId = 2
|
|
6
|
+
static RFCs = [1035]
|
|
7
|
+
static tinydnsType = '&'
|
|
8
|
+
static rdataFields = [['dname', 'fqdn']]
|
|
9
|
+
static tags = ['common']
|
|
10
|
+
|
|
4
11
|
constructor(opts) {
|
|
5
12
|
super(opts)
|
|
6
|
-
if (opts === null) return
|
|
7
13
|
}
|
|
8
14
|
|
|
9
15
|
/****** Resource record specific setters *******/
|
|
@@ -21,22 +27,6 @@ export default class NS extends RR {
|
|
|
21
27
|
return 'Name Server'
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
getTags() {
|
|
25
|
-
return ['common']
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getRdataFields(arg) {
|
|
29
|
-
return ['dname']
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getRFCs() {
|
|
33
|
-
return [1035]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getTypeId() {
|
|
37
|
-
return 2
|
|
38
|
-
}
|
|
39
|
-
|
|
40
30
|
getCanonical() {
|
|
41
31
|
return {
|
|
42
32
|
owner: 'example.com.',
|
|
@@ -50,8 +40,7 @@ export default class NS extends RR {
|
|
|
50
40
|
/****** IMPORTERS *******/
|
|
51
41
|
fromTinydns({ tinyline }) {
|
|
52
42
|
// &fqdn:ip:x:ttl:timestamp:lo
|
|
53
|
-
|
|
54
|
-
const [fqdn, ip, dname, ttl, ts, loc] = tinyline.slice(1).split(':')
|
|
43
|
+
const [fqdn, _ip, dname, ttl, ts, loc] = tinyline.slice(1).split(':')
|
|
55
44
|
|
|
56
45
|
return new NS({
|
|
57
46
|
type: 'NS',
|
|
@@ -63,28 +52,11 @@ export default class NS extends RR {
|
|
|
63
52
|
})
|
|
64
53
|
}
|
|
65
54
|
|
|
66
|
-
fromBind({ bindline }) {
|
|
67
|
-
// test.example.com 3600 IN NS dname
|
|
68
|
-
const [owner, ttl, c, type, dname] = bindline.split(/\s+/)
|
|
69
|
-
|
|
70
|
-
return new NS({
|
|
71
|
-
owner,
|
|
72
|
-
ttl: parseInt(ttl, 10),
|
|
73
|
-
class: c,
|
|
74
|
-
type: type,
|
|
75
|
-
dname: dname,
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
55
|
/****** EXPORTERS *******/
|
|
80
56
|
getWireRdata() {
|
|
81
57
|
return this.wirePackDomain(this.get('dname'))
|
|
82
58
|
}
|
|
83
59
|
|
|
84
|
-
toBind(zone_opts) {
|
|
85
|
-
return `${this.getPrefix(zone_opts)}\t${this.getFQDN('dname', zone_opts)}\n`
|
|
86
|
-
}
|
|
87
|
-
|
|
88
60
|
toTinydns() {
|
|
89
61
|
return `&${this.getTinyFQDN('owner')}::${this.getTinyFQDN('dname')}:${this.getTinydnsPostamble()}\n`
|
|
90
62
|
}
|