@nictool/dns-resource-record 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +323 -199
  3. package/dist/dns-rr.min.js +26 -0
  4. package/dist/dns-rr.min.js.map +7 -0
  5. package/index.js +12 -11
  6. package/lib/binary.js +108 -0
  7. package/lib/bind.js +94 -0
  8. package/lib/dns-query.js +67 -0
  9. package/lib/tinydns.js +128 -44
  10. package/lib/wire.js +519 -0
  11. package/package.json +23 -6
  12. package/rr/TEMPLATE.js +124 -0
  13. package/rr/a.js +8 -48
  14. package/rr/aaaa.js +13 -80
  15. package/rr/apl.js +123 -27
  16. package/rr/caa.js +27 -50
  17. package/rr/cert.js +58 -87
  18. package/rr/cname.js +7 -63
  19. package/rr/dhcid.js +20 -30
  20. package/rr/dname.js +9 -36
  21. package/rr/dnskey.js +38 -32
  22. package/rr/ds.js +43 -57
  23. package/rr/hinfo.js +21 -40
  24. package/rr/hip.js +88 -26
  25. package/rr/https.js +28 -40
  26. package/rr/ipseckey.js +97 -18
  27. package/rr/key.js +39 -29
  28. package/rr/kx.js +16 -27
  29. package/rr/loc.js +42 -12
  30. package/rr/mx.js +16 -51
  31. package/rr/naptr.js +58 -33
  32. package/rr/ns.js +8 -36
  33. package/rr/nsec.js +89 -18
  34. package/rr/nsec3.js +62 -26
  35. package/rr/nsec3param.js +56 -53
  36. package/rr/nxt.js +57 -18
  37. package/rr/openpgpkey.js +24 -30
  38. package/rr/ptr.js +7 -47
  39. package/rr/rp.js +17 -32
  40. package/rr/rrsig.js +80 -85
  41. package/rr/sig.js +70 -45
  42. package/rr/smimea.js +33 -33
  43. package/rr/soa.js +31 -49
  44. package/rr/spf.js +10 -17
  45. package/rr/srv.js +22 -62
  46. package/rr/sshfp.js +25 -53
  47. package/rr/svcb.js +27 -40
  48. package/rr/tlsa.js +34 -34
  49. package/rr/tsig.js +87 -24
  50. package/rr/txt.js +40 -59
  51. package/rr/uri.js +19 -29
  52. package/rr/wks.js +154 -22
  53. package/rr.js +290 -109
  54. package/lib/readme.js +0 -84
@@ -0,0 +1,26 @@
1
+ const Ot=new RegExp(/\\(?:[1-7][0-7]{0,2}|[0-7]{2,3})/,"g"),Lt=new TextDecoder;function vt(l,t){const e=l.slice(1).split(":"),s=e[0],i=e.slice(1,1+t),[n,a,o]=e.slice(1+t);return{owner:s,rdata:i,ttl:n,timestamp:a,location:o?.trim()??""}}function Jt(l){const[t,e,s,i,n,a]=l.slice(1).split(":");return{owner:t,typeId:e,rdata:s,ttl:parseInt(i,10),timestamp:n,location:a?.trim()??""}}function H(l){return Uint8Array.from(x(l),t=>t.charCodeAt(0))}function Mt(l,t){if(l.length<6)throw new Error(`${t}: RDATA too short: ${l}`);const e=H(l),s=e[0]<<8|e[1];let i=2;const n=[];for(;;){const a=e[i];if(i+=1,a===0)break;n.push(Lt.decode(e.subarray(i,i+a))),i+=a}return{priority:s,targetName:`${n.join(".")}.`,params:Lt.decode(e.subarray(i))}}function Zt(l){if(l.constructor.tinydnsType){const e=l.getFields("rdata").map(s=>l.isFqdnField(s)?l.getTinyFQDN(s):l.get(s)).join(":");return`${l.constructor.tinydnsType}${l.getTinyFQDN("owner")}:${e}:${l.getTinydnsPostamble()}
2
+ `}return l.getTinydnsGeneric(re(l.getWireRdata()))}function _t(l,{tinyline:t}){const e=l.getFields("rdata"),{owner:s,rdata:i,ttl:n,timestamp:a,location:o}=vt(t,e.length),r={owner:l.fullyQualify(s),type:l.constructor.typeName,ttl:parseInt(n,10),timestamp:a,location:o};for(let c=0;c<e.length;c++){const h=i[c];r[e[c]]=l.isFqdnField(e[c])?l.fullyQualify(h):h}return new l.constructor(r)}function I(l,t){let e="";return t.split(/(.{1})/g).map(s=>{e+=l.test(s)?ee(s):s}),e}function x(l){return l.replace(Ot,t=>String.fromCharCode(parseInt(t.slice(1),8)))}function Pt(l){return l.replace(Ot,t=>parseInt(t.slice(1),8).toString(16).padStart(2,0))}function E(l){return parseInt(l.slice(1,4),8)&255}function B(l){return parseInt(l.slice(1,4),8)<<8|parseInt(l.slice(5,8),8)}function gt(l){const t=parseInt(l.slice(1,4),8),e=parseInt(l.slice(5,8),8),s=parseInt(l.slice(9,12),8),i=parseInt(l.slice(13,16),8);return(t<<24|e<<16|s<<8|i)>>>0}function Bt(l){return l.match(/(.{1,255})/g).map(t=>`${u(t.length)}${t}`).join("")}function te(l){const t=Uint8Array.from(x(l.toString()),a=>a.charCodeAt(0)),e=new TextDecoder,s=[];let i=0,n;for(;(n=t[i])&&(i++,s.push(e.decode(t.subarray(i,i+n))),i=+(i+n),!(i>=t.length)););return s}function N(l){const t=new RegExp(/[^A-Za-z0-9-.]/,"g");let e="";return l.split(".").forEach(s=>{s===void 0||!s.length||(e+=u(s.length),e+=I(t,s))}),e+="\\000",e}function U(l){let t=0,e=0;const s=[],i=()=>{if(t>=l.length)return null;let a;return l[t]==="\\"?(a=parseInt(l.slice(t+1,t+4),8),t+=4):a=l.charCodeAt(t++),e++,a};let n;for(;(n=i())&&n!==0;){let a="";for(let o=0;o<n;o++){const r=i();if(r===null)break;a+=String.fromCharCode(r)}s.push(a)}return[`${s.join(".")}.`,t,e]}function O(l){let t="";for(let e=0;e<l.length;e=e+2)t+=u(parseInt(l.slice(e,e+2),16));return t}function ee(l){return u(typeof l=="number"?l:l.charCodeAt(0))}function u(l){if(l>255)throw new Error(`UInt8toOctal: value ${l} exceeds 255 \u2014 tinydns encoders require Latin-1/byte input (code points <= 0xFF)`);return`\\${parseInt(l,10).toString(8).padStart(3,0)}`}function A(l){return u(l>>>8&255)+u(l&255)}function P(l){return u(l>>>24&255)+u(l>>>16&255)+u(l>>>8&255)+u(l&255)}function qt(l){return P(l.split`.`.reduce((t,e)=>t*256+ +e))}function se(l){const t=gt(l);return[24,16,8,0].map(e=>t>>e&255).join(".")}function Rt(l,t=":"){const e=l.match(/:/g);return e?.length<7&&(l=l.replace(/::/,":".repeat(9-e.length))),l.split(":").map(s=>s.padStart(4,"0")).join(t).toLowerCase()}function ie(l){return O(Rt(l,""))}function ne(l){return Pt(l).match(/(.{4})/g).join(":")}function G(l){const t=atob(l);let e="";for(let s=0;s<t.length;s++){const i=t.charCodeAt(s);e+=/[A-Za-z0-9\-.]/.test(t[s])?t[s]:u(i)}return e}function ut(l){return btoa(x(l))}function re(l){let t="";for(const e of l)t+=u(e);return t}function F(l){return Uint8Array.from({length:l.length/2},(t,e)=>parseInt(l.slice(e*2,e*2+2),16))}function R(l){return[...l].map(t=>t.toString(16).padStart(2,"0")).join("")}function V(l){return btoa([...l].map(t=>String.fromCharCode(t)).join(""))}function L(l){return Uint8Array.from(atob(l),t=>t.charCodeAt(0))}const q={A:1,NS:2,MD:3,MF:4,CNAME:5,SOA:6,MB:7,MG:8,MR:9,NULL:10,WKS:11,PTR:12,HINFO:13,MINFO:14,MX:15,TXT:16,RP:17,AFSDB:18,X25:19,ISDN:20,RT:21,NSAP:22,NSAP_PTR:23,SIG:24,KEY:25,PX:26,GPOS:27,AAAA:28,LOC:29,NXT:30,EID:31,NIMLOC:32,SRV:33,ATMA:34,NAPTR:35,KX:36,CERT:37,A6:38,DNAME:39,SINK:40,OPT:41,APL:42,DS:43,SSHFP:44,IPSECKEY:45,RRSIG:46,NSEC:47,DNSKEY:48,DHCID:49,NSEC3:50,NSEC3PARAM:51,TLSA:52,SMIMEA:53,HIP:55,NINFO:56,RKEY:57,TALINK:58,CDS:59,CDNSKEY:60,OPENPGPKEY:61,CSYNC:62,ZONEMD:63,SVCB:64,HTTPS:65,SPF:99,UINFO:100,UID:101,GID:102,UNSPEC:103,NID:104,L32:105,L64:106,LP:107,EUI48:108,EUI64:109,TKEY:249,TSIG:250,IXFR:251,AXFR:252,MAILB:253,MAILA:254,ANY:255,URI:256,CAA:257,AVC:258,DOA:259,AMTRELAY:260,TA:32768,DLV:32769};function Ut(l,t=0){const e=[];let s=t;for(;s<l.length;){const i=l[s];if(i===0){s++;break}e.push(new TextDecoder().decode(l.subarray(s+1,s+1+i))),s+=1+i}return{fqdn:e.length?e.join(".")+".":".",end:s}}function W(l){if(l===".")return new Uint8Array([0]);const t=new TextEncoder,e=l.split(".").filter(n=>n.length>0).map(n=>{const a=t.encode(n);if(a.length>63)throw new Error(`DNS label exceeds 63 bytes: ${n}`);return a}),s=new Uint8Array(e.reduce((n,a)=>n+a.length+1,1));let i=0;for(const n of e)s[i++]=n.length,s.set(n,i),i+=n.length;return s[i]=0,s}function ae(l){const t=l.toTinydns();if(!t.startsWith(":"))throw new Error(`${l.get("type")}: getWireRdata() not implemented. Override in rr/${l.get("type").toLowerCase()}.js`);const e=t.split(":")[3];return l.octalToUint8Array(e??"")}function oe(l,t){const e=l.getWireRdata(),s=W(l.get("owner")),i=new Uint8Array(s.length+10+e.length);i.set(s,0);const n=new DataView(i.buffer,s.length,10);return n.setUint16(0,l.getTypeId()),n.setUint16(2,t[l.get("class")]??1),n.setUint32(4,l.get("ttl")),n.setUint16(8,e.length),i.set(e,s.length+10),i}function ce(l,t,e){const s=new l(null),i=t instanceof Uint8Array?t:new Uint8Array(t),{fqdn:n,end:a}=e(i,0),o=new DataView(i.buffer,i.byteOffset),r=o.getUint16(a+2),c={IN:1,CS:2,CH:3,HS:4,NONE:254,ANY:255},h=Object.keys(c).find(y=>c[y]===r)??"IN",p=o.getUint32(a+4),d=o.getUint16(a+8),g=i.slice(a+10,a+10+d);return s.fromWire({owner:n,cls:h,ttl:p,rdata:g})}function le(l,{owner:t,cls:e,ttl:s,rdata:i}){const n={owner:t,ttl:s,class:e,type:l.constructor.typeName},a=l.constructor.rdataFields??[],o=new DataView(i.buffer,i.byteOffset);let r=0;for(let c=0;c<a.length;c++){const h=a[c],p=Array.isArray(h)?h[0]:h;switch(Array.isArray(h)?h[1]:null){case"u8":n[p]=i[r++];break;case"u16":n[p]=o.getUint16(r),r+=2;break;case"certtype":{const g=o.getUint16(r),y=l.constructor.CERT_TYPES_REVERSE;n[p]=y?.[g]??g,r+=2;break}case"u32":n[p]=o.getUint32(r),r+=4;break;case"fqdn":{const{fqdn:g,end:y}=Ut(i,r);n[p]=g,r=y;break}case"hex":n[p]=R(i.subarray(r)).toUpperCase(),r=i.length;break;case"base64":n[p]=V(i.subarray(r)),r=i.length;break;case"str":n[p]=new TextDecoder().decode(i.subarray(r)),r=i.length;break;case"qstr":n[p]=new TextDecoder().decode(i.subarray(r)),r=i.length;break;case"charstr":{const g=i[r++];n[p]=new TextDecoder().decode(i.subarray(r,r+g)),r+=g;break}case"qcharstr":{const g=i[r++];n[p]=new TextDecoder().decode(i.subarray(r,r+g)),r+=g;break}case"charstrs":{const g=[];for(;r<i.length;){const y=i[r++];g.push(new TextDecoder().decode(i.subarray(r,r+y))),r+=y}n[p]=g.join("");break}case"svcparams":n[p]=de(i.subarray(r)),r=i.length;break;case"ipv4":n[p]=[...i.subarray(r,r+4)].join("."),r+=4;break;case"ipv6":{const g=[];for(let y=0;y<16;y+=2)g.push(o.getUint16(r+y).toString(16).padStart(4,"0"));n[p]=g.join(":"),r+=16;break}default:n[p]=i[r++];break}}return new l.constructor(n)}const he={mandatory:0,alpn:1,"no-default-alpn":2,port:3,ipv4hint:4,ech:5,ipv6hint:6};function Wt(l){if(!l||!l.trim())return new Uint8Array(0);const t=[],e=/([^\s=]+)(?:=(?:"([^"]*)"|(\S*)))?(?=\s|$)/g;let s;for(;(s=e.exec(l.trim()))!==null;){const o=s[1].toLowerCase(),r=s[2]??s[3]??"",c=he[o];if(c===void 0)continue;let h;if(c===1){const d=new TextEncoder,g=r.split(",").map(b=>d.encode(b.trim())),y=g.reduce((b,w)=>b+1+w.length,0);h=new Uint8Array(y);let m=0;for(const b of g)h[m++]=b.length,h.set(b,m),m+=b.length}else if(c===2)h=new Uint8Array(0);else if(c===3)h=new Uint8Array(2),new DataView(h.buffer).setUint16(0,parseInt(r,10));else if(c===4){const d=r.split(",").map(g=>g.trim().split(".").map(Number));h=new Uint8Array(d.length*4),d.forEach((g,y)=>g.forEach((m,b)=>h[y*4+b]=m))}else if(c===5)h=L(r);else if(c===6){const d=r.split(",").map(g=>F(Rt(g.trim(),"")));h=new Uint8Array(d.length*16),d.forEach((g,y)=>h.set(g,y*16))}else h=new TextEncoder().encode(r);const p=new Uint8Array(4+h.length);new DataView(p.buffer).setUint16(0,c),new DataView(p.buffer).setUint16(2,h.length),p.set(h,4),t.push(p)}t.sort((o,r)=>new DataView(o.buffer).getUint16(0)-new DataView(r.buffer).getUint16(0));const i=t.reduce((o,r)=>o+r.length,0),n=new Uint8Array(i);let a=0;for(const o of t)n.set(o,a),a+=o.length;return n}const pe={0:"mandatory",1:"alpn",2:"no-default-alpn",3:"port",4:"ipv4hint",5:"ech",6:"ipv6hint"};function de(l){if(!l||l.length===0)return"";const t=[];let e=0;for(;e+4<=l.length;){const s=new DataView(l.buffer,l.byteOffset+e),i=s.getUint16(0),n=s.getUint16(2),a=l.subarray(e+4,e+4+n);e+=4+n;const o=pe[i]??`key${i}`;if(i===1){const r=[];let c=0;for(;c<a.length;){const h=a[c++];r.push(new TextDecoder().decode(a.subarray(c,c+h))),c+=h}t.push(`alpn="${r.join(",")}"`)}else if(i===2)t.push("no-default-alpn");else if(i===3)t.push(`port=${new DataView(a.buffer,a.byteOffset).getUint16(0)}`);else if(i===4){const r=[];for(let c=0;c<a.length;c+=4)r.push([...a.subarray(c,c+4)].join("."));t.push(`ipv4hint=${r.join(",")}`)}else if(i===5)t.push(`ech=${btoa([...a].map(r=>String.fromCharCode(r)).join(""))}`);else if(i===6){const r=[];for(let c=0;c<a.length;c+=16){const h=new DataView(a.buffer,a.byteOffset+c),p=[];for(let d=0;d<16;d+=2)p.push(h.getUint16(d).toString(16).padStart(4,"0"));r.push(p.join(":"))}t.push(`ipv6hint=${r.join(",")}`)}else t.push(`${o}=${[...a].map(r=>r.toString(16).padStart(2,"0")).join("")}`)}return t.join(" ")}function ge(l,t){const e={class:"IN",type:"",rdata:[]};let s="",i=!1;for(let a=0;a<l.length;a++){const o=l[a];if(o==='"'&&(i=!i),o===";"&&!i)break;s+=o}if(s=s.trim(),!s)return null;const n=s.match(/(".*?"|\S+)/g)||[];if(n.length<1)return null;for(/^\s/.test(l)||(e.owner=n.shift());n.length>0;){const a=n[0].toUpperCase();if(t[a]){e.class=n.shift().toUpperCase();continue}if(/^\d+$/.test(a)){e.ttl=parseInt(n.shift(),10);continue}e.type=n.shift().toUpperCase();break}return e.rdata=n,e}function ue(l,t){const{owner:e,ttl:s,cls:i,rdata:n}=t,a={owner:e,ttl:s,class:i,type:l.constructor.typeName},o=l.getFields("rdata");for(let r=0;r<o.length;r++){if(r===o.length-1&&l.isQuotedField(o[r])){const p=n.slice(r).map(d=>d.replace(/^"|"$/g,"")).join("");a[o[r]]=p;break}let h=n[r];l.isQuotedField(o[r])?h=h?.replace(/^"|"$/g,""):/^\d+$/.test(h)&&(h=parseInt(h,10)),a[o[r]]=h}return new l.constructor(a)}function ye(l,t){const s=l.getFields("rdata").map(i=>l.isFqdnField(i)?l.getFQDN(i,t):l.getQuoted(i)).join(" ");return`${l.getPrefix(t)} ${s}
3
+ `}const fe=Symbol.for("nodejs.util.inspect.custom");class f{static CLASSES={IN:1,CS:2,CH:3,HS:4,NONE:254,ANY:255};static typeId;static RFCs=[];static tags=[];constructor(t){if(t!==null){t?.default&&(this.default=t.default),this.setLocation(t?.location),this.setTimestamp(t?.timestamp),this.setOwner(t?.owner),this.setType(t?.type),this.setTtl(t?.ttl),this.setClass(t?.class);for(const e of this.constructor.rdataFields??[]){const s=f.fieldName(e),i=Array.isArray(e)?e[1]:null,n=`set${this.ucFirst(s)}`;typeof this[n]=="function"?this[n](t?.[s]):i?this.setTypedValue(i,s,t?.[s]):this.set(s,t?.[s])}t?.comment&&this.set("comment",t.comment)}}static fromBind(t,e={}){const s=new this(null);e.default!==void 0&&(s.default=e.default);const i=this.parseBindLine(t);return i?s.fromBind({...e,...i,bindline:t}):null}fromBind(t){return ue(this,t)}static parseBindLine(t){return ge(t,f.CLASSES)}static fromTinydns(t,e={}){const s=new this(null);return e.default!==void 0&&(s.default=e.default),s.fromTinydns({...e,tinyline:t})}fromTinydns(t){return _t(this,t)}static fromWire(t){return ce(this,t,Ut)}fromWire(t){return le(this,t)}static#t=["__proto__","constructor","prototype"];get(t){if(f.#t.includes(t))throw new Error(`Invalid field name: ${t}`);return this[t]}set(t,e){if(f.#t.includes(t))throw new Error(`Invalid field name: ${t}`);return this[t]=e,this}toJSON(){const t=[...this.getFields(),"location","timestamp","comment"],e={};for(const s of t){const i=this.get(s);i!==void 0&&(e[s]=i)}return e}[fe](t,e,s){return`${this.type} ${s(this.toJSON(),e)}`}ucFirst(t){return t&&t.split(/\s/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}setClass(t){if([void 0,null,""].includes(t)){this.set("class","IN");return}if(f.CLASSES[t.toUpperCase()]){this.set("class",t.toUpperCase());return}this.throwHelp(`invalid class ${t}`)}setLocation(t){t!==void 0&&this.set("location",t)}setTimestamp(t){t!==void 0&&this.set("timestamp",t)}setOwner(t){t===void 0&&this.throwHelp("owner is required"),(t.length<1||t.length>255)&&this.throwHelp("Domain names must have 1-255 octets (characters): RFC 2181"),this.isFullyQualified(this.constructor.typeName??this.constructor.name,"owner",t),this.hasValidLabels(t),/\*/.test(t)&&!/^\*\./.test(t)&&!/\.\*\./.test(t)&&this.throwHelp("only *.something or * (by itself) is a valid wildcard"),this.set("owner",t.toLowerCase())}setTtl(t){if(t=t??this.default?.ttl,t===void 0){if(["SOA","SSHFP","RRSIG"].includes(this.get("type")))return;this.throwHelp("TTL is required, no default available")}typeof t!="number"&&this.throwHelp(`TTL must be numeric (${typeof t})`),this.is32bitInt(this.get("type"),"TTL",t),this.set("ttl",t)}setType(t){[void 0,""].includes(t)&&(t=this.constructor.typeName),t===void 0&&this.throwHelp("type is required"),t.toUpperCase()!==this.constructor.typeName&&this.throwHelp(`type ${t} doesn't match ${this.constructor.typeName}`),this.set("type",t.toUpperCase())}throwHelp(t){if(!this.constructor.typeName)throw new Error(t);const e=this.constructor.typeName,s=this.getCanonical?`Example ${e}:
4
+ ${JSON.stringify(this.getCanonical(),null," ")}
5
+
6
+ `:`${e} records have the fields: ${this.getFields().join(", ")}
7
+
8
+ `;throw new Error(`${t}
9
+
10
+ ${s}${this.citeRFC()}
11
+ `)}citeRFC(){return`see RFC${this.getRFCs().length>1?"s":""} ${this.getRFCs()}`}fullyQualify(t,e){return t&&(t==="@"&&e&&(t=e),t.endsWith(".")?t.toLowerCase():e?`${t}.${e}`.toLowerCase():`${t}.`)}getPrefix(t={}){const e=t.hide?.class?"":this.get("class");let s=this.get("ttl");t.hide?.ttl&&s===t.ttl&&(s="");let i=this.get("owner");return t.hide?.sameOwner&&t.previousOwner===i?i="":i=this.getFQDN("owner",t),`${i} ${s} ${e} ${this.get("type")}`}getEmpty(t){return this.get(t)??""}getComment(t){const e=this.get("comment");return!e||!e[t]?"":e[t]}getQuoted(t){return this.isQuotedField(t)?/['"]/.test(this.get(t)[0])?this.get(t):`"${this.get(t)}"`:this.get(t)}static fieldName(t){return Array.isArray(t)?t[0]:t}static fieldType(t){return Array.isArray(t)?t[1]:null}getRdataFields(){return(this.constructor.rdataFields??[]).map(t=>f.fieldName(t))}getTags(){return this.constructor.tags??[]}getRFCs(){return this.constructor.RFCs??[]}getTypeId(){const t=this.constructor.typeId;return t===void 0&&this.throwHelp(`${this.constructor.typeName}: missing static typeId`),t}static getTypeId(){return this.typeId}getFields(t){const e=["owner","ttl","class","type"];Object.freeze(e);const s=this.getRdataFields();switch(t){case"common":return e;case"rdata":return s;default:return e.concat(s)}}getFQDN(t,e={}){let s=this.get(t);if(s||this.throwHelp(`empty value for field ${t}`),s.endsWith(".")||(s+="."),e.hide?.origin&&e.origin){if(s===e.origin)return"@";if(s.endsWith(e.origin))return s.slice(0,s.length-e.origin.length-1)}return s}getTinyFQDN(t){const e=this.get(t);return e===""||e==="."?e:e.endsWith(".")?e.slice(0,-1):e}getTinydnsGeneric(t){return`:${this.getTinyFQDN("owner")}:${this.getTypeId()}:${t}:${this.getTinydnsPostamble()}
12
+ `}getTinydnsPostamble(){return["ttl","timestamp","location"].map(t=>this.getEmpty(t)).join(":")}hasValidLabels(t){const e=t.endsWith(".")?t.slice(0,-1):t;for(const s of e.split("."))(s.length<1||s.length>63)&&this.throwHelp("Labels must have 1-63 octets (characters), RFC 2181")}is8bitInt(t,e,s){if(Number.isInteger(s)&&s>=0&&s<=255)return!0;this.throwHelp(`${t} ${e} must be a 8-bit integer (in the range 0-255)`)}is16bitInt(t,e,s){if(Number.isInteger(s)&&s>=0&&s<=65535)return!0;this.throwHelp(`${t} ${e} must be a 16-bit integer (in the range 0-65535)`)}is32bitInt(t,e,s){if(Number.isInteger(s)&&s>=0&&s<=4294967295)return!0;this.throwHelp(`${t} ${e} must be a 32-bit integer (in the range 0-4294967295)`)}isBase64(t,e,s){if(typeof s=="string"&&s.length>0&&s.length%4===0&&/^[A-Za-z0-9+/]*={0,2}$/.test(s))return!0;this.throwHelp(`${t} ${e} must be a valid base64 string`)}isQuoted(t){return/^["']/.test(t)&&/["']$/.test(t)}setFqdnValue(t,e,s){s||this.throwHelp(`${t}: ${e} is required`),(this.isIPv4(s)||this.isIPv6(s))&&this.throwHelp(`${t}: ${e} must be a domain name`),this.isFullyQualified(t,e,s),this.isValidHostname(t,e,s),this.set(e,s.toLowerCase())}setTypedValue(t,e,s){const i=this.constructor.typeName;switch(t){case"u8":this.is8bitInt(i,e,s),this.set(e,parseInt(s,10));break;case"u16":this.is16bitInt(i,e,s),this.set(e,parseInt(s,10));break;case"certtype":{if((s==null||s==="")&&this.throwHelp(`${i}: ${e} is required`),typeof s=="string"&&!/^[0-9]+$/.test(s)){const n=this.constructor.CERT_TYPES;(!n||!Object.hasOwn(n,s))&&this.throwHelp(`${i}: unknown cert type mnemonic: ${s}`),this.set(e,s);break}this.is16bitInt(i,e,s),this.set(e,parseInt(s,10));break}case"u32":this.is32bitInt(i,e,s),this.set(e,parseInt(s,10));break;case"fqdn":this.setFqdnValue(i,e,s);break;case"base64":this.isBase64(i,e,s),this.set(e,s);break;case"hex":/^[0-9a-fA-F]*$/.test(s)||this.throwHelp(`${i}: ${e} must be hexadecimal`),this.set(e,s);break;case"str":s||this.throwHelp(`${i}: ${e} is required`),this.set(e,s);break;case"qstr":s==null&&this.throwHelp(`${i}: ${e} is required`),this.set(e,s);break;case"charstr":{s==null&&this.throwHelp(`${i}: ${e} is required`);const n=String(s);new TextEncoder().encode(n).length>255&&this.throwHelp(`${i}: ${e} must be <=255 bytes`),this.set(e,n);break}case"qcharstr":{s==null&&this.throwHelp(`${i}: ${e} is required`);const n=String(s);new TextEncoder().encode(n).length>255&&this.throwHelp(`${i}: ${e} must be <=255 bytes`),this.set(e,n);break}case"charstrs":s==null&&this.throwHelp(`${i}: ${e} is required`),this.set(e,s);break;case"svcparams":s==null&&this.throwHelp(`${i}: ${e} is required`),this.set(e,s);break;case"ipv4":this.isIPv4(s)||this.throwHelp(`${i}: ${e} must be a valid IPv4 address`),this.set(e,s);break;case"ipv6":this.isIPv6(s)||this.throwHelp(`${i}: ${e} must be a valid IPv6 address`),this.set(e,this.expandIPv6(s.toLowerCase()));break}}isFullyQualified(t,e,s){if(s.endsWith("."))return!0;this.throwHelp(`${t}: ${e} must be fully qualified`)}isValidHostname(t,e,s){const i=new RegExp(/[^a-zA-Z0-9\-._/\\]/);if(!i.test(s))return!0;const n=i.exec(s);this.throwHelp(`${t}, ${e} has invalid hostname character (${n[0]})`)}isIPv4(t){return/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/.test(t)}isIPv6(t){return/^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(?::[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(?::[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(?::[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(?::[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/gm.test(t)}expandIPv6(t,e){return Rt(t,e)}compressIPv6(t){const e=t.toLowerCase().split(":").map(c=>c.replace(/^0+/,"")||"0");let s=-1,i=0,n=-1,a=0;for(let c=0;c<e.length;c++)e[c]==="0"?(n===-1&&(n=c),a++,a>i&&(i=a,s=n)):(n=-1,a=0);if(i<2)return e.join(":");const o=e.slice(0,s).join(":"),r=e.slice(s+i).join(":");return`${o}::${r}`}octalToUint8Array(t){const e=x(t);return Uint8Array.from(e,s=>s.charCodeAt(0))}wireUnpackDomain(t,e=0){return Ut(t,e)}wirePackDomain(t){return W(t)}getWireRdata(){return ae(this)}toWire(){return oe(this,f.CLASSES)}toBind(t){return ye(this,t)}parseTinydnsLine(t){const e=Jt(t);return{...e,owner:this.fullyQualify(e.owner)}}toTinydns(){return Zt(this)}isFqdnField(t){return(this.constructor.rdataFields??[]).some(e=>f.fieldName(e)===t&&f.fieldType(e)==="fqdn")||!1}isQuotedField(t){const e=new Set(["qstr","qcharstr","charstrs"]);return(this.constructor.rdataFields??[]).some(s=>f.fieldName(s)===t&&e.has(f.fieldType(s)))||!1}toMaraDNS(){const t=this.get("type");return"A PTR MX AAAA SRV NAPTR NS SOA TXT SPF RAW FQDN4 FQDN6 CNAME HINFO WKS LOC".split(/\s+/g).includes(t)?`${this.get("owner")} +${this.get("ttl")} ${t} ${this.getFields("rdata").map(s=>this.getQuoted(s)).join(" ")} ~
13
+ `:this.toMaraGeneric()}toMaraGeneric(){return`${this.get("owner")} +${this.get("ttl")} RAW ${this.getTypeId()} '${this.getFields("rdata").map(t=>this.getQuoted(t)).join(" ")}' ~
14
+ `}}class Gt extends f{static typeName="A";static typeId=1;static RFCs=[1035];static tinydnsType="+";static rdataFields=[["address","ipv4"]];static tags=["common"];constructor(t){super(t)}setAddress(t){t||this.throwHelp("A: address is required"),this.isIPv4(t)||this.throwHelp("A address must be IPv4"),this.set("address",t)}getDescription(){return"Address"}getCanonical(){return{owner:"host.example.com.",class:"IN",ttl:3600,type:"A",address:"192.0.2.127"}}getWireRdata(){return new Uint8Array(this.get("address").split(".").map(Number))}}class yt extends f{static typeName="AAAA";static typeId=28;static RFCs=[3596,5952];static rdataFields=[["address","ipv6"]];static tags=["common"];constructor(t){super(t)}setAddress(t){t||this.throwHelp("AAAA: address is required"),this.isIPv6(t)||this.throwHelp(`AAAA: address must be IPv6 (${t})`),this.set("address",this.expandIPv6(t.toLowerCase()))}getCompressed(t){return this.compressIPv6(t??this.get("address"))}getDescription(){return"Address IPv6"}getCanonical(){return{owner:"host.example.com.",address:"2001:0db8:0020:000a:0000:0000:0000:0004",class:"IN",ttl:3600,type:"AAAA"}}fromTinydns({tinyline:t}){const e=t;let s,i,n,a,o,r,c;switch(e[0]){case":":[s,n,a,o,r,c]=e.slice(1).split(":"),n!=28&&this.throwHelp("AAAA fromTinydns, invalid n"),i=Pt(a).match(/([0-9a-fA-F]{4})/g).join(":");break;case"3":case"6":[s,a,o,r,c]=e.slice(1).split(":"),i=a.match(/(.{4})/g).join(":");break}return new yt({owner:this.fullyQualify(s),ttl:parseInt(o,10),type:"AAAA",address:i,timestamp:r,location:c?.trim()??""})}getWireRdata(){const t=this.expandIPv6(this.get("address"),""),e=new Uint8Array(t.length/2);for(let s=0;s<e.length;s++)e[s]=parseInt(t.slice(s*2,s*2+2),16);return e}toBind(t){return`${this.getPrefix(t)} ${this.getCompressed()}
15
+ `}toTinydns(){const t=O(this.expandIPv6(this.get("address"),""));return this.getTinydnsGeneric(t)}}class j extends f{static typeName="APL";static typeId=42;static RFCs=[3123];static rdataFields=["apl rdata"];constructor(t){super(t)}setAplRdata(t){t||this.throwHelp("APL: apl rdata is required"),this.set("apl rdata",t)}getDescription(){return"Address Prefix List"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"APL","apl rdata":"1:192.0.2.1/24 !1:192.0.2.64/28 2:2001:db8::1/128"}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");s!=42&&this.throwHelp("APL fromTinydns, invalid n");const r=Uint8Array.from(x(i),p=>p.charCodeAt(0)),c=[];let h=0;for(;h<r.length;){const p=r[h]<<8|r[h+1];h+=2;const d=r[h];h++;const g=r[h];h++;const y=(g&128)!==0,m=g&127,b=r.subarray(h,h+m);h+=m;let w;if(p===1){const T=new Uint8Array(4);T.set(b),w=[...T].join(".")}else{const T=new Uint8Array(16);T.set(b);const D=new DataView(T.buffer),C=[];for(let S=0;S<16;S+=2)C.push(D.getUint16(S).toString(16).padStart(4,"0"));w=this.compressIPv6(C.join(":"))}c.push(`${y?"!":""}${p}:${w}/${d}`)}return new j({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"APL","apl rdata":c.join(" "),timestamp:a,location:o?.trim()??""})}fromBind({bindline:t}){const e=t.split(/\s+/),[s,i,n,a]=e;return new j({owner:s,ttl:parseInt(i,10),class:n,type:a,"apl rdata":e.slice(4).join(" ").trim()})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=[];let a=0;for(;a<i.length;){const o=i[a]<<8|i[a+1];a+=2;const r=i[a++],c=i[a++],h=(c&128)!==0,p=c&127,d=i.subarray(a,a+p);a+=p;let g;if(o===1){const y=new Uint8Array(4);y.set(d),g=[...y].join(".")}else{const y=new Uint8Array(16);y.set(d);const m=new DataView(y.buffer),b=[];for(let w=0;w<16;w+=2)b.push(m.getUint16(w).toString(16).padStart(4,"0"));g=this.compressIPv6(b.join(":"))}n.push(`${h?"!":""}${o}:${g}/${r}`)}return new j({owner:t,ttl:s,class:e,type:"APL","apl rdata":n.join(" ")})}toTinydns(){return this.getTinydnsGeneric(this.get("apl rdata").split(/\s+/).map(t=>{const e=t.startsWith("!"),s=e?t.slice(1):t,i=s.indexOf(":"),n=parseInt(s.slice(0,i),10),a=s.slice(i+1),o=a.lastIndexOf("/"),r=a.slice(0,o),c=parseInt(a.slice(o+1),10);let h;if(n===1)h=new Uint8Array(r.split(".").map(y=>parseInt(y,10)));else{const y=r.indexOf("::");let m;if(y!==-1){const w=r.slice(0,y).split(":").filter(D=>D!==""),T=r.slice(y+2).split(":").filter(D=>D!=="");m=[...w,...Array(8-w.length-T.length).fill("0000"),...T]}else m=r.split(":");const b=m.map(w=>w.padStart(4,"0")).join("");h=Uint8Array.from({length:b.length/2},(w,T)=>parseInt(b.slice(T*2,T*2+2),16))}let p=h.length;for(;p>0&&h[p-1]===0;)p--;const d=h.slice(0,p);let g=A(n);g+=u(c),g+=u((e?128:0)|d.length);for(const y of d)g+=u(y);return g}).join(""))}getWireRdata(){const t=this.get("apl rdata").split(/\s+/),e=[];for(const a of t){const o=a.startsWith("!"),r=o?a.slice(1):a,c=r.indexOf(":"),h=parseInt(r.slice(0,c),10),p=r.slice(c+1),d=p.lastIndexOf("/"),g=p.slice(0,d),y=parseInt(p.slice(d+1),10);let m;if(h===1)m=new Uint8Array(g.split(".").map(C=>parseInt(C,10)));else{const C=g.indexOf("::");let S;if(C!==-1){const _=g.slice(0,C).split(":").filter(Dt=>Dt!==""),tt=g.slice(C+2).split(":").filter(Dt=>Dt!=="");S=[..._,...Array(8-_.length-tt.length).fill("0000"),...tt]}else S=g.split(":");const kt=S.map(_=>_.padStart(4,"0")).join("");m=Uint8Array.from({length:kt.length/2},(_,tt)=>parseInt(kt.slice(tt*2,tt*2+2),16))}let b=m.length;for(;b>0&&m[b-1]===0;)b--;const w=m.slice(0,b),T=new Uint8Array(4+w.length);new DataView(T.buffer,T.byteOffset).setUint16(0,h),T[2]=y,T[3]=(o?128:0)|w.length,T.set(w,4),e.push(T)}const s=e.reduce((a,o)=>a+o.length,0),i=new Uint8Array(s);let n=0;for(const a of e)i.set(a,n),n+=a.length;return i}}class ft extends f{static typeName="CAA";static typeId=257;static RFCs=[6844,8659,9619];static rdataFields=[["flags","u8"],["tag","charstr"],["value","qstr"]];static tags=["security"];constructor(t){super(t)}setFlags(t){this.is8bitInt("CAA","flags",t),this.getFlagsOptions().has(t)||this.throwHelp(`CAA flags ${t} not recognized`),this.set("flags",t)}getFlagsOptions(){return new Map([[0,"Non Critical"],[128,"Critical"]])}setTag(t){(typeof t!="string"||t.length<1||/[^a-z0-9]/.test(t))&&this.throwHelp("CAA tag must be a sequence of ASCII letters and numbers in lowercase"),this.getTagOptions().has(t)||this.throwHelp(`CAA tag ${t} not recognized`),this.set("tag",t)}getTagOptions(){return new Map([["issue"],["issuewild"],["iodef"]])}setValue(t){this.isQuoted(t)&&(t=t.replace(/^["']|["']$/g,"")),this.get("tag")==="iodef"&&(["mailto:","http:","https:"].filter(s=>t.startsWith(s)).length||this.throwHelp("CAA value must have valid iodefScheme prefix")),this.set("value",t)}getDescription(){return"Certification Authority Authorization"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"CAA",flags:0,tag:"issue",value:"http://letsencrypt.org"}}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("CAA fromTinydns, invalid typeId");const r=E(i.slice(0,4)),c=E(i.slice(4,8)),h=x(i.slice(8)),p=h.slice(0,c),d=h.slice(c);return new ft({owner:e,ttl:n,type:"CAA",flags:r,tag:p,value:d,timestamp:a,location:o})}getWireRdata(){const t=new TextEncoder().encode(this.get("tag")),e=new TextEncoder().encode(this.get("value")),s=new Uint8Array(2+t.length+e.length);return s[0]=this.get("flags"),s[1]=t.length,s.set(t,2),s.set(e,2+t.length),s}toTinydns(){return this.getTinydnsGeneric(u(this.get("flags"))+u(this.get("tag").length)+I(/[\r\n\t:\\/]/,this.get("tag"))+I(/[\r\n\t:\\/]/,this.get("value")))}}class $ extends f{static typeName="CERT";static typeId=37;static RFCs=[2538,4398];static rdataFields=[["cert type","certtype"],["key tag","u16"],["algorithm","u8"],["certificate","base64"]];static CERT_TYPES={PKIX:1,SPKI:2,PGP:3,IPKIX:4,ISPKI:5,IPGP:6,ACPKIX:7,IACPKIX:8,URI:253,OID:254};static CERT_TYPES_REVERSE=Object.fromEntries(Object.entries($.CERT_TYPES).map(([t,e])=>[e,t]));constructor(t){super(t)}setCertType(t){(t==null||t==="")&&this.throwHelp("cert type is required"),typeof t=="string"&&!/^[0-9]+$/.test(t)?Object.hasOwn($.CERT_TYPES,t)||this.throwHelp(`CERT: unknown cert type mnemonic: ${t}`):this.is16bitInt("CERT","cert type",t),this.set("cert type",t)}getCertTypeValue(t){if(typeof t=="number")return t;if(/^[0-9]+$/.test(t))return parseInt(t,10);if(Object.hasOwn($.CERT_TYPES,t))return $.CERT_TYPES[t];this.throwHelp(`CERT: unknown cert type mnemonic: ${t}`)}setCertificate(t){(t==null||t==="")&&this.throwHelp("certificate is required and cannot be empty"),this.isBase64("CERT","certificate",t.replace(/[\s()]/g,"")),this.set("certificate",t)}getDescription(){return"Certificate"}getCanonical(){return{owner:"mail.example.com.",ttl:3600,class:"IN",type:"CERT","cert type":"PGP","key tag":0,algorithm:0,certificate:"AQIDBA=="}}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("CERT fromTinydns, invalid n");const r=H(i),c=r[0]<<8|r[1],h=$.CERT_TYPES_REVERSE[c]??c;return new $({owner:e,ttl:n,type:"CERT","cert type":h,"key tag":r[2]<<8|r[3],algorithm:r[4],certificate:V(r.subarray(5)),timestamp:a,location:o})}fromBind({bindline:t}){const[e,s,i,n,a,o,r,c]=t.split(/\s+/);return new $({owner:e,ttl:parseInt(s,10),class:i,type:n,"cert type":/^[0-9]+$/.test(a)?parseInt(a,10):a,"key tag":parseInt(o,10),algorithm:parseInt(r,10),certificate:c})}toTinydns(){return this.getTinydnsGeneric(A(this.getCertTypeValue(this.get("cert type")))+A(this.get("key tag"))+u(this.get("algorithm"))+G(this.get("certificate").replace(/[\s()]/g,"")))}getWireRdata(){const t=L(this.get("certificate").replace(/[\s()]/g,"")),e=new Uint8Array(5+t.length),s=new DataView(e.buffer,e.byteOffset);return s.setUint16(0,this.getCertTypeValue(this.get("cert type"))),s.setUint16(2,this.get("key tag")),e[4]=this.get("algorithm"),e.set(t,5),e}}class Vt extends f{static typeName="CNAME";static typeId=5;static RFCs=[1035,2181];static tinydnsType="C";static rdataFields=[["cname","fqdn"]];static tags=["common"];constructor(t){super(t)}getDescription(){return"Canonical Name"}getCanonical(){return{owner:"www.example.com.",ttl:3600,class:"IN",type:"CNAME",cname:"web.example.com."}}getWireRdata(){return this.wirePackDomain(this.get("cname"))}}class mt extends f{static typeName="DHCID";static typeId=49;static RFCs=[4701];static rdataFields=[["data","base64"]];constructor(t){super(t)}setData(t){t||this.throwHelp("DHCID: data is required"),this.isBase64("DHCID","data",t),this.set("data",t)}getDescription(){return"DHCP Identifier"}getCanonical(){return{owner:"host.example.com.",ttl:3600,class:"IN",type:"DHCID",data:"AAIBY2/AuCccgoJbsaxcQc9TUapptP69lOjxfNuVAA2kjEA="}}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);return s!=this.getTypeId()&&this.throwHelp("DHCID fromTinydns, invalid n"),new mt({owner:e,ttl:n,type:"DHCID",data:ut(i),timestamp:a,location:o})}getWireRdata(){return new Uint8Array(atob(this.get("data")).split("").map(t=>t.charCodeAt(0)))}toTinydns(){return this.getTinydnsGeneric(G(this.get("data")))}}class wt extends f{static typeName="DNAME";static typeId=39;static RFCs=[2672,6672];static rdataFields=[["target","fqdn"]];constructor(t){super(t)}getDescription(){return"Delegation Name"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"DNAME",target:"example.net."}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");return s!=39&&this.throwHelp("DNAME fromTinydns, invalid n"),new wt({type:"DNAME",owner:this.fullyQualify(e),target:U(i)[0],ttl:parseInt(n,10),timestamp:a,location:o?.trim()??""})}getWireRdata(){return this.wirePackDomain(this.get("target"))}toTinydns(){const t=N(this.get("target"));return this.getTinydnsGeneric(t)}}class et extends f{static typeName="DNSKEY";static typeId=48;static RFCs=[4034,6014,8624,9619,9905];static rdataFields=[["flags","u16"],["protocol","u8"],["algorithm","u8"],["publickey","base64"]];static tags=["dnssec"];constructor(t){super(t)}setFlags(t){this.is16bitInt("DNSKEY","flags",t),this.getFlagsOptions().has(t)||this.throwHelp(`DNSKEY: flags must be in the set: ${this.getFlagsOptions()}`),this.set("flags",t)}getFlagsOptions(){return new Map([[0],[256],[257]])}setProtocol(t){this.is8bitInt("DNSKEY","protocol",t),this.getProtocolOptions().has(t)||this.throwHelp("DNSKEY: protocol invalid"),this.set("protocol",t)}getProtocolOptions(){return new Map([[3]])}setAlgorithm(t){this.is8bitInt("DNSKEY","algorithm",t),this.getAlgorithmOptions().has(t)||console.error(`DNSKEY: algorithm (${t}) not recognized`),this.set("algorithm",t)}getAlgorithmOptions(){return new Map([[1,"RSA/MD5 (DEPRECATED)"],[2,"DH"],[3,"DSA/SHA-1"],[4,"EC"],[5,"RSA/SHA-1"],[6,"DSA-NSEC3-SHA1"],[7,"RSASHA1-NSEC3-SHA1"],[8,"RSA/SHA-256"],[9,""],[10,"RSA/SHA-512"],[13,"ECDSA Curve P-256 with SHA-256"],[14,"ECDSA Curve P-384 with SHA-384"],[15,"Ed25519"],[16,"Ed448"],[253],[254]])}setPublickey(t){t||this.throwHelp("DNSKEY: publickey is required"),this.isBase64("DNSKEY","publickey",t.replace(/[\s()]/g,"")),this.set("publickey",t)}getDescription(){return"DNS Public Key"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"DNSKEY",flags:256,protocol:3,algorithm:5,publickey:"AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwIXAqcOTiW7iHnQt5hwVAAAAA=="}}fromBind({bindline:t}){const e=/^(?<owner>\S+)\s+(?<ttl>\d+)\s+(?<cls>\w+)\s+(?<type>DNSKEY)\s+(?<flags>\d+)\s+(?<protocol>\d+)\s+(?<algorithm>\d+)\s+(?<publickey>\S.*)$/i,s=t.trim().match(e);s||this.throwHelp(`unable to parse DNSKEY: ${t}`);const{owner:i,ttl:n,c:a,type:o,flags:r,protocol:c,algorithm:h,publickey:p}=s.groups;return new et({owner:i,ttl:parseInt(n,10),class:a,type:o,flags:parseInt(r,10),protocol:parseInt(c,10),algorithm:parseInt(h,10),publickey:p})}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("DNSKEY fromTinydns, invalid n");const r=H(i);return new et({owner:e,ttl:n,type:"DNSKEY",flags:r[0]<<8|r[1],protocol:r[2],algorithm:r[3],publickey:V(r.subarray(4)),timestamp:a,location:o})}toTinydns(){return this.getTinydnsGeneric(A(this.get("flags"))+u(this.get("protocol"))+u(this.get("algorithm"))+G(this.get("publickey").replace(/[\s()]/g,"")))}getWireRdata(){const t=L(this.get("publickey").replace(/[\s()]/g,"")),e=new Uint8Array(4+t.length);return new DataView(e.buffer,e.byteOffset).setUint16(0,this.get("flags")),e[2]=this.get("protocol"),e[3]=this.get("algorithm"),e.set(t,4),e}}class st extends f{static typeName="DS";static typeId=43;static RFCs=[4034,4509,9619];static rdataFields=[["key tag","u16"],"algorithm","digest type",["digest","str"]];static tags=["dnssec"];constructor(t){super(t)}setAlgorithm(t){this.getAlgorithmOptions().has(t)||this.throwHelp("DS: algorithm invalid"),this.set("algorithm",t)}getAlgorithmOptions(){return new Map([[1,"RSA/MD5"],[2,"DH"],[3,"DSA/SHA-1"],[4,"EC"],[5,"RSA/SHA-1"],[253,""],[254,""]])}setDigestType(t){[1,2].includes(t)||this.throwHelp("DS: digest type invalid"),this.set("digest type",t)}getDescription(){return"Delegation Signer"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"DS","key tag":12345,algorithm:5,"digest type":1,digest:"ABCDEF123..."}}fromTinydns(t){const{tinyline:e}=t,{owner:s,typeId:i,rdata:n,ttl:a,timestamp:o,location:r}=this.parseTinydnsLine(e);i!=this.getTypeId()&&this.throwHelp("DS fromTinydns, invalid n");const c=H(n);return new st({owner:s,ttl:a,type:"DS","key tag":c[0]<<8|c[1],algorithm:c[2],"digest type":c[3],digest:R(c.subarray(4)).toUpperCase(),timestamp:o,location:r})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=new DataView(i.buffer,i.byteOffset);return new st({owner:t,ttl:s,class:e,type:"DS","key tag":n.getUint16(0),algorithm:i[2],"digest type":i[3],digest:R(i.subarray(4)).toUpperCase()})}toTinydns(){return this.getTinydnsGeneric(A(this.get("key tag"))+u(this.get("algorithm"))+u(this.get("digest type"))+O(this.get("digest").replace(/\s+/g,"")))}getWireRdata(){const t=F(this.get("digest").replace(/\s+/g,"")),e=new Uint8Array(4+t.length);return new DataView(e.buffer,e.byteOffset).setUint16(0,this.get("key tag")),e[2]=this.get("algorithm"),e[3]=this.get("digest type"),e.set(t,4),e}}class jt extends f{static typeName="HINFO";static typeId=13;static RFCs=[1034,1035,8482];static rdataFields=[["cpu","qcharstr"],["os","qcharstr"]];static tags=["obsolete"];constructor(t){super(t)}setCpu(t){t.length>255&&this.throwHelp("HINFO cpu cannot exceed 255 chars"),this.set("cpu",t.replace(/^["']|["']$/g,""))}setOs(t){t.length>255&&this.throwHelp("HINFO os cannot exceed 255 chars"),this.set("os",t.replace(/^["']|["']$/g,""))}getDescription(){return"Host Info"}getCanonical(){return{owner:"test.example.com.",ttl:3600,class:"IN",type:"HINFO",cpu:"DEC-2060",os:"TOPS20"}}fromTinydns({tinyline:t}){const[e,,s,i,n,a]=t.slice(1).split(":"),[o,r]=[...te(s)];return new this.constructor({owner:this.fullyQualify(e),ttl:parseInt(i,10),type:"HINFO",cpu:o,os:r,timestamp:n,location:a?.trim()??""})}getWireRdata(){const t=new TextEncoder().encode(this.get("cpu")),e=new TextEncoder().encode(this.get("os")),s=new Uint8Array(2+t.length+e.length);return s[0]=t.length,s.set(t,1),s[1+t.length]=e.length,s.set(e,2+t.length),s}toTinydns(){return this.getTinydnsGeneric([Bt(this.get("cpu")),Bt(this.get("os"))].join(""))}}class K extends f{static typeName="HIP";static typeId=55;static RFCs=[8005];static rdataFields=["pk algorithm","hit","public key","rendezvous servers"];constructor(t){super(t)}setPkAlgorithm(t){t===void 0&&this.throwHelp("HIP: pk algorithm is required"),this.is8bitInt("HIP","pk algorithm",t),this.set("pk algorithm",t)}setHit(t){t||this.throwHelp("HIP: hit is required"),this.set("hit",t)}setPublicKey(t){t||this.throwHelp("HIP: public key is required"),this.set("public key",t)}setRendezvousServers(t){this.set("rendezvous servers",t??"")}getDescription(){return"Host Identity Protocol"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"HIP","pk algorithm":2,hit:"200100107B1A74DF365639CC39F1D578","public key":"AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwIXAqcOTiW7iHnQt5hwVAAAAA==","rendezvous servers":""}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");s!=55&&this.throwHelp("HIP fromTinydns, invalid n");const r=Uint8Array.from(x(i),b=>b.charCodeAt(0)),c=r[0],h=r[1],p=r[2]<<8|r[3],d=R(r.subarray(4,4+c)).toUpperCase(),g=V(r.subarray(4+c,4+c+p)),y=[];let m=4+c+p;for(;m<r.length;){const[b,w]=U([...r.subarray(m)].map(T=>T<32||T>126?u(T):String.fromCharCode(T)).join(""));m+=w,b!=="."&&y.push(b)}return new K({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"HIP","pk algorithm":h,hit:d,"public key":g,"rendezvous servers":y.join(" "),timestamp:a,location:o?.trim()??""})}fromBind({bindline:t}){const e=t.split(/\s+/),[s,i,n,a,o,r]=e,c=e.slice(6),h=[],p=[];for(const d of c)/^[A-Za-z0-9+/=]+$/.test(d)?h.push(d):p.push(d);return new K({owner:s,ttl:parseInt(i,10),class:n,type:a,"pk algorithm":parseInt(o,10),hit:r,"public key":h.join(""),"rendezvous servers":p.join(" ").trim()})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=new DataView(i.buffer,i.byteOffset),a=i[0],o=i[1],r=n.getUint16(2),c=R(i.subarray(4,4+a)).toUpperCase(),h=V(i.subarray(4+a,4+a+r)),p=[];let d=4+a+r;for(;d<i.length;){const{fqdn:g,end:y}=this.wireUnpackDomain(i,d);p.push(g),d=y}return new K({owner:t,ttl:s,class:e,type:"HIP","pk algorithm":o,hit:c,"public key":h,"rendezvous servers":p.join(" ")})}toBind(t){const e=this.get("rendezvous servers"),s=e?` ${e}`:"";return`${this.getPrefix(t)} ${this.get("pk algorithm")} ${this.get("hit")} ${this.get("public key")}${s}
16
+ `}toTinydns(){const t=this.get("hit"),e=F(t),s=L(this.get("public key")),i=this.get("rendezvous servers");let n="";n+=u(e.length),n+=u(this.get("pk algorithm")),n+=A(s.length);for(const a of e)n+=u(a);for(const a of s)n+=u(a);if(i)for(const a of i.split(/\s+/))n+=N(a);return this.getTinydnsGeneric(n)}getWireRdata(){const t=this.get("hit"),e=F(t),s=L(this.get("public key")),i=this.get("rendezvous servers"),a=(i?i.split(/\s+/):[]).map(d=>W(d)),o=a.reduce((d,g)=>d+g.length,0),r=4+e.length+s.length+o,c=new Uint8Array(r),h=new DataView(c.buffer,c.byteOffset);let p=0;c[p++]=e.length,c[p++]=this.get("pk algorithm"),h.setUint16(p,s.length),p+=2,c.set(e,p),p+=e.length,c.set(s,p),p+=s.length;for(const d of a)c.set(d,p),p+=d.length;return c}}class it extends f{static typeName="HTTPS";static typeId=65;static RFCs=[9460];static tags=["common"];static rdataFields=[["priority","u16"],["target name","fqdn"],["params","svcparams"]];constructor(t){super(t)}setPriority(t){this.is16bitInt("HTTPS","priority",t),this.set("priority",t)}setTargetName(t){this.set("target name",t.toLowerCase())}setParams(t){this.set("params",t)}getDescription(){return"HTTP Semantics"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"HTTPS",priority:1,"target name":"example.com.",params:'alpn="h2,h3"'}}fromBind({bindline:t}){const[e,s,i,n,a,o]=t.split(/\s+/);return new it({owner:e,ttl:parseInt(s,10),class:i,type:n,priority:parseInt(a,10),"target name":o,params:t.split(/\s+/).slice(6).join(" ").trim()})}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("HTTPS fromTinydns, invalid n");const{priority:r,targetName:c,params:h}=Mt(i,"HTTPS");return new it({owner:e,ttl:n,type:"HTTPS",priority:r,"target name":c,params:h,timestamp:a,location:o})}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g");return this.getTinydnsGeneric(A(this.get("priority"))+N(this.get("target name"))+I(t,this.get("params")))}getWireRdata(){const t=this.wirePackDomain(this.get("target name")),e=Wt(this.get("params")),s=new Uint8Array(2+t.length+e.length);return new DataView(s.buffer).setUint16(0,this.get("priority")),s.set(t,2),s.set(e,2+t.length),s}}class Q extends f{static typeName="IPSECKEY";static typeId=45;static RFCs=[4025];static rdataFields=["precedence","gateway type","algorithm","gateway","publickey"];static tags=["security"];constructor(t){super(t)}setPrecedence(t){this.is8bitInt("IPSECKEY","precedence",t),this.set("precedence",t)}setGatewayType(t){this.getGatewayTypeOptions().has(t)||this.throwHelp("IPSECKEY: Gateway Type is invalid"),this.set("gateway type",t)}getGatewayTypeOptions(){return new Map([[0,"none"],[1,"4-byte IPv4"],[2,"16-byte IPv6"],[3,"wire encoded domain name"]])}setAlgorithm(t){this.getAlgorithmOptions().has(t)||this.throwHelp("IPSECKEY: Algorithm invalid"),this.set("algorithm",t)}getAlgorithmOptions(){return new Map([[1,"DSA"],[2,"RSA"]])}setGateway(t){const e=this.get("gateway type"),s=new Error(`IPSECKEY: gateway invalid (${t}) for type ${e}`);switch(e){case 0:if(t!==".")throw s;break;case 1:if(!this.isIPv4(t))throw s;break;case 2:if(!this.isIPv6(t))throw s;break}this.set("gateway",t)}setPublickey(t){t&&this.isBase64("IPSECKEY","publickey",t),this.set("publickey",t)}getDescription(){return"IPsec Keying"}getCanonical(){return{owner:"38.2.0.192.in-addr.arpa.",ttl:7200,class:"IN",type:"IPSECKEY",precedence:10,"gateway type":1,algorithm:2,gateway:"192.0.2.38",publickey:"AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ=="}}fromBind({bindline:t}){const[e,s,i,n,a,o,r,c,h]=t.split(/\s+/);return new Q({owner:e,ttl:parseInt(s,10),class:i,type:n,precedence:parseInt(a,10),"gateway type":parseInt(o,10),algorithm:parseInt(r,10),gateway:c,publickey:h})}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");s!=45&&this.throwHelp("IPSECKEY fromTinydns, invalid n");const r=E(i.slice(0,4)),c=E(i.slice(4,8)),h=E(i.slice(8,12));let p,d,g;switch(c){case 0:d=i.slice(12,13),g=i.slice(13);break;case 1:d=se(i.slice(12,28)),g=i.slice(28);break;case 2:d=ne(i.slice(12,76)),g=i.slice(76);break;case 3:[d,p]=U(i.slice(12)),g=i.slice(12+p);break}return new Q({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"IPSECKEY",precedence:r,"gateway type":c,algorithm:h,gateway:d,publickey:ut(g),timestamp:a,location:o?.trim()??""})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=i[0],a=i[1],o=i[2];let r,c;switch(a){case 0:r=".",c=3;break;case 1:r=[...i.subarray(3,7)].join("."),c=7;break;case 2:{const p=new DataView(i.buffer,i.byteOffset+3),d=[];for(let g=0;g<16;g+=2)d.push(p.getUint16(g).toString(16).padStart(4,"0"));r=d.join(":"),c=19;break}case 3:{const{fqdn:p,end:d}=this.wireUnpackDomain(i,3);r=p,c=d;break}}const h=V(i.subarray(c));return new Q({owner:t,ttl:s,class:e,type:"IPSECKEY",precedence:n,"gateway type":a,algorithm:o,gateway:r,publickey:h})}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g");let e="";switch(e+=u(this.get("precedence")),e+=u(this.get("gateway type")),e+=u(this.get("algorithm")),this.get("gateway type")){case 0:e+=I(t,".");break;case 1:e+=qt(this.get("gateway"));break;case 2:e+=ie(this.get("gateway"));break;case 3:e+=N(this.get("gateway"));break}return e+=G(this.get("publickey")),this.getTinydnsGeneric(e)}getWireRdata(){const t=L(this.get("publickey")),e=this.get("gateway type");let s;switch(e){case 0:s=new Uint8Array(0);break;case 1:s=new Uint8Array(4),this.get("gateway").split(".").forEach((n,a)=>{s[a]=parseInt(n,10)});break;case 2:s=new Uint8Array(16);{const n=this.get("gateway").split(":");let a=0;for(const o of n){if(o==="")continue;const r=parseInt(o,16);s[a++]=r>>>8&255,s[a++]=r&255}}break;case 3:s=W(this.get("gateway"));break}const i=new Uint8Array(3+s.length+t.length);return i[0]=this.get("precedence"),i[1]=e,i[2]=this.get("algorithm"),i.set(s,3),i.set(t,3+s.length),i}}class nt extends f{static typeName="KEY";static typeId=25;static RFCs=[2535,3445,4034,6840];static rdataFields=[["flags","u16"],["protocol","u8"],["algorithm","u8"],["publickey","base64"]];static tags=["obsolete"];constructor(t){super(t)}setFlags(t){this.is16bitInt("KEY","flags",t),this.set("flags",t)}setProtocol(t){this.is8bitInt("KEY","protocol",t),this.set("protocol",t)}setAlgorithm(t){this.getAlgorithmOptions().has(t)||this.throwHelp("KEY: algorithm invalid"),this.set("algorithm",t)}getAlgorithmOptions(){return new Map([[1,"RSA/MD5"],[2,"DH"],[3,"DSA/SHA-1"],[4,"EC"],[5,"RSA/SHA-1"],[253,""],[254,""]])}setPublickey(t){t||this.throwHelp("KEY: publickey is required"),this.isBase64("KEY","publickey",t.replace(/[\s()]/g,"")),this.set("publickey",t)}getDescription(){return"DNS Public Key"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"KEY",flags:256,protocol:3,algorithm:5,publickey:"AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwIXAqcOTiW7iHnQt5hwVAAAAA=="}}fromBind({bindline:t}){const[e,s,i,n,a,o,r]=t.split(/\s+/);return new nt({owner:e,ttl:parseInt(s,10),class:i,type:n,flags:parseInt(a,10),protocol:parseInt(o,10),algorithm:parseInt(r,10),publickey:t.split(/\s+/).slice(7).join(" ").trim()})}fromTinydns({tinyline:t}){const{owner:e,rdata:s,ttl:i,timestamp:n,location:a}=this.parseTinydnsLine(t);return s.length<16&&this.throwHelp(`KEY: RDATA too short: ${s}`),new nt({owner:e,ttl:i,type:"KEY",flags:B(s.slice(0,8)),protocol:E(s.slice(8,12)),algorithm:E(s.slice(12,16)),publickey:ut(s.slice(16)),timestamp:n,location:a})}toTinydns(){return this.getTinydnsGeneric(A(this.get("flags"))+u(this.get("protocol"))+u(this.get("algorithm"))+G(this.get("publickey").replace(/[\s()]/g,"")))}getWireRdata(){const t=L(this.get("publickey").replace(/[\s()]/g,"")),e=new Uint8Array(4+t.length);return new DataView(e.buffer,e.byteOffset).setUint16(0,this.get("flags")),e[2]=this.get("protocol"),e[3]=this.get("algorithm"),e.set(t,4),e}}class bt extends f{static typeName="KX";static typeId=36;static RFCs=[2230];static rdataFields=[["preference","u16"],["exchanger","fqdn"]];constructor(t){super(t)}setPreference(t){t===void 0&&this.throwHelp("KX: preference is required"),this.is16bitInt("KX","preference",t),this.set("preference",t)}setExchanger(t){t||this.throwHelp("KX: exchanger is required"),this.isFullyQualified("KX","exchanger",t),this.isValidHostname("KX","exchanger",t),this.set("exchanger",t.toLowerCase())}getDescription(){return"Key Exchanger"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"KX",preference:10,exchanger:"kx.example.com."}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");return s!=36&&this.throwHelp("KX fromTinydns, invalid n"),new bt({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"KX",preference:B(i.slice(0,8)),exchanger:U(i.slice(8))[0],timestamp:a,location:o?.trim()??""})}getWireRdata(){const t=this.wirePackDomain(this.get("exchanger")),e=new Uint8Array(2+t.length);return new DataView(e.buffer).setUint16(0,this.get("preference")),e.set(t,2),e}toTinydns(){return this.getTinydnsGeneric(A(this.get("preference"))+N(this.get("exchanger")))}}const M={LATLON:2**31,ALTITUDE:1e5*100},k={sec:1e3,min:60*1e3,deg:3600*1e3};class Y extends f{static typeName="LOC";static typeId=29;static RFCs=[1876];static rdataFields=["address"];constructor(t){super(t)}setAddress(t){t||this.throwHelp("LOC: address is required"),this.parseLoc(t),this.set("address",t)}getDescription(){return"Location"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"LOC",address:"52 22 23.000 N 4 53 32.000 E 10m 100m 10m 2m"}}parseLoc(t){const e="(\\d+)\\s+(?:(\\d+)\\s+)?(?:([\\d.]+)\\s+)?",s="(-?[\\d.]+)m?(?:\\s+([\\d.]+)m?)?(?:\\s+([\\d.]+)m?)?(?:\\s+([\\d.]+)m?)?",i=new RegExp(`^${e}(N|S)\\s+${e}(E|W)\\s+${s}`,"i"),n=t.match(i);return n||this.throwHelp("LOC address: invalid format, see RFC 1876"),{latitude:{degrees:n[1],minutes:n[2],seconds:n[3],hemisphere:n[4].toUpperCase()},longitude:{degrees:n[5],minutes:n[6],seconds:n[7],hemisphere:n[8].toUpperCase()},altitude:n[9]*100,size:n[10]*100,precision:{horizontal:n[11]*100,vertical:n[12]*100}}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");s!=29&&this.throwHelp("LOC fromTinydns, invalid n");const r={version:E(i.slice(0,4)),size:this.fromExponent(E(i.slice(4,8))),precision:{horizontal:this.fromExponent(E(i.slice(8,12))),vertical:this.fromExponent(E(i.slice(12,16)))},latitude:this.arcSecToDMS(gt(i.slice(16,32)),"lat"),longitude:this.arcSecToDMS(gt(i.slice(32,48)),"lon"),altitude:gt(i.slice(48,64))-M.ALTITUDE};return new Y({type:"LOC",owner:this.fullyQualify(e),address:this.toHuman(r),ttl:parseInt(n,10),timestamp:a,location:o?.trim()??""})}fromBind({bindline:t}){const[e,s,i,n]=t.split(/\s+/);return new Y({owner:e,ttl:parseInt(s,10),class:i,type:n,address:t.split(/\s+/).slice(4).join(" ").trim()})}dmsToArcSec(t){let e=t.degrees*k.deg+(t.minutes??0)*k.min+(t.seconds??0)*k.sec;switch(t.hemisphere.toUpperCase()){case"W":case"S":e=-e;break}return e+=M.LATLON,e}arcSecToDMS(t,e){let s=Math.abs(t-M.LATLON);const i=Math.floor(s/k.deg);s-=i*k.deg;const n=Math.floor(s/k.min);s-=n*k.min;const a=Math.floor(s/k.sec);s-=a*k.sec;let o;switch(e){case"lat":o=t>=M.LATLON?"N":"S";break;case"lon":o=t>=M.LATLON?"E":"W";break;default:this.throwHelp("unknown or missing hemisphere")}return`${i} ${n} ${a}${s?"."+s:""} ${o}`}fromExponent(t){const e=(t>>4&15)%10,s=(t>>0&15)%10;return e*Math.pow(10,s)}toExponent(t){let e=0;for(;t>=10;)t/=10,++e;return parseInt(t)<<4|e&15}toHuman(t){let e=`${t.latitude} ${t.longitude} ${t.altitude/100}m`;return t.size&&(e+=` ${t.size/100}m`),t.precision.horizontal&&(e+=` ${t.precision.horizontal/100}m`),t.precision.vertical&&(e+=` ${t.precision.vertical/100}m`),e}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=new DataView(i.buffer,i.byteOffset),a={size:this.fromExponent(i[1]),precision:{horizontal:this.fromExponent(i[2]),vertical:this.fromExponent(i[3])},latitude:this.arcSecToDMS(n.getUint32(4),"lat"),longitude:this.arcSecToDMS(n.getUint32(8),"lon"),altitude:n.getUint32(12)-M.ALTITUDE};return new Y({owner:t,ttl:s,class:e,type:"LOC",address:this.toHuman(a)})}toTinydns(){const t=this.parseLoc(this.get("address"));let e="";return e+=u(0),e+=u(this.toExponent(t.size)),e+=u(this.toExponent(t.precision.horizontal)),e+=u(this.toExponent(t.precision.vertical)),e+=P(this.dmsToArcSec(t.latitude)),e+=P(this.dmsToArcSec(t.longitude)),e+=P(t.altitude+M.ALTITUDE),this.getTinydnsGeneric(e)}getWireRdata(){const t=this.parseLoc(this.get("address")),e=new Uint8Array(16),s=new DataView(e.buffer,e.byteOffset);return e[0]=0,e[1]=this.toExponent(t.size),e[2]=this.toExponent(t.precision.horizontal),e[3]=this.toExponent(t.precision.vertical),s.setUint32(4,this.dmsToArcSec(t.latitude)),s.setUint32(8,this.dmsToArcSec(t.longitude)),s.setUint32(12,t.altitude+M.ALTITUDE),e}}class Tt extends f{static typeName="MX";static typeId=15;static RFCs=[1035,2181,7505];static tinydnsType="@";static rdataFields=[["preference","u16"],["exchange","fqdn"]];static tags=["common"];constructor(t){super(t)}setPreference(t){t===void 0&&(t=this?.default?.preference),t===void 0&&this.throwHelp("MX: preference is required"),this.is16bitInt("MX","preference",t),this.set("preference",t)}getDescription(){return"Mail Exchanger"}getCanonical(){return{owner:"example.com.",ttl:43200,class:"IN",type:"MX",preference:10,exchange:"mail.example.com."}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o,r]=t.slice(1).split(":");return new Tt({type:"MX",owner:this.fullyQualify(e),exchange:this.fullyQualify(/\./.test(i)?i:`${i}.mx.${e}`),preference:parseInt(n,10)||0,ttl:parseInt(a,10),timestamp:o,location:r?.trim()??""})}getWireRdata(){const t=this.wirePackDomain(this.get("exchange")),e=new Uint8Array(2+t.length);return new DataView(e.buffer).setUint16(0,this.get("preference")),e.set(t,2),e}toTinydns(){return`@${this.getTinyFQDN("owner")}::${this.getTinyFQDN("exchange")}:${this.get("preference")}:${this.getTinydnsPostamble()}
17
+ `}}const Ft=/[\r\n\t:\\/]/;class rt extends f{static typeName="NAPTR";static typeId=35;static RFCs=[2915,3403,4848];static rdataFields=[["order","u16"],["preference","u16"],["flags","qcharstr"],["service","qcharstr"],["regexp","qcharstr"],["replacement","fqdn"]];constructor(t){super(t)}getDescription(){return"Naming Authority Pointer"}getCanonical(){return{owner:"cid.urn.arpa.",ttl:3600,class:"IN",type:"NAPTR",order:100,preference:10,flags:"S",service:"z3950+N2L+N2R",regexp:"",replacement:"gatekeeper.example.com."}}setOrder(t){this.is16bitInt("NAPTR","order",t),this.set("order",t)}setPreference(t){this.is16bitInt("NAPTR","preference",t),this.set("preference",t)}setFlags(t){this.getFlagsOptions().has(t.toUpperCase())||this.throwHelp("NAPTR flags are invalid"),this.set("flags",t.toUpperCase())}getFlagsOptions(){return new Map([[""],["S"],["A"],["U"],["P"]])}setService(t){this.set("service",t)}setRegexp(t){this.set("regexp",t)}setReplacement(t){this.set("replacement",t)}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("NAPTR fromTinydns, invalid n");const r=H(i),c=new DataView(r.buffer,r.byteOffset,r.byteLength),h={type:"NAPTR",owner:e,ttl:n,timestamp:a,location:o,order:c.getUint16(0),preference:c.getUint16(2)};let p=4;const d=r[p];p++,h.flags=new TextDecoder().decode(r.subarray(p,p+d)),p+=d;const g=r[p];p++,h.service=new TextDecoder().decode(r.subarray(p,p+g)),p+=g;const y=r[p];p++,h.regexp=new TextDecoder().decode(r.subarray(p,p+y)),p+=y;const m=r[p];return p++,h.replacement=new TextDecoder().decode(r.subarray(p,p+m)),new rt(h)}fromBind({bindline:t}){const e=/^(?<owner>\S+)\s+(?<ttl>\d+)\s+(?<class>\S+)\s+(?<type>NAPTR)\s+(?<order>\d+)\s+(?<preference>\d+)\s+["'](?<flags>[^"']*)["']\s+["'](?<service>[^"']*)["']\s+["'](?<regexp>[^"']*)["']\s+(?<replacement>\S+)$/,s=t.trim().match(e);if(!s)throw new Error(`Invalid NAPTR BIND line: ${t}`);const{owner:i,ttl:n,type:a,order:o,preference:r,flags:c,service:h,regexp:p,replacement:d}=s.groups;return new rt({owner:this.fullyQualify(i),ttl:parseInt(n,10),class:s.groups.class,type:a,order:parseInt(o,10),preference:parseInt(r,10),flags:c,service:h,regexp:p,replacement:d})}toTinydns(){let t=A(this.get("order"))+A(this.get("preference"))+u(this.get("flags").length)+this.get("flags")+u(this.get("service").length)+I(Ft,this.get("service"))+u(this.get("regexp").length)+I(Ft,this.get("regexp"));const e=this.get("replacement");return e!==""&&(t+=u(e.length),t+=I(Ft,e)),t+="\\000",this.getTinydnsGeneric(t)}getWireRdata(){const t=new TextEncoder,e=t.encode(this.get("flags")),s=t.encode(this.get("service")),i=t.encode(this.get("regexp")),n=this.wirePackDomain(this.get("replacement")),a=5+e.length+1+s.length+1+i.length+n.length,o=new Uint8Array(a),r=new DataView(o.buffer);let c=0;return r.setUint16(c,this.get("order")),c+=2,r.setUint16(c,this.get("preference")),c+=2,o[c++]=e.length,o.set(e,c),c+=e.length,o[c++]=s.length,o.set(s,c),c+=s.length,o[c++]=i.length,o.set(i,c),c+=i.length,o.set(n,c),o}}class At extends f{static typeName="NS";static typeId=2;static RFCs=[1035];static tinydnsType="&";static rdataFields=[["dname","fqdn"]];static tags=["common"];constructor(t){super(t)}setDname(t){t||this.throwHelp("NS: dname is required"),this.isFullyQualified("NS","dname",t),this.isValidHostname("NS","dname",t),this.set("dname",t.toLowerCase())}getDescription(){return"Name Server"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"NS",dname:"ns1.example.com."}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");return new At({type:"NS",owner:this.fullyQualify(e),dname:this.fullyQualify(/\./.test(i)?i:`${i}.ns.${e}`),ttl:parseInt(n,10),timestamp:a,location:o?.trim()??""})}getWireRdata(){return this.wirePackDomain(this.get("dname"))}toTinydns(){return`&${this.getTinyFQDN("owner")}::${this.getTinyFQDN("dname")}:${this.getTinydnsPostamble()}
18
+ `}}class X extends f{static typeName="NSEC";static typeId=47;static RFCs=[4034];static rdataFields=["next domain","type bit maps"];static tags=["dnssec"];constructor(t){super(t)}setNextDomain(t){t||this.throwHelp("NSEC: 'next domain' is required:"),this.isFullyQualified("NSEC","next domain",t),this.isValidHostname("NSEC","next domain",t),this.set("next domain",t.toLowerCase())}setTypeBitMaps(t){t||this.throwHelp("NSEC: 'type bit maps' is required"),this.set("type bit maps",t)}getDescription(){return"Next Secure"}getCanonical(){return{owner:"alfa.example.com.",ttl:3600,class:"IN",type:"NSEC","next domain":"host.example.com.","type bit maps":"A MX RRSIG NSEC TYPE1234"}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":"),r=Uint8Array.from(x(i),d=>d.charCodeAt(0)),[c,h,p]=U(i);return new X({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"NSEC","next domain":c,"type bit maps":new TextDecoder().decode(r.subarray(p)),timestamp:a,location:o?.trim()??""})}fromBind({bindline:t}){const[e,s,i,n,a]=t.split(/\s+/);return new X({owner:e,ttl:parseInt(s,10),class:i,type:n,"next domain":a,"type bit maps":t.split(/\s+/).slice(5).filter(me).join(" ").trim()})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const{fqdn:n,end:a}=this.wireUnpackDomain(i,0),o=we(i.subarray(a));return new X({owner:t,ttl:s,class:e,type:"NSEC","next domain":n,"type bit maps":o})}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g");return this.getTinydnsGeneric(N(this.get("next domain"))+I(t,this.get("type bit maps")))}getWireRdata(){const t=this.wirePackDomain(this.get("next domain")),e=be(this.get("type bit maps")),s=new Uint8Array(t.length+e.length);return s.set(t),s.set(e,t.length),s}}const me=l=>!["(",")"].includes(l);function we(l){const t=Object.fromEntries(Object.entries(q).map(([i,n])=>[n,i])),e=[];let s=0;for(;s+2<=l.length;){const i=l[s],n=l[s+1];s+=2;for(let a=0;a<n;a++){const o=l[s+a];for(let r=0;r<8;r++)if(o&128>>r){const c=i*256+a*8+r;e.push(t[c]??`TYPE${c}`)}}s+=n}return e.join(" ")}function be(l){const t=l.trim().split(/\s+/).map(o=>/^TYPE\d+$/i.test(o)?parseInt(o.slice(4),10):q[o.toUpperCase()]).filter(o=>o!==void 0&&o>=0),e=new Map;for(const o of t){const r=Math.floor(o/256);e.has(r)||e.set(r,[]),e.get(r).push(o%256)}const s=[];for(const[o,r]of[...e.entries()].sort((c,h)=>c[0]-h[0])){const c=Math.max(...r),h=Math.floor(c/8)+1,p=new Uint8Array(h);for(const d of r)p[Math.floor(d/8)]|=128>>d%8;s.push(new Uint8Array([o,h,...p]))}const i=s.reduce((o,r)=>o+r.length,0),n=new Uint8Array(i);let a=0;for(const o of s)n.set(o,a),a+=o.length;return n}class z extends f{static typeName="NSEC3";static typeId=50;static RFCs=[5155,9077];static rdataFields=["hash algorithm","flags","iterations","salt","next hashed owner name","type bit maps"];static tags=["dnssec"];constructor(t){super(t)}setHashAlgorithm(t){t||this.throwHelp("NSEC3: 'hash algorithm' is required"),this.is8bitInt("NSEC3","hash algorithm",t),this.set("hash algorithm",t)}setFlags(t){t||this.throwHelp("NSEC3: 'flags' is required"),this.is8bitInt("NSEC3","flags",t),this.set("flags",t)}setIterations(t){t||this.throwHelp("NSEC3: 'iterations' is required"),this.is16bitInt("NSEC3","flags",t),this.set("iterations",t)}setSalt(t){this.set("salt",t)}setNextHashedOwnerName(t){t||this.throwHelp("NSEC3: 'next hashed owner name' is required"),this.set("next hashed owner name",t)}setTypeBitMaps(t){t||this.throwHelp("NSEC3: 'type bit maps' is required"),this.set("type bit maps",t)}getDescription(){return"Next Secure"}getCanonical(){return{owner:"test.example.com.",ttl:3600,class:"IN",type:"NSEC3","hash algorithm":1,flags:1,iterations:12,salt:"aabbccdd","next hashed owner name":"2vptu5timamqttgl4luu9kg21e0aor3s","type bit maps":"A RRSIG"}}fromBind({bindline:t}){const[e,s,i,n,a,o,r,c]=t.split(/\s+/),h=t.includes("(")?t.split(/\(|\)/)[1]:t.split(/\s+/).slice(8).join(" ");return new z({owner:e,ttl:parseInt(s,10),class:i,type:n,"hash algorithm":parseInt(a,10),flags:parseInt(o,10),iterations:parseInt(r,10),salt:c,"next hashed owner name":h.trim().split(/\s+/)[0],"type bit maps":h.trim().split(/\s+/).slice(1).join(" ")})}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");s!=50&&this.throwHelp("NSEC3 fromTinydns, invalid n");const r=Uint8Array.from(x(i),b=>b.charCodeAt(0)),c=new DataView(r.buffer,r.byteOffset,r.byteLength),h=r[0],p=r[1],d=c.getUint16(2),{salt:g,nextHashedOwnerName:y,typeBitMaps:m}=Kt(r);return new z({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"NSEC3","hash algorithm":h,flags:p,iterations:d,salt:g,"next hashed owner name":y,"type bit maps":m,timestamp:a,location:o?.trim()??""})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=new DataView(i.buffer,i.byteOffset),{salt:a,nextHashedOwnerName:o,typeBitMaps:r}=Kt(i);return new z({owner:t,ttl:s,class:e,type:"NSEC3","hash algorithm":i[0],flags:i[1],iterations:n.getUint16(2),salt:a,"next hashed owner name":o,"type bit maps":r})}toBind(t){return`${this.getFQDN("owner",t)} ${this.get("ttl")} ${this.get("class")} NSEC3${this.getRdataFields().slice(0,4).map(e=>" "+this.get(e)).join("")} (${this.getRdataFields().slice(4).map(e=>this.get(e)).join(" ")})
19
+ `}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g");return this.getTinydnsGeneric(u(this.get("hash algorithm"))+u(this.get("flags"))+A(this.get("iterations"))+I(t,this.get("salt"))+I(t,this.get("next hashed owner name"))+I(t,this.get("type bit maps")))}getWireRdata(){const t=`${this.get("salt")}${this.get("next hashed owner name")}${this.get("type bit maps")}`,e=new TextEncoder().encode(t),s=4+e.length,i=new Uint8Array(s),n=new DataView(i.buffer,i.byteOffset);let a=0;return i[a++]=this.get("hash algorithm"),i[a++]=this.get("flags"),n.setUint16(a,this.get("iterations")),a+=2,i.set(e,a),i}}function Kt(l){const t=new TextDecoder().decode(l.subarray(4)),e=l[0],s=e===1?32:e===2?52:32;let i="",n="",a="";const o=Math.min(64,t.length);for(let r=o;r>=1;r--){const c=t.slice(r,r+s);if(c.length!==s||!/^[0-9a-z]+$/.test(c))continue;const h=t.slice(0,r);if(/^[0-9A-Fa-f]+$/.test(h)){i=h,n=c,a=t.slice(r+s);break}}if(!n){const r=t.match(/^([0-9A-Fa-f]*)/);i=r?r[1]:"",n=t.slice(i.length),a=""}return{salt:i,nextHashedOwnerName:n,typeBitMaps:a}}class at extends f{static typeName="NSEC3PARAM";static typeId=51;static RFCs=[5155];static rdataFields=["hash algorithm","flags","iterations","salt"];static tags=["dnssec"];constructor(t){super(t)}setHashAlgorithm(t){t==null&&this.throwHelp("NSEC3PARAM: 'hash algorithm' is required"),this.is8bitInt("NSEC3PARAM","hash algorithm",t),this.set("hash algorithm",t)}setFlags(t){t==null&&this.throwHelp("NSEC3PARAM: 'flags' is required"),this.is8bitInt("NSEC3PARAM","flags",t),this.set("flags",t)}setIterations(t){t==null&&this.throwHelp("NSEC3PARAM: 'iterations' is required"),this.is16bitInt("NSEC3PARAM","iterations",t),this.set("iterations",t)}setSalt(t){if(t==="-"){this.set("salt",t);return}t!=null&&!/^[0-9A-Fa-f]*$/.test(t)&&this.throwHelp("NSEC3PARAM: 'salt' must be hex or '-'"),this.set("salt",t)}getDescription(){return"Next Secure Parameters"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"NSEC3PARAM","hash algorithm":1,flags:1,iterations:12,salt:"aabbccdd"}}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("NSEC3PARAM fromTinydns, invalid n"),i.length<4&&this.throwHelp(`NSEC3PARAM: RDATA too short: ${i}`);const r=H(i);return new at({owner:e,ttl:n,type:"NSEC3PARAM","hash algorithm":r[0],flags:r[1],iterations:r[2]<<8|r[3],salt:r[4]===0?"-":R(r.subarray(5,5+r[4])),timestamp:a,location:o})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=new DataView(i.buffer,i.byteOffset),a=i[4],o=a===0?"-":R(i.subarray(5,5+a));return new at({owner:t,ttl:s,class:e,type:"NSEC3PARAM","hash algorithm":i[0],flags:i[1],iterations:n.getUint16(2),salt:o})}toTinydns(){const t=this.get("salt"),e=t==="-"?u(0):u(t.length/2)+O(t);return this.getTinydnsGeneric(u(this.get("hash algorithm"))+u(this.get("flags"))+A(this.get("iterations"))+e)}getWireRdata(){const t=this.get("salt"),e=t==="-"?new Uint8Array(0):F(t),s=new Uint8Array(5+e.length),i=new DataView(s.buffer,s.byteOffset);return s[0]=this.get("hash algorithm"),s[1]=this.get("flags"),i.setUint16(2,this.get("iterations")),s[4]=e.length,s.set(e,5),s}}class v extends f{static typeName="NXT";static typeId=30;static RFCs=[2065];static rdataFields=["next domain","type bit map"];static tags=["obsolete"];constructor(t){super(t)}setNextDomain(t){t||this.throwHelp("NXT: 'next domain' is required"),this.isFullyQualified("NXT","next domain",t),this.isValidHostname("NXT","next domain",t),this.set("next domain",t.toLowerCase())}setTypeBitMap(t){t||this.throwHelp("NXT: 'type bit map' is required"),this.set("type bit map",t)}getDescription(){return"Next Secure"}getCanonical(){return{owner:"big.example.com.",ttl:3600,class:"IN",type:"NXT","next domain":"host.example.com.","type bit map":"A MX NXT"}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");parseInt(s,10)!==this.getTypeId()&&this.throwHelp("NXT fromTinydns, invalid n");const r=Uint8Array.from(x(i),d=>d.charCodeAt(0)),[c,h,p]=U(i);return new v({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"NXT","next domain":c,"type bit map":new TextDecoder().decode(r.subarray(p)),timestamp:a,location:o?.trim()??""})}fromBind({bindline:t}){const[e,s,i,n,a]=t.split(/\s+/);return new v({owner:e,ttl:parseInt(s,10),class:i,type:n,"next domain":a,"type bit map":t.split(/\s+/).slice(5).filter(Te).join(" ").trim()})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const{fqdn:n,end:a}=this.wireUnpackDomain(i,0),o=Ae(i.subarray(a));return new v({owner:t,ttl:s,class:e,type:"NXT","next domain":n,"type bit map":o})}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g");return this.getTinydnsGeneric(N(this.get("next domain"))+I(t,this.get("type bit map")))}getWireRdata(){const t=this.wirePackDomain(this.get("next domain")),e=Ie(this.get("type bit map")),s=new Uint8Array(t.length+e.length);return s.set(t),s.set(e,t.length),s}}const Te=l=>!["(",")"].includes(l);function Ae(l){const t=Object.fromEntries(Object.entries(q).map(([s,i])=>[i,s])),e=[];for(let s=0;s<l.length;s++){const i=l[s];for(let n=0;n<8;n++)if(i&128>>n){const a=s*8+n;e.push(t[a]??`TYPE${a}`)}}return e.join(" ")}function Ie(l){const t=new Uint8Array(16);for(const s of l.trim().split(/\s+/)){const i=/^TYPE\d+$/i.test(s)?parseInt(s.slice(4),10):q[s.toUpperCase()];i!==void 0&&i<128&&(t[Math.floor(i/8)]|=128>>i%8)}let e=t.length;for(;e>0&&t[e-1]===0;)e--;return t.slice(0,e)}class ot extends f{static typeName="OPENPGPKEY";static typeId=61;static RFCs=[4880,7929];static rdataFields=[["public key","base64"]];static tags=["security"];constructor(t){super(t)}setPublicKey(t){this.isBase64("OPENPGPKEY","public key",t),this.set("public key",t)}getDescription(){return"OpenPGP Public Key"}getCanonical(){return{owner:"matt.example.com.",ttl:3600,class:"IN",type:"OPENPGPKEY","public key":"AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwIXAqcOTiW7iHnQt5hwVAAAAA=="}}fromBind({bindline:t}){const e=/^(?<owner>\S+)\s+(?<ttl>\d{1,10})\s+(?<class>IN)\s+(?<type>OPENPGPKEY)\s+(?<publickey>\S[\s\S]*)$/i,s=t.trim().match(e);s||this.throwHelp(`unable to parse OPENPGPKEY: ${t}`);const{owner:i,ttl:n,class:a,type:o,publickey:r}=s.groups,c=r.trim().replace(/\s+/g,"");return new ot({owner:i,ttl:parseInt(n,10),class:a,type:o,"public key":c})}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);return s!=this.getTypeId()&&this.throwHelp("OPENPGPKEY fromTinydns, invalid n"),new ot({owner:e,ttl:n,type:"OPENPGPKEY","public key":ut(i),timestamp:a,location:o})}toTinydns(){return this.getTinydnsGeneric(G(this.get("public key")))}getWireRdata(){return L(this.get("public key"))}}class Qt extends f{static typeName="PTR";static typeId=12;static RFCs=[1035];static tinydnsType="^";static rdataFields=[["dname","fqdn"]];static tags=["common"];constructor(t){super(t)}setDname(t){this.isFullyQualified("PTR","dname",t),this.isValidHostname("PTR","dname",t),this.set("dname",t.toLowerCase())}getDescription(){return"Pointer"}getCanonical(){return{owner:"2.2.0.192.in-addr.arpa.",ttl:3600,class:"IN",type:"PTR",dname:"host.example.com."}}getWireRdata(){return this.wirePackDomain(this.get("dname"))}}class It extends f{static typeName="RP";static rdataFields=[["mbox","fqdn"],["txt","fqdn"]];constructor(t){super(t)}setMbox(t){t||this.throwHelp("RP: mbox is required"),this.isFullyQualified("RP","mbox",t),this.set("mbox",t.toLowerCase())}setTxt(t){t||this.throwHelp("RP: txt is required"),this.isFullyQualified("RP","txt",t),this.set("txt",t.toLowerCase())}getDescription(){return"Responsible Person"}static tags=["obsolete"];static RFCs=[1183];static typeId=17;getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"RP",mbox:"admin.example.com.",txt:"info.example.com."}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":"),[r,c]=U(i),h=U(i.slice(c))[0];return new It({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"RP",mbox:r,txt:h,timestamp:a,location:o?.trim()??""})}getWireRdata(){const t=this.wirePackDomain(this.get("mbox")),e=this.wirePackDomain(this.get("txt")),s=new Uint8Array(t.length+e.length);return s.set(t,0),s.set(e,t.length),s}toTinydns(){return this.getTinydnsGeneric(N(this.get("mbox"))+N(this.get("txt")))}}class ct extends f{static typeName="RRSIG";static typeId=46;static RFCs=[4034];static rdataFields=[["type covered","u16"],["algorithm","u8"],["labels","u8"],["original ttl","u32"],["signature expiration","u32"],["signature inception","u32"],["key tag","u16"],["signers name","fqdn"],["signature","str"]];static tags=["dnssec"];constructor(t){super(t)}setTypeCovered(t){if(!t&&t!==0&&this.throwHelp("RRSIG: 'type covered' is required"),typeof t=="string"){const e=t.match(/^TYPE(\d+)$/i);if(e)t=parseInt(e[1],10);else{const s=q[t.toUpperCase()];s===void 0&&this.throwHelp("RRSIG: 'type covered' is not a recognized type name"),t=s}}this.is16bitInt("RRSIG","type covered",t),this.set("type covered",t)}setAlgorithm(t){this.getAlgorithmOptions().has(t)||this.throwHelp("RRSIG: algorithm invalid"),this.set("algorithm",t)}getAlgorithmOptions(){return new Map([[1,"RSA/MD5"],[2,"DH"],[3,"RRSIGA/SHA-1"],[4,"EC"],[5,"RSA/SHA-1"],[253],[254]])}getDescription(){return"Resource Record Signature"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"RRSIG","type covered":1,algorithm:5,labels:3,"original ttl":3600,"signature expiration":1045053120,"signature inception":1042461120,"key tag":12345,"signers name":"example.com.",signature:"ABCDEF..."}}fromBind({bindline:t}){const e=t.trim().split(/\s+/),s=e[4],i=s.match(/^TYPE(\d+)$/i),n=/^\d+$/.test(s)?parseInt(s,10):i?parseInt(i[1],10):q[s.toUpperCase()]??parseInt(s,10);return new ct({owner:e[0],ttl:parseInt(e[1],10),class:e[2],type:"RRSIG","type covered":n,algorithm:parseInt(e[5],10),labels:parseInt(e[6],10),"original ttl":parseInt(e[7],10),"signature expiration":parseInt(e[8],10),"signature inception":parseInt(e[9],10),"key tag":parseInt(e[10],10),"signers name":e[11],signature:e.slice(12).filter(a=>a!=="("&&a!==")").join(" ").trim()})}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");parseInt(s,10)!==this.getTypeId()&&this.throwHelp("RRSIG fromTinydns, invalid n");const r=Uint8Array.from(x(i),S=>S.charCodeAt(0)),c=new DataView(r.buffer,r.byteOffset,r.byteLength),h=c.getUint16(0),p=r[2],d=r[3],g=c.getUint32(4),y=c.getUint32(8),m=c.getUint32(12),b=c.getUint16(16);let w=18;const T=[];for(;w<r.length;){const S=r[w++];if(S===0)break;T.push(new TextDecoder().decode(r.subarray(w,w+S))),w+=S}const D=`${T.join(".")}.`,C=new TextDecoder().decode(r.subarray(w));return new ct({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"RRSIG","type covered":h,algorithm:p,labels:d,"original ttl":g,"signature expiration":y,"signature inception":m,"key tag":b,"signers name":D,signature:C,timestamp:a,location:o?.trim()??""})}toTinydns(){const t=new RegExp(/[\r\n\t:]/,"g");return this.getTinydnsGeneric(A(this.get("type covered"))+u(this.get("algorithm"))+u(this.get("labels"))+P(this.get("original ttl"))+P(this.get("signature expiration"))+P(this.get("signature inception"))+A(this.get("key tag"))+N(this.get("signers name"))+I(t,this.get("signature")))}getWireRdata(){const t=W(this.get("signers name")),e=new TextEncoder().encode(this.get("signature")),s=18+t.length+e.length,i=new Uint8Array(s),n=new DataView(i.buffer,i.byteOffset);let a=0;return n.setUint16(a,this.get("type covered")),a+=2,i[a++]=this.get("algorithm"),i[a++]=this.get("labels"),n.setUint32(a,this.get("original ttl")),a+=4,n.setUint32(a,this.get("signature expiration")),a+=4,n.setUint32(a,this.get("signature inception")),a+=4,n.setUint16(a,this.get("key tag")),a+=2,i.set(t,a),a+=t.length,i.set(e,a),i}}class lt extends f{static typeName="SIG";static typeId=24;static RFCs=[2535,3755];static rdataFields=[["type covered","u16"],["algorithm","u8"],["labels","u8"],["original ttl","u32"],["signature expiration","u32"],["signature inception","u32"],["key tag","u16"],["signers name","fqdn"],["signature","str"]];static tags=["obsolete"];constructor(t){super(t)}setTypeCovered(t){t||this.throwHelp("SIG: 'type covered' is required"),this.set("type covered",t)}setAlgorithm(t){this.is8bitInt("SIG","algorithm",t),this.set("algorithm",t)}setLabels(t){this.is8bitInt("SIG","labels",t),this.set("labels",t)}setOriginalTtl(t){this.is32bitInt("SIG","original ttl",t),this.set("original ttl",t)}setSignatureExpiration(t){this.set("signature expiration",t)}setSignatureInception(t){this.set("signature inception",t)}setKeyTag(t){this.set("key tag",t)}setSignersName(t){this.set("signers name",t.toLowerCase())}setSignature(t){this.set("signature",t)}getDescription(){return"Signature"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"SIG","type covered":1,algorithm:5,labels:3,"original ttl":3600,"signature expiration":1045053120,"signature inception":1042461120,"key tag":12345,"signers name":"example.com.",signature:"ABCDEF..."}}fromBind({bindline:t}){const e=t.trim().split(/\s+/),s=e[4],i=/^\d+$/.test(s)?parseInt(s,10):q[s.toUpperCase()]??parseInt(s,10);return new lt({owner:e[0],ttl:parseInt(e[1],10),class:e[2],type:"SIG","type covered":i,algorithm:parseInt(e[5],10),labels:parseInt(e[6],10),"original ttl":parseInt(e[7],10),"signature expiration":parseInt(e[8],10),"signature inception":parseInt(e[9],10),"key tag":parseInt(e[10],10),"signers name":e[11],signature:e.slice(12).filter(n=>n!=="("&&n!==")").join(" ").trim()})}toTinydns(){const t=new RegExp(/[\r\n\t:]/,"g");return this.getTinydnsGeneric(A(this.get("type covered"))+u(this.get("algorithm"))+u(this.get("labels"))+P(this.get("original ttl"))+P(this.get("signature expiration"))+P(this.get("signature inception"))+A(this.get("key tag"))+N(this.get("signers name"))+I(t,this.get("signature")))}getWireRdata(){const t=W(this.get("signers name")),e=new TextEncoder().encode(this.get("signature")),s=18+t.length+e.length,i=new Uint8Array(s),n=new DataView(i.buffer,i.byteOffset);let a=0;return n.setUint16(a,this.get("type covered")),a+=2,i[a++]=this.get("algorithm"),i[a++]=this.get("labels"),n.setUint32(a,this.get("original ttl")),a+=4,n.setUint32(a,this.get("signature expiration")),a+=4,n.setUint32(a,this.get("signature inception")),a+=4,n.setUint16(a,this.get("key tag")),a+=2,i.set(t,a),a+=t.length,i.set(e,a),i}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);parseInt(s,10)!==this.getTypeId()&&this.throwHelp("SIG fromTinydns, invalid n");const r=H(i),c=new DataView(r.buffer,r.byteOffset,r.byteLength),h=c.getUint16(0),p=r[2],d=r[3],g=c.getUint32(4),y=c.getUint32(8),m=c.getUint32(12),b=c.getUint16(16);let w=18;const T=[];for(;w<r.length;){const S=r[w++];if(S===0)break;T.push(new TextDecoder().decode(r.subarray(w,w+S))),w+=S}const D=`${T.join(".")}.`,C=new TextDecoder().decode(r.subarray(w));return new lt({owner:e,ttl:n,type:"SIG","type covered":h,algorithm:p,labels:d,"original ttl":g,"signature expiration":y,"signature inception":m,"key tag":b,"signers name":D,signature:C,timestamp:a,location:o})}toBind(t){return`${this.getFQDN("owner",t)} ${this.get("ttl")} ${this.get("class")} SIG${this.getRdataFields().slice(0,4).map(e=>" "+this.get(e)).join("")} ${this.getRdataFields().slice(4,8).map(e=>this.get(e)).join(" ")} ( ${this.get("signature")} )`}}class ht extends f{static typeName="SMIMEA";static typeId=53;static RFCs=[8162];static rdataFields=[["certificate usage","u8"],["selector","u8"],["matching type","u8"],["certificate association data","hex"]];static tags=["security"];constructor(t){super(t)}setCertificateUsage(t){this.getCertificateUsageOptions().has(t)||this.throwHelp("SMIMEA: certificate usage invalid"),this.set("certificate usage",t)}getCertificateUsageOptions(){return new Map([[0,"CA certificate"],[1,"an end entity certificate"],[2,"the trust anchor"],[3,"domain-issued certificate"]])}setSelector(t){this.getSelectorOptions().has(t)||this.throwHelp("SMIMEA: selector invalid"),this.set("selector",t)}getSelectorOptions(){return new Map([[0,"Full certificate"],[1,"SubjectPublicKeyInfo"]])}setMatchingType(t){this.getMatchingTypeOptions().has(t)||this.throwHelp("SMIMEA: matching type"),this.set("matching type",t)}getMatchingTypeOptions(){return new Map([[0,"Exact match"],[1,"SHA-256 hash"],[2,"SHA-512 hash"]])}setCertificateAssociationData(t){this.set("certificate association data",t)}getDescription(){return"S/MIME cert association"}getCanonical(){return{owner:"_443._tcp.www.example.com.",ttl:3600,class:"IN",type:"SMIMEA","certificate usage":0,selector:0,"matching type":1,"certificate association data":"ABCDEF..."}}fromBind({bindline:t}){const[e,s,i,n,a,o,r]=t.split(/\s+/);return new ht({owner:e,ttl:parseInt(s,10),class:i,type:n,"certificate usage":parseInt(a,10),selector:parseInt(o,10),"matching type":parseInt(r,10),"certificate association data":t.split(/\s+/).slice(7).join(" ").trim()})}fromTinydns({tinyline:t}){const{owner:e,rdata:s,ttl:i,timestamp:n,location:a}=this.parseTinydnsLine(t),o=H(s);return new ht({owner:e,ttl:i,type:"SMIMEA","certificate usage":o[0],selector:o[1],"matching type":o[2],"certificate association data":R(o.subarray(3)),timestamp:n,location:a})}toTinydns(){return this.getTinydnsGeneric(u(this.get("certificate usage"))+u(this.get("selector"))+u(this.get("matching type"))+O(this.get("certificate association data").replace(/[\s()]/g,"")))}getWireRdata(){const t=F(this.get("certificate association data").replace(/[\s()]/g,"")),e=new Uint8Array(3+t.length);return e[0]=this.get("certificate usage"),e[1]=this.get("selector"),e[2]=this.get("matching type"),e.set(t,3),e}}class St extends f{static typeName="SOA";static typeId=6;static RFCs=[1035,2308];static tinydnsType="Z";static rdataFields=[["mname","fqdn"],["rname","fqdn"],["serial","u32"],["refresh","u32"],["retry","u32"],["expire","u32"],["minimum","u32"]];static tags=["common"];constructor(t){super(t)}setMinimum(t){this.is32bitInt("SOA","minimum",t),this.set("minimum",t)}setMname(t){this.isValidHostname("SOA","MNAME",t),this.isFullyQualified("SOA","MNAME",t),this.set("mname",t.toLowerCase())}setRname(t){this.isValidHostname("SOA","RNAME",t),this.isFullyQualified("SOA","RNAME",t),/@/.test(t)&&this.throwHelp("SOA rname replaces @ with a . (dot)"),this.set("rname",t.toLowerCase())}setSerial(t){this.is32bitInt("SOA","serial",t),this.set("serial",t)}setRefresh(t){this.is32bitInt("SOA","refresh",t),this.set("refresh",t)}setRetry(t){this.is32bitInt("SOA","retry",t),this.set("retry",t)}setExpire(t){this.is32bitInt("SOA","expire",t),this.set("expire",t)}getDescription(){return"Start Of Authority"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"SOA",mname:"ns1.example.com.",rname:"admin.example.com.",serial:2023051001,refresh:7200,retry:3600,expire:1209600,minimum:3600}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o,r,c,h,p,d]=t.slice(1).split(":");return new St({owner:this.fullyQualify(e),ttl:parseInt(h,10),type:"SOA",mname:this.fullyQualify(s),rname:this.fullyQualify(i),serial:parseInt(n??this.default?.serial,10),refresh:parseInt(a,10)||16384,retry:parseInt(o,10)||2048,expire:parseInt(r,10)||1048576,minimum:parseInt(c,10)||2560,timestamp:parseInt(p)||"",location:d?.trim()??""})}toMaraDNS(){return`${this.get("owner")} SOA ${this.getFields("rdata").map(t=>this.getQuoted(t)).join(" ")} ~
20
+ `}getWireRdata(){const t=this.wirePackDomain(this.get("mname")),e=this.wirePackDomain(this.get("rname")),s=new Uint8Array(t.length+e.length+20);let i=0;s.set(t,i),i+=t.length,s.set(e,i),i+=e.length;const n=new DataView(s.buffer,i);return n.setUint32(0,this.get("serial")),n.setUint32(4,this.get("refresh")),n.setUint32(8,this.get("retry")),n.setUint32(12,this.get("expire")),n.setUint32(16,this.get("minimum")),s}toTinydns(){return`Z${this.getTinyFQDN("owner")}:${this.getTinyFQDN("mname")}:${this.getTinyFQDN("rname")}:${this.getEmpty("serial")}:${this.getEmpty("refresh")}:${this.getEmpty("retry")}:${this.getEmpty("expire")}:${this.getEmpty("minimum")}:${this.getTinydnsPostamble()}
21
+ `}}class $t extends f{static typeName="TXT";static typeId=16;static RFCs=[1035,4408,7208,6376];static tinydnsType="'";static rdataFields=[["data","charstrs"]];static tags=["common"];constructor(t){super(t)}setData(t){this.set("data",t)}getDescription(){return"Text"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"TXT",data:"v=spf1 mx -all"}}fromTinydns({tinyline:t}){const e=t;let s,i,n,a,o,r;return e[0]==="'"?([s,n,a,o,r]=e.slice(1).split(":"),i=x(n)):[s,i,a,o,r]=this.fromTinydnsGeneric(e),new this.constructor({owner:this.fullyQualify(s),ttl:parseInt(a,10),type:"TXT",data:i,timestamp:o,location:r?.trim()||""})}fromTinydnsGeneric(t){let[e,s,i,n,a,o]=t.slice(1).split(":");s!=16&&this.throwHelp("TXT fromTinydns, invalid n"),i=x(i);let r="",c=i[0].charCodeAt(0),h=1;for(;h<i.length;)r+=i.slice(h,+(c+h)),h=c+h,c=i.charCodeAt(h+1);return[e,r,n,a,o]}toBind(t){return`${this.getPrefix(t)} "${Yt(this.get("data"))}"
22
+ `}toMaraDNS(){const t=Yt(this.get("data")).replace(/"/g,"'");return`${this.get("owner")} +${this.get("ttl")} ${this.get("type")} '${t}' ~
23
+ `}getWireRdata(){let t=this.get("data");return Array.isArray(t)&&(t=t.join("")),Se(t)}toTinydns(){let t=this.get("data");Array.isArray(t)&&(t=t.join(""));const e=I(new RegExp(/[\r\n\t:\\/]/,"g"),t);return`'${this.getTinyFQDN("owner")}:${e}:${this.getTinydnsPostamble()}
24
+ `}}function Yt(l){const t=new TextEncoder;return Array.isArray(l)?l.some(s=>t.encode(s).length>255)?Xt(l.join(""),255).join('" "'):l.join('" "'):t.encode(l).length<=255?l:Xt(l,255).join('" "')}function Xt(l,t){const e=new TextEncoder().encode(l),s=new TextDecoder,i=[];let n=0;for(;n<e.length;){let a=Math.min(n+t,e.length);for(;a<e.length&&(e[a]&192)===128;)a--;i.push(s.decode(e.subarray(n,a))),n=a}return i}function Se(l){const t=new TextEncoder().encode(l);if(t.length===0)return new Uint8Array([0]);const e=[];for(let n=0;n<t.length;n+=255)e.push(t.subarray(n,n+255));const s=new Uint8Array(t.length+e.length);let i=0;for(const n of e)s[i++]=n.length,s.set(n,i),i+=n.length;return s}class xt extends $t{static typeName="SPF";static typeId=99;static RFCs=[4408,7208];static rdataFields=[["data","charstrs"]];static tags=["obsolete"];constructor(t){super(t)}setData(t){this.set("data",t)}getDescription(){return"Sender Policy Framework"}getCanonical(){return{owner:"example.com.",ttl:3600,class:"IN",type:"SPF",data:"v=spf1 mx -all"}}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");return s!=99&&this.throwHelp("SPF fromTinydns, invalid n"),new xt({type:"SPF",owner:this.fullyQualify(e),data:x(i),ttl:parseInt(n,10),timestamp:a,location:o?.trim()??""})}getWireRdata(){return super.getWireRdata()}toTinydns(){const t=I(new RegExp(/[\r\n\t:\\/]/,"g"),this.get("data"));return this.getTinydnsGeneric(t)}}class Ct extends f{static typeName="SRV";static typeId=33;static RFCs=[2782];static rdataFields=[["priority","u16"],["weight","u16"],["port","u16"],["target","fqdn"]];static tags=["common"];constructor(t){super(t)}getDescription(){return"Service"}getCanonical(){return{owner:"_imaps._tcp.example.com.",ttl:3600,class:"IN",type:"SRV",priority:10,weight:10,port:993,target:"mail.example.com."}}fromTinydns({tinyline:t}){const e=t;let s,i,n,a,o,r,c,h,p,d;return e[0]==="S"?[s,i,n,a,o,r,c,h]=e.slice(1).split(":"):([s,p,d,r,c,h]=e.slice(1).split(":"),p!=33&&this.throwHelp("SRV fromTinydns: invalid n"),a=B(d.slice(0,8)),o=B(d.slice(8,16)),n=B(d.slice(16,24)),i=U(d.slice(24))[0]),new Ct({owner:this.fullyQualify(s),ttl:parseInt(r,10),type:"SRV",priority:parseInt(a,10),weight:parseInt(o,10),port:parseInt(n,10),target:this.fullyQualify(i),timestamp:c,location:h?.trim()??""})}getWireRdata(){const t=this.wirePackDomain(this.get("target")),e=new Uint8Array(6+t.length),s=new DataView(e.buffer);return s.setUint16(0,this.get("priority")),s.setUint16(2,this.get("weight")),s.setUint16(4,this.get("port")),e.set(t,6),e}toTinydns(){let t="";for(const e of["priority","weight","port"])t+=A(this.get(e));return t+=N(this.get("target")),this.getTinydnsGeneric(t)}}class Nt extends f{static typeName="SSHFP";static typeId=44;static RFCs=[4255,7479,8709];static rdataFields=[["algorithm","u8"],["fptype","u8"],["fingerprint","hex"]];static tags=["security"];constructor(t){super(t)}getAlgorithmOptions(){return new Map([[0,"reserved"],[1,"RSA"],[2,"DSA"],[3,"ECDSA"],[4,"Ed25519"],[6,"Ed448"]])}getFptypeOptions(){return new Map([[0,"reserved"],[1,"SHA-1"],[2,"SHA-256"]])}getDescription(){return"Secure Shell Key Fingerprints"}getCanonical(){return{owner:"mail.example.com.",ttl:3600,class:"IN",type:"SSHFP",algorithm:2,fptype:1,fingerprint:"123456789abcdef6789abcdf6789abdf6789abcd"}}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);return s!=this.getTypeId()&&this.throwHelp("SSHFP fromTinydns, invalid n"),new Nt({owner:e,ttl:n,type:"SSHFP",algorithm:E(i.slice(0,4)),fptype:E(i.slice(4,8)),fingerprint:Pt(i.slice(8)),timestamp:a,location:o})}toTinydns(){return this.getTinydnsGeneric(u(this.get("algorithm"))+u(this.get("fptype"))+O(this.get("fingerprint")))}getWireRdata(){const t=new Uint8Array(2+F(this.get("fingerprint")).length);return t[0]=this.get("algorithm"),t[1]=this.get("fptype"),t.set(F(this.get("fingerprint")),2),t}}class pt extends f{static typeName="SVCB";static typeId=64;static RFCs=[9460];static rdataFields=[["priority","u16"],["target name","fqdn"],["params","svcparams"]];constructor(t){super(t)}setPriority(t){this.is16bitInt("SVCB","priority",t),this.set("priority",t)}setTargetName(t){this.set("target name",t.toLowerCase())}setParams(t){this.set("params",t)}getDescription(){return"Service Binding"}getCanonical(){return{owner:"_8443._foo.api.example.com.",ttl:3600,class:"IN",type:"SVCB",priority:1,"target name":"svc4.example.net.",params:'alpn="h2,h3"'}}fromBind({bindline:t}){const[e,s,i,n,a,o]=t.split(/\s+/);return new pt({owner:e,ttl:parseInt(s,10),class:i,type:n,priority:parseInt(a,10),"target name":o,params:t.split(/\s+/).slice(6).join(" ").trim()})}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("SVCB fromTinydns, invalid n");const{priority:r,targetName:c,params:h}=Mt(i,"SVCB");return new pt({owner:e,ttl:n,type:"SVCB",priority:r,"target name":c,params:h,timestamp:a,location:o})}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g");return this.getTinydnsGeneric(A(this.get("priority"))+N(this.get("target name"))+I(t,this.get("params")))}getWireRdata(){const t=this.wirePackDomain(this.get("target name")),e=Wt(this.get("params")),s=new Uint8Array(2+t.length+e.length);return new DataView(s.buffer).setUint16(0,this.get("priority")),s.set(t,2),s.set(e,2+t.length),s}}class dt extends f{static typeName="TLSA";static typeId=52;static RFCs=[6698,7671];static rdataFields=[["certificate usage","u8"],["selector","u8"],["matching type","u8"],["certificate association data","hex"]];static tags=["security"];constructor(t){super(t)}setCertificateUsage(t){this.getCertificateUsageOptions().has(t)||this.throwHelp("TLSA: certificate usage invalid"),this.set("certificate usage",t)}getCertificateUsageOptions(){return new Map([[0,"CA certificate"],[1,"an end entity certificate"],[2,"the trust anchor"],[3,"domain-issued certificate"]])}setSelector(t){this.getSelectorOptions().has(t)||this.throwHelp("TLSA: selector invalid"),this.set("selector",t)}getSelectorOptions(){return new Map([[0,"Full certificate"],[1,"SubjectPublicKeyInfo"]])}setMatchingType(t){this.getMatchingTypeOptions().has(t)||this.throwHelp("TLSA: matching type"),this.set("matching type",t)}getMatchingTypeOptions(){return new Map([[0,"Exact match"],[1,"SHA-256 hash"],[2,"SHA-512 hash"]])}setCertificateAssociationData(t){this.set("certificate association data",t)}getDescription(){return"TLSA certificate association"}getCanonical(){return{owner:"_443._tcp.www.example.com.",ttl:3600,class:"IN",type:"TLSA","certificate usage":3,selector:1,"matching type":1,"certificate association data":"ABCDEF..."}}fromBind({bindline:t}){const e=/^(?<owner>\S+)\s+(?<ttl>\d{1,10})\s+(?<cls>IN)\s+(?<type>TLSA)\s+(?<usage>\d+)\s+(?<selector>\d+)\s+(?<matchtype>\d+)\s+(?<cad>\S.*)$/i,s=t.trim().match(e);s||this.throwHelp(`unable to parse TLSA: ${t}`);const{owner:i,ttl:n,cls:a,type:o,usage:r,selector:c,matchtype:h,cad:p}=s.groups;return new dt({owner:this.fullyQualify(i),ttl:parseInt(n,10),class:a.toUpperCase(),type:o.toUpperCase(),"certificate usage":parseInt(r,10),selector:parseInt(c,10),"matching type":parseInt(h,10),"certificate association data":p.trim()})}fromTinydns({tinyline:t}){const{owner:e,typeId:s,rdata:i,ttl:n,timestamp:a,location:o}=this.parseTinydnsLine(t);s!=this.getTypeId()&&this.throwHelp("TLSA fromTinydns, invalid n");const r=H(i);return new dt({owner:e,ttl:n,type:"TLSA","certificate usage":r[0],selector:r[1],"matching type":r[2],"certificate association data":R(r.subarray(3)),timestamp:a,location:o})}toTinydns(){return this.getTinydnsGeneric(u(this.get("certificate usage"))+u(this.get("selector"))+u(this.get("matching type"))+O(this.get("certificate association data").replace(/[\s()]/g,"")))}getWireRdata(){const t=F(this.get("certificate association data").replace(/[\s()]/g,"")),e=new Uint8Array(3+t.length);return e[0]=this.get("certificate usage"),e[1]=this.get("selector"),e[2]=this.get("matching type"),e.set(t,3),e}}class J extends f{static typeName="TSIG";static typeId=250;static RFCs=[2845,8945];static rdataFields=["algorithm name","time signed","fudge","mac","original id","error","other"];constructor(t){super(t)}getDescription(){return"Transaction Signature"}getCanonical(){return{owner:"test.example.",ttl:0,class:"ANY",type:"TSIG","algorithm name":"hmac-sha256.","time signed":162065e4,fudge:300,mac:"ABCDEF...","original id":12345,error:0,other:""}}setClass(t){t!=="ANY"&&this.throwHelp("TSIG: Class is required to be ANY"),this.set("class",t)}setTtl(t){t!==0&&this.throwHelp("TSIG: TTL is required to be 0"),this.set("ttl",t)}setAlgorithmName(t){t||this.throwHelp("TSIG: 'algorithm name' is required"),this.set("algorithm name",t)}setTimeSigned(t){t===void 0&&this.throwHelp("TSIG: 'time signed' is required"),this.set("time signed",t)}setFudge(t){this.is16bitInt("TSIG","fudge",t),this.set("fudge",t)}setMac(t){this.set("mac",t??"")}setOriginalId(t){this.is16bitInt("TSIG","original id",t),this.set("original id",t)}setError(t){this.is16bitInt("TSIG","error",t),this.set("error",t)}setOther(t){this.set("other",t??"")}fromBind({bindline:t}){const e=t.trimEnd().split(" "),[s,i,n,a,o,r,c,,h,p,d]=e;return new J({owner:s,ttl:parseInt(i,10),class:n,type:a.toUpperCase(),"algorithm name":o,"time signed":parseInt(r,10),fudge:parseInt(c,10),mac:h||"","original id":parseInt(p,10),error:parseInt(d,10),other:""})}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":"),r=U(i),c=r[2],h=Uint8Array.from(x(i),C=>C.charCodeAt(0)),p=new DataView(h.buffer,h.byteOffset,h.byteLength);let d=c;const g=p.getUint32(d);d+=4;const y=p.getUint16(d);d+=2;const m=p.getUint16(d);d+=2;const b=m>0?R(h.subarray(d,d+m)):"";d+=m;const w=p.getUint16(d);d+=2;const T=p.getUint16(d);d+=2;const D=d<h.length?new TextDecoder().decode(h.subarray(d)):"";return new J({owner:this.fullyQualify(e),ttl:parseInt(n,10),class:"ANY",type:"TSIG","algorithm name":r[0],"time signed":g,fudge:y,mac:b,"original id":w,error:T,other:D,timestamp:a,location:o?.trim()??""})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const{fqdn:n,end:a}=this.wireUnpackDomain(i,0),o=new DataView(i.buffer,i.byteOffset);let r=a;const c=o.getUint32(r);r+=4;const h=o.getUint16(r);r+=2;const p=o.getUint16(r);r+=2;const d=p>0?R(i.subarray(r,r+p)):"";r+=p;const g=o.getUint16(r);r+=2;const y=o.getUint16(r);r+=2;const m=r<i.length?new TextDecoder().decode(i.subarray(r)):"";return new J({owner:t,ttl:0,class:"ANY",type:"TSIG","algorithm name":n,"time signed":c,fudge:h,mac:d,"original id":g,error:y,other:m})}toBind(t){const e=this.get("mac")??"",s=e.length>0?e.length:"",i=this.get("other")??"",n=i.length>0?i.length:0;return[this.getFQDN("owner",t),this.get("ttl"),this.get("class"),this.get("type"),this.get("algorithm name"),this.get("time signed"),this.get("fudge"),s,e,this.get("original id"),this.get("error"),n].join(" ")+`
25
+ `}getWireRdata(){const t=W(this.get("algorithm name")||""),e=this.get("mac")??"",s=e.length>0?F(e):new Uint8Array,i=this.get("other")??"",n=i.length>0?new TextEncoder().encode(i):new Uint8Array,a=new Uint8Array(t.length+4+2+2+s.length+2+2+n.length),o=new DataView(a.buffer,a.byteOffset);let r=0;return a.set(t,r),r+=t.length,o.setUint32(r,this.get("time signed")??0),r+=4,o.setUint16(r,this.get("fudge")??0),r+=2,o.setUint16(r,s.length),r+=2,s.length>0&&(a.set(s,r),r+=s.length),o.setUint16(r,this.get("original id")??0),r+=2,o.setUint16(r,this.get("error")??0),r+=2,n.length>0&&a.set(n,r),a}toTinydns(){const t=this.get("algorithm name")||"",e=this.get("mac")??"",s=e.length>0?e.length/2:0;return this.getTinydnsGeneric(N(t)+P(this.get("time signed")??0)+A(this.get("fudge"))+A(s)+(s>0?O(e):"")+A(this.get("original id")??0)+A(this.get("error")??0)+(this.get("other").length>0?I(new RegExp(/[\r\n\t:\\/]/,"g"),this.get("other")):""))}}class Et extends f{static typeName="URI";static typeId=256;static RFCs=[7553];static rdataFields=[["priority","u16"],["weight","u16"],["target","qstr"]];constructor(t){super(t)}setPriority(t){this.is16bitInt("URI","priority",t),this.set("priority",t)}setWeight(t){this.is16bitInt("URI","weight",t),this.set("weight",t)}setTarget(t){t||this.throwHelp("URI: target is required"),this.set("target",t)}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":");return s!=256&&this.throwHelp("URI fromTinydns, invalid n"),new Et({type:"URI",owner:this.fullyQualify(e),priority:B(i.slice(0,8)),weight:B(i.slice(8,16)),target:x(i.slice(16)),ttl:parseInt(n,10),timestamp:a,location:o?.trim()??""})}getDescription(){return"URI"}getCanonical(){return{owner:"www.example.com.",ttl:3600,class:"IN",type:"URI",priority:10,weight:10,target:"http://www.example.com/"}}getWireRdata(){const t=new TextEncoder().encode(this.get("target")),e=new Uint8Array(4+t.length),s=new DataView(e.buffer);return s.setUint16(0,this.get("priority")),s.setUint16(2,this.get("weight")),e.set(t,4),e}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g");let e="";for(const s of["priority","weight"])e+=A(this.get(s));return e+=I(t,this.get("target")),this.getTinydnsGeneric(e)}}const zt={echo:7,discard:9,systat:11,daytime:13,netstat:15,ftp_data:20,ftp:21,ssh:22,telnet:23,smtp:25,time:37,rlp:39,nameserver:42,nicname:43,domain:53,mtp:57,bootps:67,bootpc:68,tftp:69,gopher:70,rje:77,finger:79,http:80,link:87,supdup:95,hostnames:101,iso_tsap:102,csnet_ns:105,pop_2:109,pop3:110,sunrpc:111,auth:113,sftp:115,uucp_path:117,nntp:119,ntp:123,netbios_ns:137,netbios_dgm:138,netbios_ssn:139,imap:143,sql_net:150,snmp:161,snmp_trap:162,cmip_man:163,cmip_agent:164,xdmcp:177,nextstep:178,bgp:179,prospero:191,irc:194,smux:199,at_rtmp:201,at_nbp:202,at_echo:204,at_zis:206,qmtp:209,z3950:210,ipx:213,imap3:220,ulistproc:372,https:443,snpp:444,microsoft_ds:445,kpasswd:464,urd:465,saft:487,isakmp:500,exec:512,biff:512,login:513,who:513,cmd:514,syslog:514,printer:515,talk:517,ntalk:518,route:520,timed:525,tempo:526,courier:530,netnews:532,netwall:533,uucp:540,remotefs:556,nntps:563,ldap:389};class Z extends f{static typeName="WKS";static typeId=11;static RFCs=[883,1035];static rdataFields=["address","protocol","bit map"];static tags=["obsolete"];constructor(t){super(t)}setAddress(t){t||this.throwHelp("WKS: address is required"),this.isIPv4(t)||this.throwHelp("WKS address must be IPv4"),this.set("address",t)}setProtocol(t){t||this.throwHelp("WKS: protocol is required");const e=typeof t=="string"?t.toUpperCase():t;["TCP","UDP",6,17].includes(e)||this.throwHelp("WKS protocol must be TCP or UDP"),this.set("protocol",e)}setBitMap(t){this.set("bit map",t??"")}getDescription(){return"Well Known Service"}getCanonical(){return{owner:"host.example.com.",ttl:3600,class:"IN",type:"WKS",address:"192.0.2.1",protocol:"TCP","bit map":"ftp smtp"}}fromBind({bindline:t}){const e=t.split(/\s+/),[s,i,n,a,o,r]=e;return new Z({owner:s,ttl:parseInt(i,10),class:n,type:a,address:o,protocol:r,"bit map":e.slice(6).join(" ").trim()})}fromTinydns({tinyline:t}){const[e,s,i,n,a,o]=t.slice(1).split(":"),r=Uint8Array.from(x(i),y=>y.charCodeAt(0)),c=[r[0],r[1],r[2],r[3]].join("."),h=r[4],d={6:"TCP",17:"UDP"}[h]??h,g=new TextDecoder().decode(r.subarray(5));return new Z({owner:this.fullyQualify(e),ttl:parseInt(n,10),type:"WKS",address:c,protocol:d,"bit map":g,timestamp:a,location:o?.trim()??""})}fromWire({owner:t,cls:e,ttl:s,rdata:i}){const n=[...i.subarray(0,4)].join("."),a=i[4],r={6:"TCP",17:"UDP"}[a]??String(a),c=Object.fromEntries(Object.entries(zt).map(([d,g])=>[g,d])),h=i.subarray(5),p=[];for(let d=0;d<h.length;d++)for(let g=0;g<8;g++)if(h[d]&128>>g){const y=d*8+g;p.push(c[y]??String(y))}return new Z({owner:t,ttl:s,class:e,type:"WKS",address:n,protocol:r,"bit map":p.join(" ")})}toTinydns(){const t=new RegExp(/[\r\n\t:\\/]/,"g"),s={TCP:6,UDP:17,6:6,17:17}[this.get("protocol")];return this.getTinydnsGeneric(qt(this.get("address"))+u(s)+I(t,this.get("bit map")))}getWireRdata(){const t={TCP:6,UDP:17,6:6,17:17},e=this.get("address").split(".").map(Number),s=t[this.get("protocol")],i=this.get("bit map").trim().split(/\s+/).map(c=>/^\d+$/.test(c)?parseInt(c,10):zt[c.toLowerCase()]).filter(c=>c!==void 0);if(i.length===0)return new Uint8Array([...e,s]);const n=Math.max(...i),a=Math.floor(n/8)+1,o=new Uint8Array(a);for(const c of i)o[Math.floor(c/8)]|=128>>c%8;const r=new Uint8Array(5+a);return r.set(e),r[4]=s,r.set(o,5),r}}const Ht={},xe=[Gt,yt,j,ft,$,Vt,mt,wt,et,st,jt,K,it,Q,nt,bt,Y,Tt,rt,At,X,z,at,v,ot,Qt,It,ct,lt,ht,Nt,St,xt,Ct,pt,dt,J,$t,Et,Z];for(const l of xe){const t=l.getTypeId();Ht[t]=l.typeName,Ht[l.typeName]=t}export{Gt as A,yt as AAAA,j as APL,ft as CAA,$ as CERT,Vt as CNAME,mt as DHCID,wt as DNAME,et as DNSKEY,st as DS,jt as HINFO,K as HIP,it as HTTPS,Q as IPSECKEY,nt as KEY,bt as KX,Y as LOC,Tt as MX,rt as NAPTR,At as NS,X as NSEC,z as NSEC3,at as NSEC3PARAM,v as NXT,ot as OPENPGPKEY,Qt as PTR,It as RP,ct as RRSIG,lt as SIG,ht as SMIMEA,St as SOA,xt as SPF,Ct as SRV,Nt as SSHFP,pt as SVCB,dt as TLSA,J as TSIG,$t as TXT,Et as URI,Z as WKS,f as default,Ht as typeMap};
26
+ //# sourceMappingURL=dns-rr.min.js.map