From 4e25954bb410049b40ce21c7107534642d85c440 Mon Sep 17 00:00:00 2001 From: Floyd Pink Date: Wed, 9 Jan 2019 22:39:15 -0500 Subject: [PATCH] add support for encoding RP records --- README.md | 9 +++++++++ index.js | 39 +++++++++++++++++++++++++++++++++++++++ test.js | 11 +++++++++++ 3 files changed, 59 insertions(+) diff --git a/README.md b/README.md index 78a51dd..00f02a1 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,15 @@ And an answer, additional, or authority looks like this } ``` +#### `RP` + +``` js +{ + mbox: mbox-dname, + txt: txt-dname +} +``` + #### `SOA` ``` js diff --git a/index.js b/index.js index 0eed92e..fb6e171 100644 --- a/index.js +++ b/index.js @@ -878,6 +878,44 @@ rrrsig.encodingLength = function (sig) { 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 = {} typebitmap.encode = function (typelist, buf, offset) { @@ -1152,6 +1190,7 @@ const renc = exports.record = function (type) { case 'OPT': return ropt case 'DNSKEY': return rdnskey case 'RRSIG': return rrrsig + case 'RP': return rrp case 'NSEC': return rnsec case 'NSEC3': return rnsec3 case 'DS': return rds diff --git a/test.js b/test.js index a38146e..936eae8 100644 --- a/test.js +++ b/test.js @@ -399,6 +399,17 @@ tape('rrsig', function (t) { 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) { testEncoder(t, packet.nsec, { nextDomain: 'foo.com',