diff --git a/lib/dns/resource.js b/lib/dns/resource.js index dbf3a78fd3..c4afd15dd8 100644 --- a/lib/dns/resource.js +++ b/lib/dns/resource.js @@ -349,11 +349,11 @@ class Resource extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(Array.isArray(json.records)); + assert(json && typeof json === 'object', 'Invalid json.'); + assert(Array.isArray(json.records), 'Invalid records.'); for (const item of json.records) { - assert(item && typeof item === 'object'); + assert(item && typeof item === 'object', 'Invalid record.'); const RD = stringToClass(item.type); @@ -437,13 +437,17 @@ class DS extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(json.type === 'DS'); - assert((json.keyTag & 0xffff) === json.keyTag); - assert((json.algorithm & 0xff) === json.algorithm); - assert((json.digestType & 0xff) === json.digestType); - assert(typeof json.digest === 'string'); - assert((json.digest.length >>> 1) <= 255); + assert(json && typeof json === 'object', 'Invalid json in DS record.'); + assert(json.type === 'DS', 'Invalid type in DS record.'); + assert((json.keyTag & 0xffff) === json.keyTag, + 'Invalid keyTag in DS record.'); + assert((json.algorithm & 0xff) === json.algorithm, + 'Invalid algorithm in DS record.'); + assert((json.digestType & 0xff) === json.digestType, + 'Invalid digestType in DS record.'); + assert(typeof json.digest === 'string', 'Invalid digest in DS record.'); + assert((json.digest.length >>> 1) <= 255, + 'Invalid digest length in DS record.'); this.keyTag = json.keyTag; this.algorithm = json.algorithm; @@ -495,9 +499,9 @@ class NS extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(json.type === 'NS'); - assert(isName(json.ns)); + assert(json && typeof json === 'object', 'Invalid json in NS record.'); + assert(json.type === 'NS', 'Invalid type in NS record.'); + assert(isName(json.ns), 'Invalid ns in NS record.'); this.ns = json.ns; @@ -554,10 +558,10 @@ class GLUE4 extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(json.type === 'GLUE4'); - assert(isName(json.ns)); - assert(IP.isIPv4String(json.address)); + assert(json && typeof json === 'object', 'Invalid json in GLUE4 record.'); + assert(json.type === 'GLUE4', 'Invalid type in GLUE4 record.'); + assert(isName(json.ns), 'Invalid ns in GLUE4 record.'); + assert(IP.isIPv4String(json.address), 'Invalid address in GLUE4 record.'); this.ns = json.ns; this.address = IP.normalize(json.address); @@ -615,10 +619,10 @@ class GLUE6 extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(json.type === 'GLUE6'); - assert(isName(json.ns)); - assert(IP.isIPv6String(json.address)); + assert(json && typeof json === 'object', 'Invalid JSON in GLUE6 record.'); + assert(json.type === 'GLUE6', 'Invalid type in GLUE6 record.'); + assert(isName(json.ns), 'Invalid ns in GLUE6 record.'); + assert(IP.isIPv6String(json.address), 'Invalid address in GLUE6 record.'); this.ns = json.ns; this.address = IP.normalize(json.address); @@ -677,9 +681,9 @@ class SYNTH4 extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(json.type === 'SYNTH4'); - assert(IP.isIPv4String(json.address)); + assert(json && typeof json === 'object', 'Invalid json in SYNTH4 record.'); + assert(json.type === 'SYNTH4', 'Invalid type in SYNTH4 record.'); + assert(IP.isIPv4String(json.address), 'Invalid address in SYNTH4 record.'); this.address = IP.normalize(json.address); @@ -737,9 +741,9 @@ class SYNTH6 extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(json.type === 'SYNTH6'); - assert(IP.isIPv6String(json.address)); + assert(json && typeof json === 'object', 'Invalid json in SYNTH6 record.'); + assert(json.type === 'SYNTH6', 'Invalid type in SYNTH6 record.'); + assert(IP.isIPv6String(json.address), 'Invalid address in SYNTH6 record.'); this.address = IP.normalize(json.address); @@ -812,13 +816,13 @@ class TXT extends Struct { } fromJSON(json) { - assert(json && typeof json === 'object'); - assert(json.type === 'TXT'); - assert(Array.isArray(json.txt)); + assert(json && typeof json === 'object', 'Invalid json in TXT record.'); + assert(json.type === 'TXT', 'Invalid type in TXT record.'); + assert(Array.isArray(json.txt), 'Invalid txt in TXT record.'); for (const txt of json.txt) { - assert(typeof txt === 'string'); - assert(txt.length <= 255); + assert(typeof txt === 'string', 'Invalid txt entry in TXT record.'); + assert(txt.length <= 255, 'Invalid txt entry length in TXT record.'); this.txt.push(txt); }