add support for encoding RP records

This commit is contained in:
Floyd Pink 2019-01-09 22:39:15 -05:00 committed by silverwind
parent 003cbeca51
commit 4e25954bb4
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
3 changed files with 59 additions and 0 deletions

View File

@ -289,6 +289,15 @@ And an answer, additional, or authority looks like this
} }
``` ```
#### `RP`
``` js
{
mbox: mbox-dname,
txt: txt-dname
}
```
#### `SOA` #### `SOA`
``` js ``` js

View File

@ -878,6 +878,44 @@ rrrsig.encodingLength = function (sig) {
Buffer.byteLength(sig.signature) Buffer.byteLength(sig.signature)
} }
const rrp = exports.rp = {}
rrp.encode = function (data, buf, offset) {
data.txt = data.txt || '.'
if (!buf) buf = Buffer.allocUnsafe(rrp.encodingLength(data))
if (!offset) offset = 0
string.encode(data.mbox, buf, offset)
offset += string.encode.bytes
string.encode(data.txt, buf, offset)
rrp.encode.bytes = rrp.encodingLength(data)
return buf
}
rrp.encode.bytes = 0
rrp.decode = function (buf, offset) {
if (!offset) offset = 0
const oldOffset = offset
const data = {}
data.mbox = string.decode(buf, offset)
offset += string.decode.bytes
data.txt = string.decode(buf, offset)
offset += string.decode.bytes
rrp.decode.bytes = offset - oldOffset
return data
}
rrp.decode.bytes = 0
rrp.encodingLength = function (data) {
return string.encodingLength(data.mbox || data) + string.encodingLength(data.txt || '.') + 2
}
const typebitmap = {} const typebitmap = {}
typebitmap.encode = function (typelist, buf, offset) { typebitmap.encode = function (typelist, buf, offset) {
@ -1152,6 +1190,7 @@ const renc = exports.record = function (type) {
case 'OPT': return ropt case 'OPT': return ropt
case 'DNSKEY': return rdnskey case 'DNSKEY': return rdnskey
case 'RRSIG': return rrrsig case 'RRSIG': return rrrsig
case 'RP': return rrp
case 'NSEC': return rnsec case 'NSEC': return rnsec
case 'NSEC3': return rnsec3 case 'NSEC3': return rnsec3
case 'DS': return rds case 'DS': return rds

11
test.js
View File

@ -399,6 +399,17 @@ tape('rrsig', function (t) {
t.end() t.end()
}) })
tape('rrp', function (t) {
testEncoder(t, packet.rp, {
mbox: 'rp.world.com',
txt: 'hello'
})
testEncoder(t, packet.rp, {
mbox: 'rp.world.com'
})
t.end()
})
tape('nsec', function (t) { tape('nsec', function (t) {
testEncoder(t, packet.nsec, { testEncoder(t, packet.nsec, {
nextDomain: 'foo.com', nextDomain: 'foo.com',