@nictool/dns-resource-record 1.1.7 → 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.
- package/.prettierrc.yml +3 -0
- package/CHANGELOG.md +17 -43
- package/README.md +45 -47
- package/index.js +77 -29
- package/lib/tinydns.js +68 -61
- package/package.json +1 -2
- package/rr/a.js +19 -20
- package/rr/aaaa.js +35 -31
- package/rr/caa.js +41 -39
- package/rr/cert.js +21 -19
- package/rr/cname.js +19 -20
- package/rr/dname.js +19 -19
- package/rr/dnskey.js +48 -41
- package/rr/ds.js +38 -36
- package/rr/hinfo.js +26 -25
- package/rr/ipseckey.js +53 -45
- package/rr/key.js +21 -21
- package/rr/loc.js +67 -54
- package/rr/mx.js +26 -24
- package/rr/naptr.js +51 -52
- package/rr/ns.js +25 -22
- package/rr/nsec.js +26 -20
- package/rr/nsec3.js +63 -44
- package/rr/nsec3param.js +29 -26
- package/rr/nxt.js +67 -0
- package/rr/openpgpkey.js +13 -14
- package/rr/ptr.js +20 -21
- package/rr/rrsig.js +27 -21
- package/rr/sig.js +24 -19
- package/rr/smimea.js +35 -28
- package/rr/soa.js +57 -42
- package/rr/spf.js +20 -17
- package/rr/srv.js +41 -41
- package/rr/sshfp.js +29 -30
- package/rr/tlsa.js +47 -40
- package/rr/tsig.js +48 -0
- package/rr/txt.js +40 -33
- package/rr/uri.js +31 -31
- package/rr/wks.js +44 -0
- package/rr.js +111 -77
- 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/ipseckey.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import net from 'net'
|
|
3
2
|
|
|
4
3
|
import RR from '../rr.js'
|
|
@@ -6,130 +5,139 @@ import RR from '../rr.js'
|
|
|
6
5
|
import * as TINYDNS from '../lib/tinydns.js'
|
|
7
6
|
|
|
8
7
|
export default class IPSECKEY extends RR {
|
|
9
|
-
constructor
|
|
8
|
+
constructor(opts) {
|
|
10
9
|
super(opts)
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
/****** Resource record specific setters *******/
|
|
14
|
-
setPrecedence
|
|
13
|
+
setPrecedence(val) {
|
|
15
14
|
// an 8-bit precedence for this record.
|
|
16
15
|
this.is8bitInt('IPSECKEY', 'precedence', val)
|
|
17
16
|
|
|
18
17
|
this.set('precedence', val)
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
setGatewayType
|
|
20
|
+
setGatewayType(val) {
|
|
22
21
|
// 0 (none), 1 (4-byte IPv4), 2 (16-byte IPv6), 3 (wire encoded domain name)
|
|
23
|
-
if (![
|
|
22
|
+
if (![0, 1, 2, 3].includes(val))
|
|
24
23
|
throw new Error(`IPSECKEY: Gateway Type is invalid, ${this.citeRFC()}`)
|
|
25
24
|
|
|
26
25
|
this.set('gateway type', val)
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
setAlgorithm
|
|
28
|
+
setAlgorithm(val) {
|
|
30
29
|
// unsigned int, 1 octet, values: 1=DSA, 2=RSA
|
|
31
|
-
if (![
|
|
30
|
+
if (![1, 2].includes(val))
|
|
32
31
|
throw new Error(`IPSECKEY: Algorithm invalid, ${this.citeRFC()}`)
|
|
33
32
|
|
|
34
33
|
this.set('algorithm', val)
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
setGateway
|
|
38
|
-
const gwErr = new Error(
|
|
36
|
+
setGateway(val) {
|
|
37
|
+
const gwErr = new Error(
|
|
38
|
+
`IPSECKEY: gateway invalid (${val}), ${this.citeRFC()}`,
|
|
39
|
+
)
|
|
39
40
|
switch (this.get('gateway type')) {
|
|
40
|
-
case 0:
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
case 0:
|
|
42
|
+
if (val !== '.') throw gwErr
|
|
43
|
+
break
|
|
44
|
+
case 1:
|
|
45
|
+
if (!net.isIPv4(val)) throw gwErr
|
|
46
|
+
break
|
|
47
|
+
case 2:
|
|
48
|
+
if (!net.isIPv6(val)) throw gwErr
|
|
49
|
+
break
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
this.set('gateway', val)
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
setPublickey
|
|
55
|
+
setPublickey(val) {
|
|
49
56
|
// if (val) throw new Error(`IPSECKEY: publickey is optional, ${this.citeRFC()}`)
|
|
50
57
|
|
|
51
58
|
this.set('publickey', val)
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
getDescription
|
|
61
|
+
getDescription() {
|
|
55
62
|
return 'IPsec Keying'
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
getRdataFields
|
|
59
|
-
return [
|
|
65
|
+
getRdataFields(arg) {
|
|
66
|
+
return ['precedence', 'gateway type', 'algorithm', 'gateway', 'publickey']
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
getRFCs
|
|
63
|
-
return [
|
|
69
|
+
getRFCs() {
|
|
70
|
+
return [4025]
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
getTypeId
|
|
73
|
+
getTypeId() {
|
|
67
74
|
return 45
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
/****** IMPORTERS *******/
|
|
71
|
-
fromBind
|
|
78
|
+
fromBind(opts) {
|
|
72
79
|
// FQDN TTL CLASS IPSECKEY Precedence GatewayType Algorithm Gateway PublicKey
|
|
73
|
-
const [
|
|
80
|
+
const [owner, ttl, c, type, prec, gwt, algo, gateway, publickey] =
|
|
81
|
+
opts.bindline.split(/\s+/)
|
|
74
82
|
return new IPSECKEY({
|
|
75
83
|
owner,
|
|
76
|
-
ttl
|
|
77
|
-
class
|
|
84
|
+
ttl: parseInt(ttl, 10),
|
|
85
|
+
class: c,
|
|
78
86
|
type,
|
|
79
|
-
precedence
|
|
80
|
-
'gateway type': parseInt(gwt,
|
|
81
|
-
algorithm
|
|
87
|
+
precedence: parseInt(prec, 10),
|
|
88
|
+
'gateway type': parseInt(gwt, 10),
|
|
89
|
+
algorithm: parseInt(algo, 10),
|
|
82
90
|
gateway,
|
|
83
91
|
publickey,
|
|
84
92
|
})
|
|
85
93
|
}
|
|
86
94
|
|
|
87
|
-
fromTinydns
|
|
88
|
-
const [
|
|
95
|
+
fromTinydns(opts) {
|
|
96
|
+
const [fqdn, n, rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
|
|
89
97
|
if (n != 45) throw new Error('IPSECKEY fromTinydns, invalid n')
|
|
90
98
|
|
|
91
99
|
const precedence = TINYDNS.octalToUInt8(rdata.substring(0, 4))
|
|
92
|
-
const gwType
|
|
93
|
-
const algorithm
|
|
100
|
+
const gwType = TINYDNS.octalToUInt8(rdata.substring(4, 8))
|
|
101
|
+
const algorithm = TINYDNS.octalToUInt8(rdata.substring(8, 12))
|
|
94
102
|
|
|
95
103
|
let len, gateway, octalKey
|
|
96
104
|
|
|
97
105
|
switch (gwType) {
|
|
98
|
-
case 0:
|
|
99
|
-
gateway
|
|
106
|
+
case 0: // no gateway
|
|
107
|
+
gateway = rdata.substring(12, 13) // should always be: '.'
|
|
100
108
|
octalKey = rdata.substring(13)
|
|
101
109
|
break
|
|
102
|
-
case 1:
|
|
103
|
-
gateway
|
|
110
|
+
case 1: // 4-byte IPv4 address
|
|
111
|
+
gateway = TINYDNS.octalToIPv4(rdata.substring(12, 28))
|
|
104
112
|
octalKey = rdata.substring(28)
|
|
105
113
|
break
|
|
106
|
-
case 2:
|
|
107
|
-
gateway
|
|
114
|
+
case 2: // 16-byte IPv6
|
|
115
|
+
gateway = TINYDNS.octalToHex(rdata.substring(12, 76))
|
|
108
116
|
octalKey = rdata.substring(76)
|
|
109
117
|
break
|
|
110
|
-
case 3:
|
|
111
|
-
[
|
|
118
|
+
case 3: // wire encoded domain name
|
|
119
|
+
;[gateway, len] = TINYDNS.unpackDomainName(rdata.substring(12))
|
|
112
120
|
octalKey = rdata.substring(12 + len)
|
|
113
121
|
break
|
|
114
122
|
}
|
|
115
123
|
|
|
116
124
|
return new IPSECKEY({
|
|
117
|
-
owner
|
|
118
|
-
ttl
|
|
119
|
-
type
|
|
125
|
+
owner: this.fullyQualify(fqdn),
|
|
126
|
+
ttl: parseInt(ttl, 10),
|
|
127
|
+
type: 'IPSECKEY',
|
|
120
128
|
precedence,
|
|
121
129
|
'gateway type': gwType,
|
|
122
130
|
algorithm,
|
|
123
131
|
gateway,
|
|
124
|
-
publickey
|
|
125
|
-
timestamp
|
|
126
|
-
location
|
|
132
|
+
publickey: TINYDNS.octalToBase64(octalKey),
|
|
133
|
+
timestamp: ts,
|
|
134
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
127
135
|
})
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
/****** EXPORTERS *******/
|
|
131
139
|
|
|
132
|
-
toTinydns
|
|
140
|
+
toTinydns() {
|
|
133
141
|
const rdataRe = new RegExp(/[\r\n\t:\\/]/, 'g')
|
|
134
142
|
|
|
135
143
|
let rdata = ''
|
package/rr/key.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
|
|
2
1
|
import RR from '../rr.js'
|
|
3
2
|
|
|
4
3
|
export default class KEY extends RR {
|
|
5
|
-
constructor
|
|
4
|
+
constructor(opts) {
|
|
6
5
|
super(opts)
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
/****** Resource record specific setters *******/
|
|
10
|
-
setFlags
|
|
9
|
+
setFlags(val) {
|
|
11
10
|
// a 2 octet Flags Field
|
|
12
11
|
this.is16bitInt('KEY', 'flags', val)
|
|
13
12
|
|
|
14
13
|
this.set('flags', val)
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
setProtocol
|
|
16
|
+
setProtocol(val) {
|
|
18
17
|
// 1 octet
|
|
19
18
|
this.is8bitInt('KEY', 'protocol', val)
|
|
20
19
|
|
|
21
20
|
this.set('protocol', val)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
setAlgorithm
|
|
23
|
+
setAlgorithm(val) {
|
|
25
24
|
// 1 octet
|
|
26
25
|
// 1=RSA/MD5, 2=DH, 3=DSA/SHA-1, 4=EC, 5=RSA/SHA-1
|
|
27
|
-
if (![
|
|
26
|
+
if (![1, 2, 3, 4, 5, 253, 254].includes(val))
|
|
28
27
|
throw new Error(`KEY: algorithm invalid, ${this.citeRFC()}`)
|
|
29
28
|
|
|
30
29
|
this.set('algorithm', val)
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
setPublickey
|
|
32
|
+
setPublickey(val) {
|
|
34
33
|
if (!val) throw new Error(`KEY: publickey is required, ${this.citeRFC()}`)
|
|
35
34
|
|
|
36
35
|
this.set('publickey', val)
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
getDescription
|
|
38
|
+
getDescription() {
|
|
40
39
|
return 'DNS Public Key'
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
getRdataFields
|
|
44
|
-
return [
|
|
42
|
+
getRdataFields(arg) {
|
|
43
|
+
return ['flags', 'protocol', 'algorithm', 'publickey']
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
getRFCs
|
|
48
|
-
return [
|
|
46
|
+
getRFCs() {
|
|
47
|
+
return [2535, 3445]
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
getTypeId
|
|
50
|
+
getTypeId() {
|
|
52
51
|
return 25
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
/****** IMPORTERS *******/
|
|
56
55
|
|
|
57
|
-
fromBind
|
|
56
|
+
fromBind(opts) {
|
|
58
57
|
// test.example.com 3600 IN KEY Flags Protocol Algorithm PublicKey
|
|
59
|
-
const [
|
|
58
|
+
const [owner, ttl, c, type, flags, protocol, algorithm] =
|
|
59
|
+
opts.bindline.split(/\s+/)
|
|
60
60
|
return new KEY({
|
|
61
61
|
owner,
|
|
62
|
-
ttl
|
|
63
|
-
class
|
|
64
|
-
type
|
|
65
|
-
flags
|
|
66
|
-
protocol
|
|
67
|
-
algorithm: parseInt(algorithm,
|
|
62
|
+
ttl: parseInt(ttl, 10),
|
|
63
|
+
class: c,
|
|
64
|
+
type: type,
|
|
65
|
+
flags: parseInt(flags, 10),
|
|
66
|
+
protocol: parseInt(protocol, 10),
|
|
67
|
+
algorithm: parseInt(algorithm, 10),
|
|
68
68
|
publickey: opts.bindline.split(/\s+/).slice(7).join(' ').trim(),
|
|
69
69
|
})
|
|
70
70
|
}
|
package/rr/loc.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
1
|
import RR from '../rr.js'
|
|
3
2
|
import * as TINYDNS from '../lib/tinydns.js'
|
|
4
3
|
|
|
5
|
-
const REF = {
|
|
6
|
-
|
|
4
|
+
const REF = {
|
|
5
|
+
// RFC 1876
|
|
6
|
+
LATLON: 2 ** 31, // LAT equator, LON prime meridian
|
|
7
7
|
ALTITUDE: 100000 * 100, // reference spheroid used by GPS, in cm
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -14,12 +14,12 @@ const CONV = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export default class LOC extends RR {
|
|
17
|
-
constructor
|
|
17
|
+
constructor(opts) {
|
|
18
18
|
super(opts)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/****** Resource record specific setters *******/
|
|
22
|
-
setAddress
|
|
22
|
+
setAddress(val) {
|
|
23
23
|
if (!val) throw new Error('LOC: address is required')
|
|
24
24
|
|
|
25
25
|
/*
|
|
@@ -32,29 +32,29 @@ export default class LOC extends RR {
|
|
|
32
32
|
this.set('address', val)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
getDescription
|
|
35
|
+
getDescription() {
|
|
36
36
|
return 'Location'
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
getRdataFields
|
|
40
|
-
return [
|
|
39
|
+
getRdataFields(arg) {
|
|
40
|
+
return ['address']
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
getRFCs
|
|
44
|
-
return [
|
|
43
|
+
getRFCs() {
|
|
44
|
+
return [1876]
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
getTypeId
|
|
47
|
+
getTypeId() {
|
|
48
48
|
return 29
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
parseLoc
|
|
52
|
-
|
|
51
|
+
parseLoc(string) {
|
|
53
52
|
// d1 [m1 [s1]]
|
|
54
53
|
const dms = '(\\d+)\\s+(?:(\\d+)\\s+)?(?:([\\d.]+)\\s+)?'
|
|
55
54
|
|
|
56
55
|
// alt["m"] [siz["m"] [hp["m"] [vp["m"]]]]
|
|
57
|
-
const alt =
|
|
56
|
+
const alt =
|
|
57
|
+
'(-?[\\d.]+)m?(?:\\s+([\\d.]+)m?)?(?:\\s+([\\d.]+)m?)?(?:\\s+([\\d.]+)m?)?'
|
|
58
58
|
|
|
59
59
|
// put them all together
|
|
60
60
|
const locRe = new RegExp(`^${dms}(N|S)\\s+${dms}(E|W)\\s+${alt}`, 'i')
|
|
@@ -63,22 +63,22 @@ export default class LOC extends RR {
|
|
|
63
63
|
|
|
64
64
|
const loc = {
|
|
65
65
|
latitude: {
|
|
66
|
-
degrees
|
|
67
|
-
minutes
|
|
68
|
-
seconds
|
|
66
|
+
degrees: r[1],
|
|
67
|
+
minutes: r[2],
|
|
68
|
+
seconds: r[3],
|
|
69
69
|
hemisphere: r[4].toUpperCase(),
|
|
70
70
|
},
|
|
71
71
|
longitude: {
|
|
72
|
-
degrees
|
|
73
|
-
minutes
|
|
74
|
-
seconds
|
|
72
|
+
degrees: r[5],
|
|
73
|
+
minutes: r[6],
|
|
74
|
+
seconds: r[7],
|
|
75
75
|
hemisphere: r[8].toUpperCase(),
|
|
76
76
|
},
|
|
77
|
-
altitude
|
|
78
|
-
size
|
|
77
|
+
altitude: r[9] * 100, // m -> cm
|
|
78
|
+
size: r[10] * 100,
|
|
79
79
|
precision: {
|
|
80
80
|
horizontal: r[11] * 100,
|
|
81
|
-
vertical
|
|
81
|
+
vertical: r[12] * 100,
|
|
82
82
|
},
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -86,48 +86,61 @@ export default class LOC extends RR {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/****** IMPORTERS *******/
|
|
89
|
-
fromTinydns
|
|
89
|
+
fromTinydns(opts) {
|
|
90
90
|
// LOC via generic, :fqdn:n:rdata:ttl:timestamp:lo
|
|
91
|
-
const [
|
|
91
|
+
const [fqdn, n, rdata, ttl, ts, loc] = opts.tinyline.substring(1).split(':')
|
|
92
92
|
if (n != 29) throw new Error('LOC fromTinydns, invalid n')
|
|
93
93
|
|
|
94
94
|
// divide by 100 is to convert cm to meters
|
|
95
95
|
const l = {
|
|
96
|
-
version
|
|
97
|
-
size
|
|
96
|
+
version: TINYDNS.octalToUInt8(rdata.substring(0, 4)),
|
|
97
|
+
size: this.fromExponent(TINYDNS.octalToUInt8(rdata.substring(4, 8))),
|
|
98
98
|
precision: {
|
|
99
|
-
horizontal: this.fromExponent(
|
|
100
|
-
|
|
99
|
+
horizontal: this.fromExponent(
|
|
100
|
+
TINYDNS.octalToUInt8(rdata.substring(8, 12)),
|
|
101
|
+
),
|
|
102
|
+
vertical: this.fromExponent(
|
|
103
|
+
TINYDNS.octalToUInt8(rdata.substring(12, 16)),
|
|
104
|
+
),
|
|
101
105
|
},
|
|
102
|
-
latitude
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
latitude: this.arcSecToDMS(
|
|
107
|
+
TINYDNS.octalToUInt32(rdata.substring(16, 32)),
|
|
108
|
+
'lat',
|
|
109
|
+
),
|
|
110
|
+
longitude: this.arcSecToDMS(
|
|
111
|
+
TINYDNS.octalToUInt32(rdata.substring(32, 48)),
|
|
112
|
+
'lon',
|
|
113
|
+
),
|
|
114
|
+
altitude: TINYDNS.octalToUInt32(rdata.substring(48, 64)) - REF.ALTITUDE,
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
return new LOC({
|
|
108
|
-
type
|
|
109
|
-
owner
|
|
110
|
-
address
|
|
111
|
-
ttl
|
|
118
|
+
type: 'LOC',
|
|
119
|
+
owner: this.fullyQualify(fqdn),
|
|
120
|
+
address: this.toHuman(l),
|
|
121
|
+
ttl: parseInt(ttl, 10),
|
|
112
122
|
timestamp: ts,
|
|
113
|
-
location
|
|
123
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
114
124
|
})
|
|
115
125
|
}
|
|
116
126
|
|
|
117
|
-
fromBind
|
|
118
|
-
const [
|
|
127
|
+
fromBind(opts) {
|
|
128
|
+
const [owner, ttl, c, type] = opts.bindline.split(/\s+/)
|
|
119
129
|
|
|
120
130
|
return new LOC({
|
|
121
131
|
owner,
|
|
122
|
-
ttl
|
|
123
|
-
class
|
|
124
|
-
type
|
|
132
|
+
ttl: parseInt(ttl, 10),
|
|
133
|
+
class: c,
|
|
134
|
+
type: type,
|
|
125
135
|
address: opts.bindline.split(/\s+/).slice(4).join(' ').trim(),
|
|
126
136
|
})
|
|
127
137
|
}
|
|
128
138
|
|
|
129
|
-
dmsToArcSec
|
|
130
|
-
let retval =
|
|
139
|
+
dmsToArcSec(obj) {
|
|
140
|
+
let retval =
|
|
141
|
+
obj.degrees * CONV.deg +
|
|
142
|
+
(obj.minutes || 0) * CONV.min +
|
|
143
|
+
(obj.seconds || 0) * CONV.sec
|
|
131
144
|
switch (obj.hemisphere.toUpperCase()) {
|
|
132
145
|
case 'W':
|
|
133
146
|
case 'S':
|
|
@@ -138,7 +151,7 @@ export default class LOC extends RR {
|
|
|
138
151
|
return retval
|
|
139
152
|
}
|
|
140
153
|
|
|
141
|
-
arcSecToDMS
|
|
154
|
+
arcSecToDMS(rawmsec, latlon) {
|
|
142
155
|
let msec = Math.abs(rawmsec - REF.LATLON)
|
|
143
156
|
// console.log(`rawmsec: ${rawmsec}, abs msec: ${msec}`)
|
|
144
157
|
|
|
@@ -163,16 +176,16 @@ export default class LOC extends RR {
|
|
|
163
176
|
throw new Error('unknown or missing hemisphere')
|
|
164
177
|
}
|
|
165
178
|
|
|
166
|
-
return `${deg} ${min} ${sec}${msec ? '.'+msec : ''} ${hem}`
|
|
179
|
+
return `${deg} ${min} ${sec}${msec ? '.' + msec : ''} ${hem}`
|
|
167
180
|
}
|
|
168
181
|
|
|
169
|
-
fromExponent
|
|
182
|
+
fromExponent(prec) {
|
|
170
183
|
const mantissa = ((prec >> 4) & 0x0f) % 10
|
|
171
184
|
const exponent = ((prec >> 0) & 0x0f) % 10
|
|
172
185
|
return mantissa * Math.pow(10, exponent)
|
|
173
186
|
}
|
|
174
187
|
|
|
175
|
-
toExponent
|
|
188
|
+
toExponent(val) {
|
|
176
189
|
/*
|
|
177
190
|
RFC 1876, ... expressed as a pair of four-bit unsigned
|
|
178
191
|
integers, each ranging from zero to nine, with the most
|
|
@@ -188,22 +201,22 @@ export default class LOC extends RR {
|
|
|
188
201
|
return (parseInt(val) << 4) | (exponent & 0x0f)
|
|
189
202
|
}
|
|
190
203
|
|
|
191
|
-
toHuman
|
|
192
|
-
let r = `${obj.latitude} ${obj.longitude} ${
|
|
193
|
-
if (obj.size)
|
|
204
|
+
toHuman(obj) {
|
|
205
|
+
let r = `${obj.latitude} ${obj.longitude} ${obj.altitude / 100}m`
|
|
206
|
+
if (obj.size) r += ` ${obj.size / 100}m`
|
|
194
207
|
if (obj.precision.horizontal) r += ` ${obj.precision.horizontal / 100}m`
|
|
195
|
-
if (obj.precision.vertical
|
|
208
|
+
if (obj.precision.vertical) r += ` ${obj.precision.vertical / 100}m`
|
|
196
209
|
return r
|
|
197
210
|
}
|
|
198
211
|
|
|
199
212
|
/****** EXPORTERS *******/
|
|
200
213
|
|
|
201
|
-
toTinydns
|
|
214
|
+
toTinydns() {
|
|
202
215
|
const loc = this.parseLoc(this.get('address'))
|
|
203
216
|
|
|
204
217
|
// LOC format declares in meters, tinydns uses cm (hence * 100)
|
|
205
218
|
let rdata = ''
|
|
206
|
-
rdata += TINYDNS.UInt8toOctal(0)
|
|
219
|
+
rdata += TINYDNS.UInt8toOctal(0) // version
|
|
207
220
|
rdata += TINYDNS.UInt8toOctal(this.toExponent(loc.size))
|
|
208
221
|
rdata += TINYDNS.UInt8toOctal(this.toExponent(loc.precision.horizontal))
|
|
209
222
|
rdata += TINYDNS.UInt8toOctal(this.toExponent(loc.precision.vertical))
|
package/rr/mx.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
1
|
import net from 'net'
|
|
3
2
|
|
|
4
3
|
import RR from '../rr.js'
|
|
5
4
|
|
|
6
5
|
export default class MX extends RR {
|
|
7
|
-
constructor
|
|
6
|
+
constructor(opts) {
|
|
8
7
|
super(opts)
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
/****** Resource record specific setters *******/
|
|
12
|
-
setPreference
|
|
11
|
+
setPreference(val) {
|
|
13
12
|
if (val === undefined) val = this?.default?.preference
|
|
14
13
|
this.is16bitInt('MX', 'preference', val)
|
|
15
14
|
this.set('preference', val)
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
setExchange
|
|
17
|
+
setExchange(val) {
|
|
19
18
|
if (!val) throw new Error('MX: exchange is required')
|
|
20
19
|
|
|
21
20
|
if (net.isIPv4(val) || net.isIPv6(val))
|
|
@@ -28,47 +27,50 @@ export default class MX extends RR {
|
|
|
28
27
|
this.set('exchange', val.toLowerCase())
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
getDescription
|
|
30
|
+
getDescription() {
|
|
32
31
|
return 'Mail Exchanger'
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
getRdataFields
|
|
36
|
-
return [
|
|
34
|
+
getRdataFields(arg) {
|
|
35
|
+
return ['preference', 'exchange']
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
getRFCs
|
|
40
|
-
return [
|
|
38
|
+
getRFCs() {
|
|
39
|
+
return [1035, 2181, 7505]
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
getTypeId
|
|
42
|
+
getTypeId() {
|
|
44
43
|
return 15
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
/****** IMPORTERS *******/
|
|
48
|
-
fromTinydns
|
|
47
|
+
fromTinydns(opts) {
|
|
49
48
|
// @fqdn:ip:x:dist:ttl:timestamp:lo
|
|
50
49
|
// eslint-disable-next-line no-unused-vars
|
|
51
|
-
const [
|
|
50
|
+
const [owner, ip, x, preference, ttl, ts, loc] = opts.tinyline
|
|
51
|
+
.substring(1)
|
|
52
|
+
.split(':')
|
|
52
53
|
|
|
53
54
|
return new MX({
|
|
54
|
-
type
|
|
55
|
-
owner
|
|
56
|
-
exchange
|
|
55
|
+
type: 'MX',
|
|
56
|
+
owner: this.fullyQualify(owner),
|
|
57
|
+
exchange: this.fullyQualify(/\./.test(x) ? x : `${x}.mx.${owner}`),
|
|
57
58
|
preference: parseInt(preference, 10) || 0,
|
|
58
|
-
ttl
|
|
59
|
-
timestamp
|
|
60
|
-
location
|
|
59
|
+
ttl: parseInt(ttl, 10),
|
|
60
|
+
timestamp: ts,
|
|
61
|
+
location: loc !== '' && loc !== '\n' ? loc : '',
|
|
61
62
|
})
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
fromBind
|
|
65
|
+
fromBind(opts) {
|
|
65
66
|
// test.example.com 3600 IN MX preference exchange
|
|
66
|
-
const [
|
|
67
|
+
const [owner, ttl, c, type, preference, exchange] =
|
|
68
|
+
opts.bindline.split(/\s+/)
|
|
67
69
|
|
|
68
70
|
return new MX({
|
|
69
71
|
owner,
|
|
70
|
-
ttl
|
|
71
|
-
class
|
|
72
|
+
ttl: parseInt(ttl, 10),
|
|
73
|
+
class: c,
|
|
72
74
|
type,
|
|
73
75
|
preference: parseInt(preference),
|
|
74
76
|
exchange,
|
|
@@ -76,11 +78,11 @@ export default class MX extends RR {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/****** EXPORTERS *******/
|
|
79
|
-
toBind
|
|
81
|
+
toBind(zone_opts) {
|
|
80
82
|
return `${this.getPrefix(zone_opts)}\t${this.get('preference')}\t${this.getFQDN('exchange', zone_opts)}\n`
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
toTinydns
|
|
85
|
+
toTinydns() {
|
|
84
86
|
return `@${this.getTinyFQDN('owner')}::${this.getTinyFQDN('exchange')}:${this.get('preference')}:${this.getTinydnsPostamble()}\n`
|
|
85
87
|
}
|
|
86
88
|
}
|