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
{
mbox: mbox-dname,
txt: txt-dname
mbox: 'admin.example.com',
txt: 'txt.example.com'
}
```

View File

@ -881,15 +881,17 @@ rrrsig.encodingLength = function (sig) {
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
const oldOffset = offset
string.encode(data.mbox, buf, offset)
offset += string.encode.bytes
string.encode(data.txt, buf, offset)
rrp.encode.bytes = rrp.encodingLength(data)
offset += 2 // Leave space for length
name.encode(data.mbox || '.', buf, offset)
offset += name.encode.bytes
name.encode(data.txt || '.', buf, offset)
offset += name.encode.bytes
rrp.encode.bytes = offset - oldOffset
buf.writeUInt16BE(rrp.encode.bytes - 2, oldOffset)
return buf
}
@ -897,15 +899,13 @@ 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
offset += 2
data.mbox = name.decode(buf, offset) || '.'
offset += name.decode.bytes
data.txt = name.decode(buf, offset) || '.'
rrp.decode.bytes = offset - oldOffset
return data
}
@ -913,7 +913,7 @@ rrp.decode = function (buf, offset) {
rrp.decode.bytes = 0
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 = {}

View File

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