fix RP handling

This commit is contained in:
silverwind 2019-01-22 22:37:33 +01:00
parent 4e25954bb4
commit b5c0ab3161
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
3 changed files with 19 additions and 18 deletions

View File

@ -293,8 +293,8 @@ And an answer, additional, or authority looks like this
``` js ``` js
{ {
mbox: mbox-dname, mbox: 'admin.example.com',
txt: txt-dname txt: 'txt.example.com'
} }
``` ```

View File

@ -881,15 +881,17 @@ rrrsig.encodingLength = function (sig) {
const rrp = exports.rp = {} const rrp = exports.rp = {}
rrp.encode = function (data, buf, offset) { rrp.encode = function (data, buf, offset) {
data.txt = data.txt || '.'
if (!buf) buf = Buffer.allocUnsafe(rrp.encodingLength(data)) if (!buf) buf = Buffer.allocUnsafe(rrp.encodingLength(data))
if (!offset) offset = 0 if (!offset) offset = 0
const oldOffset = offset
string.encode(data.mbox, buf, offset) offset += 2 // Leave space for length
offset += string.encode.bytes name.encode(data.mbox || '.', buf, offset)
string.encode(data.txt, buf, offset) offset += name.encode.bytes
name.encode(data.txt || '.', buf, offset)
rrp.encode.bytes = rrp.encodingLength(data) offset += name.encode.bytes
rrp.encode.bytes = offset - oldOffset
buf.writeUInt16BE(rrp.encode.bytes - 2, oldOffset)
return buf return buf
} }
@ -897,15 +899,13 @@ rrp.encode.bytes = 0
rrp.decode = function (buf, offset) { rrp.decode = function (buf, offset) {
if (!offset) offset = 0 if (!offset) offset = 0
const oldOffset = offset const oldOffset = offset
const data = {} const data = {}
data.mbox = string.decode(buf, offset) offset += 2
offset += string.decode.bytes data.mbox = name.decode(buf, offset) || '.'
data.txt = string.decode(buf, offset) offset += name.decode.bytes
offset += string.decode.bytes data.txt = name.decode(buf, offset) || '.'
rrp.decode.bytes = offset - oldOffset rrp.decode.bytes = offset - oldOffset
return data return data
} }
@ -913,7 +913,7 @@ rrp.decode = function (buf, offset) {
rrp.decode.bytes = 0 rrp.decode.bytes = 0
rrp.encodingLength = function (data) { rrp.encodingLength = function (data) {
return string.encodingLength(data.mbox || data) + string.encodingLength(data.txt || '.') + 2 return 2 + name.encodingLength(data.mbox) + name.encodingLength(data.txt || '.')
} }
const typebitmap = {} const typebitmap = {}

View File

@ -401,11 +401,12 @@ tape('rrsig', function (t) {
tape('rrp', function (t) { tape('rrp', function (t) {
testEncoder(t, packet.rp, { testEncoder(t, packet.rp, {
mbox: 'rp.world.com', mbox: 'foo.bar.com',
txt: 'hello' txt: 'baz.bar.com'
}) })
testEncoder(t, packet.rp, { testEncoder(t, packet.rp, {
mbox: 'rp.world.com' mbox: 'rp.world.com',
txt: '.'
}) })
t.end() t.end()
}) })