Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fromString(str) {
assert(typeof str === 'string');
assert(str.length <= 255);
str = str.toLowerCase();
const parts = str.split('@');
if (parts.length > 1) {
const name = util.fqdn(parts[0]);
assert(isName(name));
const ips = parts[1].split(',');
assert(ips.length <= 2);
this.type = types.GLUE;
this.target = name;
for (const ip of ips) {
const [type, addr] = parseIP(ip);
switch (type) {
case types.ONION:
throw new Error('Bad glue address.');
case types.INET4:
if (addr === '0.0.0.0')
assert(str[index - 1] === '?' || str[index - 1] === '&');
str = str.substring(index + 7);
const parts = str.split(/[:&]/);
assert(parts.length >= 2);
const [nid, nin] = parts;
assert(nid.length <= 255);
assert(nin.length <= 255);
assert(isSingle(nid));
this.nid = util.fqdn(nid);
this.nin = nin;
return this;
}
fromString(str) {
assert(typeof str === 'string');
assert(str.length <= 512);
const parts = str.split(':');
assert(parts.length === 2);
const [currency, address] = parts;
assert(currency.length <= 255);
assert(address.length <= 255);
assert(isSingle(currency));
this.currency = util.fqdn(currency);
this.address = address;
return this;
}
fromJSON(json) {
assert(json && typeof json === 'object');
if (json.service != null) {
assert(isSingle(json.service));
this.service = util.fqdn(json.service);
}
if (json.protocol != null) {
assert(isSingle(json.protocol));
this.protocol = util.fqdn(json.protocol);
}
if (json.priority != null) {
assert((json.priority & 0xff) === json.priority);
this.priority = json.priority;
}
if (json.weight != null) {
assert((json.weight & 0xff) === json.weight);
this.weight = json.weight;
}
if (json.target != null)
this.target.fromJSON(json.target);
if (json.port != null) {
function isSingle(label) {
label = util.fqdn(label);
if (!isName(label))
return false;
if (util.countLabels(label) !== 1)
return false;
return true;
}
return this;
}
if (onion.isLegacyString(str)) {
this.type = types.ONION;
this.target = onion.normalizeLegacy(str);
return this;
}
if (onion.isNGString(str)) {
this.type = types.ONIONNG;
this.target = onion.normalizeNG(str, sha3.digest);
return this;
}
const name = util.fqdn(str);
assert(isName(name));
this.type = types.NAME;
this.target = name;
return this;
}