Skip to content

Commit

Permalink
Release 1.0.1 (#28)
Browse files Browse the repository at this point in the history
- feat(IPSECKEY): added basic support
- doc(README): update for ES module usage
- fix: call is[8|16]BitInt() correctly
- style: replace this.constructor with class name
- test: show more results in test output
- test(CERT): added two test cases
- test(KEY): added valid test
  • Loading branch information
msimerson authored Apr 20, 2022
1 parent c6c64ca commit e861565
Show file tree
Hide file tree
Showing 36 changed files with 287 additions and 101 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@

#### 1.N.N - YYYY-MM-DD

#### 1.0.1 - 2022-04-19

- feat(IPSECKEY): added basic support
- doc(README): update for ES module usage
- fix: call is[8|16]BitInt() correctly
- style: replace this.constructor with class name
- test: show more results in test output
- test(CERT): added two test cases
- test(KEY): added valid test


#### 1.0.0 - 2022-04-18

- style: move rr/index to ./rr
Expand Down
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,27 @@ This package is for working with _individual_ Resource Records. For working with
Load the index for access to all RR types:

```js
const RR = require('dns-resource-record')
import * as RR from 'dns-resource-record'
```

### EXAMPLES

```js
const RR = require('dns-resource-record')
const exampleRRs = {
A: {
owner : 'test.example.com',
owner : 'test.example.com.',
type : 'A',
address: '192.0.2.127',
ttl : 3600,
},
AAAA: {
owner : 'test.example.com',
owner : 'test.example.com.',
type : 'AAAA',
address: '2605:7900:20:a::4',
ttl : 3600,
},
SOA: {
owner : 'example.com',
owner : 'example.com.',
type : 'SOA',
mname : 'matt.example.com.',
rname : 'ns1.example.com.',
Expand All @@ -69,7 +68,7 @@ const exampleRRs = {
try {
console.log(new RR.SOA(exampleRRs.SOA))
SOA(11) [Map] {
'owner' => 'example.com',
'owner' => 'example.com.',
'ttl' => 3600,
'class' => 'IN',
'type' => 'SOA',
Expand All @@ -90,19 +89,18 @@ catch (e) {
Validate records by passing a properly formatted JS object to the record-specific class. To validate an A record:

```js
const A = require('dns-resource-record').A
const validatedA = new A(exampleRRs.A)
const validatedA = new RR.A(exampleRRs.A)
```

Manipulate the validated record using pattern named setters:

```js
console.log(validatedA.toBind())
test.example.com 3600 IN A 192.0.2.127
test.example.com. 3600 IN A 192.0.2.127

validatedA.setAddress('192.0.2.128')
console.log(validatedA.toBind())
test.example.com 3600 IN A 192.0.2.128
test.example.com. 3600 IN A 192.0.2.128
```

The setters are named: `set` + `Field`, where field is the resource record field name to modify. Multi-word names are camel cased, so a field named `Certificate Usage` has a setter named `setCertificateUsage`. The RFCs aren't always consistent regarding RR field names so aliases are permissible for interoperability.
Expand All @@ -112,7 +110,7 @@ The setters are named: `set` + `Field`, where field is the resource record field
Get the field names for each RR type with `getFields()`:

```js
> const RR = require('dns-resource-record')
> import * as RR from 'dns-resource-record'
> new RR.A(null).getFields()
[ 'owner', 'ttl', 'class', 'type', 'address' ]

Expand Down Expand Up @@ -203,7 +201,7 @@ PRs are welcome, especially PRs with tests.
| **DNSKEY** |:white_check_mark:| |:white_check_mark:| |
| **DS** |:white_check_mark:| |:white_check_mark:| |
| **HINFO** |:white_check_mark:| |:white_check_mark:| |
|**IPSECKEY**| | | | |
|**IPSECKEY**|:white_check_mark:| |:white_check_mark:| |
| **KEY** | | | | |
| **LOC** |:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
| **MX** |:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:|
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import DNAME from './rr/dname.js'
import DNSKEY from './rr/dnskey.js'
import DS from './rr/ds.js'
import HINFO from './rr/hinfo.js'
import IPSECKEY from './rr/ipseckey.js'
import KEY from './rr/key.js'
import LOC from './rr/loc.js'
import MX from './rr/mx.js'
Expand Down Expand Up @@ -42,6 +43,7 @@ export {
DNSKEY,
DS,
HINFO,
IPSECKEY,
KEY,
LOC,
MX,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dns-resource-record",
"version": "1.0.0",
"version": "1.0.1",
"description": "DNS Resource Records",
"main": "index.js",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions rr/aaaa.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class AAAA extends RR {
break
}

return new this.constructor({
return new AAAA({
owner : this.fullyQualify(fqdn),
ttl : parseInt(ttl, 10),
type : 'AAAA',
Expand All @@ -70,7 +70,7 @@ export default class AAAA extends RR {
fromBind (str) {
// test.example.com 3600 IN AAAA ...
const [ owner, ttl, c, type, ip ] = str.split(/\s+/)
return new this.constructor({
return new AAAA({
owner,
ttl : parseInt(ttl, 10),
class : c,
Expand Down
4 changes: 2 additions & 2 deletions rr/caa.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class CAA extends RR {
const tag = unescaped.substring(0, taglen)
const fingerprint = unescaped.substring(taglen)

return new this.constructor({
return new CAA({
owner : this.fullyQualify(fqdn),
ttl : parseInt(ttl, 10),
type : 'CAA',
Expand All @@ -102,7 +102,7 @@ export default class CAA extends RR {
if (!fields) throw new Error(`unable to parse: ${str}`)

const [ owner, ttl, c, type, flags, tag, value ] = fields.slice(1)
return new this.constructor({
return new CAA({
owner,
ttl : parseInt(ttl, 10),
class: c,
Expand Down
14 changes: 9 additions & 5 deletions rr/cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class CERT extends RR {
}

getRFCs () {
return [ 4398 ]
return [ 2538, 4398 ]
}

getTypeId () {
Expand All @@ -58,12 +58,16 @@ export default class CERT extends RR {

fromBind (str) {
// test.example.com 3600 IN CERT certtype, keytag, algo, cert
const [ owner, ttl, c, type ] = str.split(/\s+/)
return new this.constructor({
const [ owner, ttl, c, type, certtype, keytag, algo, certificate ] = str.split(/\s+/)
return new CERT({
owner,
ttl : parseInt(ttl, 10),
class: c,
ttl : parseInt(ttl, 10),
class : c,
type,
'cert type': /^[0-9]+$/.test(certtype) ? parseInt(certtype, 10) : certtype,
'key tag' : parseInt(keytag, 10),
algorithm : parseInt(algo, 10),
certificate,
})
}

Expand Down
4 changes: 2 additions & 2 deletions rr/cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class CNAME extends RR {
// Cfqdn:p:ttl:timestamp:lo
const [ fqdn, p, ttl, ts, loc ] = str.substring(1).split(':')

return new this.constructor({
return new CNAME({
owner : this.fullyQualify(fqdn),
ttl : parseInt(ttl, 10),
type : 'CNAME',
Expand All @@ -59,7 +59,7 @@ export default class CNAME extends RR {
fromBind (str) {
// test.example.com 3600 IN CNAME ...
const [ owner, ttl, c, type, cname ] = str.split(/\s+/)
return new this.constructor({
return new CNAME({
owner,
ttl : parseInt(ttl, 10),
class: c,
Expand Down
4 changes: 2 additions & 2 deletions rr/dname.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class DNAME extends RR {
const [ fqdn, n, rdata, ttl, ts, loc ] = str.substring(1).split(':')
if (n != 39) throw new Error('DNAME fromTinydns, invalid n')

return new this.constructor({
return new DNAME({
type : 'DNAME',
owner : this.fullyQualify(fqdn),
target : `${TINYDNS.unpackDomainName(rdata)}.`,
Expand All @@ -57,7 +57,7 @@ export default class DNAME extends RR {
fromBind (str) {
// test.example.com 3600 IN DNAME ...
const [ owner, ttl, c, type, target ] = str.split(/\s+/)
return new this.constructor({
return new DNAME({
owner,
ttl : parseInt(ttl, 10),
class: c,
Expand Down
2 changes: 1 addition & 1 deletion rr/dnskey.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class DNSKEY extends RR {
if (!match) throw new Error(`unable to parse DNSKEY: ${str}`)
const [ owner, ttl, c, type, flags, protocol, algorithm, publickey ] = match.slice(1)

return new this.constructor({
return new DNSKEY({
owner,
ttl : parseInt(ttl, 10),
class : c,
Expand Down
2 changes: 1 addition & 1 deletion rr/ds.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class DS extends RR {
fromBind (str) {
// test.example.com 3600 IN DS Key Tag Algorithm, Digest Type, Digest
const [ owner, ttl, c, type, keytag, algorithm, digesttype ] = str.split(/\s+/)
return new this.constructor({
return new DS({
owner,
ttl : parseInt(ttl, 10),
class : c,
Expand Down
5 changes: 2 additions & 3 deletions rr/hinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ export default class HINFO extends RR {
if (!match) throw new Error(`unable to parse HINFO: ${str}`)
const [ owner, ttl, c, type, cpu, os ] = match.slice(1)

const bits = {
return new HINFO({
owner,
ttl : parseInt(ttl, 10),
class: c,
type,
cpu,
os,
}
return new this.constructor(bits)
})
}

// fromTinydns (str) {
Expand Down
81 changes: 81 additions & 0 deletions rr/ipseckey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

import RR from '../rr.js'

export default class IPSECKEY extends RR {
constructor (opts) {
super(opts)
}

/****** Resource record specific setters *******/
setPrecedence (val) {
// an 8-bit precedence for this record.
this.is8bitInt('IPSECKEY', 'precedence', val)

this.set('precedence', val)
}

setGatewayType (val) {
// 0 (none), 1 (4-byte IPv4), 2 (16-byte IPv6), 3 (wire encoded domain name)
if (![ 0,1,2,3 ].includes(val))
throw new Error(`IPSECKEY: Gateway Type is invalid, ${this.citeRFC()}`)

this.set('gateway type', val)
}

setAlgorithm (val) {
// unsigned int, 1 octet, values: 1=DSA, 2=RSA
if (![ 1,2 ].includes(val))
throw new Error(`IPSECKEY: Algorithm invalid, ${this.citeRFC()}`)

this.set('algorithm', val)
}

setGateway (val) {
if (this.get('gateway') === 0 && val !== '.')
throw new Error(`IPSECKEY: gateway invalid, ${this.citeRFC()}`)

this.set('gateway', val)
}

setPublickey (val) {
if (!val) throw new Error(`IPSECKEY: publickey is required, ${this.citeRFC()}`)

this.set('publickey', val)
}

getDescription () {
return 'IPsec Keying'
}

getRdataFields (arg) {
return [ 'precedence', 'gateway type', 'algorithm', 'gateway', 'publickey' ]
}

getRFCs () {
return [ 4025 ]
}

getTypeId () {
return 45
}

/****** IMPORTERS *******/

fromBind (str) {
// FQDN TTL CLASS IPSECKEY Precedence GatewayType Algorithm Gateway PublicKey
const [ owner, ttl, c, type, prec, gwt, algo, gateway, publickey ] = str.split(/\s+/)
return new IPSECKEY({
owner,
ttl : parseInt(ttl, 10),
class : c,
type,
precedence : parseInt(prec, 10),
'gateway type': parseInt(gwt, 10),
algorithm : parseInt(algo, 10),
gateway,
publickey,
})
}

/****** EXPORTERS *******/
}
8 changes: 4 additions & 4 deletions rr/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export default class KEY extends RR {
/****** Resource record specific setters *******/
setFlags (val) {
// a 2 octet Flags Field
this.is16bitInt(val)
this.is16bitInt('KEY', 'flags', val)

this.set('flags', val)
}

setProtocol (val) {
// 1 octet
this.is8bitInt(val)
this.is8bitInt('KEY', 'protocol', val)

this.set('protocol', val)
}
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class KEY extends RR {
}

getRFCs () {
return [ 2535 ]
return [ 2535, 3445 ]
}

getTypeId () {
Expand All @@ -57,7 +57,7 @@ export default class KEY extends RR {
fromBind (str) {
// test.example.com 3600 IN KEY Flags Protocol Algorithm PublicKey
const [ owner, ttl, c, type, flags, protocol, algorithm ] = str.split(/\s+/)
return new this.constructor({
return new KEY({
owner,
ttl : parseInt(ttl, 10),
class : c,
Expand Down
4 changes: 2 additions & 2 deletions rr/loc.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class LOC extends RR {
altitude : TINYDNS.octalToUInt32(rdata.substring(48, 64)) - REF.ALTITUDE,
}

return new this.constructor({
return new LOC({
type : 'LOC',
owner : this.fullyQualify(fqdn),
address : this.toHuman(l),
Expand All @@ -117,7 +117,7 @@ export default class LOC extends RR {
fromBind (str) {
const [ owner, ttl, c, type ] = str.split(/\s+/)

return new this.constructor({
return new LOC({
owner,
ttl : parseInt(ttl, 10),
class : c,
Expand Down
Loading

0 comments on commit e861565

Please sign in to comment.