fix RP handling
This commit is contained in:
parent
4e25954bb4
commit
b5c0ab3161
@ -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'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
26
index.js
26
index.js
@ -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 = {}
|
||||||
|
|||||||
7
test.js
7
test.js
@ -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()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user