typepki-strconv 0.4.0 → 0.6.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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  typepki-strconv: TypePKI string converters and utilities sub module for TypePKI library
2
2
  ====================================================================================
3
3
 
4
- [TOP](https://kjur.github.io/typepki-strconv/) | [github](https://github.com/kjur/typepki-strconv) | [npm](https://www.npmjs.com/package/typepki-strconv) | [TypePKI](https://kjur.github.com/typepki/)
4
+ [TOP](https://kjur.github.io/typepki-strconv/) | [github](https://github.com/kjur/typepki-strconv) | [npm](https://www.npmjs.com/package/typepki-strconv) | [TypePKI](https://kjur.github.io/typepki/)
5
5
 
6
6
  The 'TypePKI' library is an opensource free TypeScript PKI library which is the successor of the long lived [jsrsasign](https://kjur.github.io/jsrsasign) library.
7
7
 
@@ -1,11 +1,21 @@
1
1
  export declare function b64tohex(b64: string): string;
2
2
  export declare function hextob64(hex: string): string;
3
+ /**
4
+ * convert hexadecimal string to UTF-8 string
5
+ * @param h - hexadecimal string
6
+ * @return UTF-8 string
7
+ * @throws Error if hexadecimal can't decoded as UTF-8 string
8
+ * @example
9
+ * hextoutf8("616263") -> "abc"
10
+ * hextoutf8("616161e38182e38184e38186") -> "aaaあいう"
11
+ * hextoutf8("6161ff") -> throws malformed error
12
+ */
13
+ export declare function hextoutf8(h: string): string;
14
+ export declare function utf8tohex(u8: string): string;
3
15
  export declare function b64toutf8(b64: string): string;
4
16
  export declare function utf8tob64(u8: string): string;
5
17
  export declare function b64utoutf8(b64u: string): string;
6
18
  export declare function utf8tob64u(u8: string): string;
7
- export declare function hextoutf8(hex: string): string;
8
- export declare function utf8tohex(u8: string): string;
9
19
  export declare function b64utohex(b64u: string): string;
10
20
  export declare function hextob64u(hex: string): string;
11
21
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"conv.d.mts","sourceRoot":"","sources":["../../src/conv.mts"],"names":[],"mappings":"AACA,wBAAgB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CAAC,GACzB,MAAM,CAYR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,GAAG,CAejE"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * zero padding for hexadecimal string
3
+ * @param s - odd or even length hexadecimal string
4
+ * @return even length zero padded hexadecimal string
5
+ * @example
6
+ * hexpad("1") -> "01"
7
+ * hexpad("ab3c") -> "ab3c"
8
+ */
9
+ export declare function hexpad(s: string): string;
10
+ //# sourceMappingURL=hexutil.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hexutil.d.mts","sourceRoot":"","sources":["../../src/hexutil.mts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAExC"}
@@ -21,4 +21,6 @@ import { hextoip, hextoipv6, ipnetmask, ipprefixlen, iptohex, ipv6tohex } from "
21
21
  export { ipv6tohex, hextoipv6, hextoip, iptohex, ipprefixlen, ipnetmask };
22
22
  import { ucs2hextoutf8 } from "./conv_ucs2.mts";
23
23
  export { ucs2hextoutf8 };
24
+ import { hexpad } from "./hexutil.mts";
25
+ export { hexpad };
24
26
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,EAAE,MAA+D,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAA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SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
- function a(r){return Buffer.from(r,"base64").toString("hex")}function x(r){return Buffer.from(r,"hex").toString("base64")}function j(r){return Buffer.from(r,"base64").toString("utf8")}function N(r){return Buffer.from(r,"utf8").toString("base64")}function k(r){return Buffer.from(p(r),"base64").toString("utf8")}function R(r){return b(Buffer.from(r,"utf8").toString("base64"))}function c(r){return Buffer.from(r,"hex").toString("utf8")}function m(r){return Buffer.from(r,"utf8").toString("hex")}function Z(r){return a(p(r))}function F(r){return b(x(r))}function L(r){let t="";for(let e=0;e<r.length;e+=2){let n=parseInt(r.substr(e,2),16);t+=String.fromCharCode(n)}return t}function G(r){let t="";for(let e=0;e<r.length;e++)t+=`0${r.charCodeAt(e).toString(16)}`.slice(-2);return t}function V(r){return Buffer.from(r).toString("base64")}function b(r){let t=r;return t=t.replace(/\=/g,""),t=t.replace(/\+/g,"-"),t=t.replace(/\//g,"_"),t}function p(r){let t=r;return t.length%4===2?t=`${t}==`:t.length%4===3&&(t=`${t}=`),t=t.replace(/-/g,"+"),t=t.replace(/_/g,"/"),t}var _=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return S(t)}catch{return null}};function O(r){if(typeof r!="string"||r.length%2!==0||!r.match(/^[0-9a-f]+$/))return null;try{let t=parseInt(r.substr(0,2),16);if(t<0||7<t)return null;let e=r.substr(2),n="";for(let i=0;i<e.length;i+=2){let o=e.substr(i,2),s=parseInt(o,16).toString(2);s=`0000000${s}`.slice(-8),n+=s}return n.substr(0,n.length-t)}catch{return null}}function S(r){if(typeof r!="number"||r<0)return null;let t=Number(r).toString(2),e=8-t.length%8;e===8&&(e=0),t=t+C("",e,"0");let n=parseInt(t,2).toString(16);return n.length%2===1&&(n=`0${n}`),`0${e}`+n}var C=(r,t,e)=>{let n=e===void 0?"0":e;return r.length>=t?r:new Array(t-r.length+1).join(n)+r};function P(r,t){let e=0;for(let o=0;o<r.length;o++)e|=1<<t[r[o]];let n=e.toString(2),i="";for(let o=n.length-1;o>=0;o--)i+=n[o];return i}function Y(r,t,e){let n=r,i=t.split(".");for(let o=0;o<i.length&&n;o++){let s=i[o];if(typeof n=="object"&&"length"in n&&s.match(/^[0-9]+$/))n=n[parseInt(s)];else if(typeof n=="object"&&s in n)n=n[s];else return e}return n||n===!1?n:e}function q(r){return!(r.length%2===1||r.match(/^[0-9a-f]+$/)==null)}function U(r){let t=r.replace(/\s+/g,"");return!!(t.match(/^[0-9A-Za-z+\/]+={0,3}$/)&&t.length%4===0)}function J(r){if(r.match(/[+/=]/))return!1;let t=p(r);return U(t)}function $(r){return E(T(r))}function E(r){let t="";for(let e=0;e<r.length;e++){let n=r[e].toString(16);n.length===1&&(n=`0${n}`),t=t+n}return t}function K(r){let t=[];for(let e=0;e<r.length;e+=2)t.push(parseInt(r.slice(e,e+2),16));return t}function T(r){let t=new Array;for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function Q(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}function W(r){return c(H(r))}function X(r){return tt(m(r))}function H(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++){let i=parseInt(t[n],16);161<=i&&i<=191?(e.push("c2"),e.push(t[n])):192<=i&&i<=255?(e.push("c3"),e.push((i-64).toString(16))):e.push(t[n])}return e.join("")}function tt(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++)if(t[n]==="c2")n++,e.push(t[n]);else if(t[n]==="c3"){n++;let i=parseInt(t[n],16)+64;e.push(i.toString(16))}else e.push(t[n]);return e.join("")}function rt(r,t,e=`\r
2
- `){return`-----BEGIN ${t}-----${e}${d(x(r),64)}${e}-----END ${t}-----${e}`}function et(r,t){return a(v(r,t))}function v(r,t){let e=r;if(e.indexOf("-----BEGIN ")===-1)throw new Error("can't find PEM header");return t!==void 0?(e=e.replace(new RegExp(`^[^-]*-----BEGIN ${t}-----`),""),e=e.replace(new RegExp(`-----END ${t}-----[^-]*$`),"")):(e=e.replace(/^[^-]*-----BEGIN [^-]+-----/,""),e=e.replace(/-----END [^-]+-----[^-]*$/,"")),e.replace(/\s+/g,"")}function nt(r,t,e=`\r
3
- `){return`-----BEGIN ${t}-----${e}${d(r,64,e)}${e}-----END ${t}-----${e}`}function ot(r){let t=r.replace(/[^0-9A-Za-z\/+=]*/g,"");return a(t)}function d(r,t,e=`\r
4
- `){let n=r;return n=n.replace(new RegExp(`(.{${t}})`,"g"),`$1${e}`),n=n.replace(/\s+$/,""),n}function it(r){if(r.length%2!==0)throw"input is not even length";if(r.match(/^[0-9A-Fa-f]+$/)==null)throw"input is not hexadecimal";let t=new ArrayBuffer(r.length/2),e=new DataView(t);for(let n=0;n<r.length/2;n++)e.setUint8(n,parseInt(r.substr(n*2,2),16));return t}function st(r){let t="",e=new DataView(r);for(let n=0;n<r.byteLength;n++)t+=`00${e.getUint8(n).toString(16)}`.slice(-2);return t}function y(r){let t=r,e,n,i,o,s,f,u,g,h;t=D(t);let l=t.match(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/);if(l)return e=parseInt(l[1]),n=parseInt(l[2])-1,i=parseInt(l[3]),o=parseInt(l[4]),s=parseInt(l[5]),f=parseInt(l[6]),u=0,g=l[7],g!==""&&(h=`${g.substr(1)}00`.substr(0,3),u=parseInt(h)),Date.UTC(e,n,i,o,s,f,u);throw new Error(`unsupported zulu format: ${t}`)}function ut(r){let t=new Date(r),e=`0000${t.getUTCFullYear()}`.slice(-4),n=`00${t.getUTCMonth()+1}`.slice(-2),i=`00${t.getUTCDate()}`.slice(-2),o=`00${t.getUTCHours()}`.slice(-2),s=`00${t.getUTCMinutes()}`.slice(-2),f=`00${t.getUTCSeconds()}`.slice(-2),u=`000${t.getUTCMilliseconds()}`.slice(-3);return u=u.replace(/0+$/,""),u=u!==""?`.${u}`:u,`${e+n+i+o+s+f+u}Z`}function lt(r){return Math.round(y(r)/1e3)}function ft(r){return new Date(y(r))}function ct(r,t=!1,e=!1){let n,i=r.getUTCFullYear();if(t){if(i<1950||2049<i)throw new Error(`not proper year for UTCTime: ${i}`);n=`${i}`.slice(-2)}else n=`000${i}`.slice(-4);if(n+=`0${r.getUTCMonth()+1}`.slice(-2),n+=`0${r.getUTCDate()}`.slice(-2),n+=`0${r.getUTCHours()}`.slice(-2),n+=`0${r.getUTCMinutes()}`.slice(-2),n+=`0${r.getUTCSeconds()}`.slice(-2),e){let o=r.getUTCMilliseconds();if(o!==0){let s=`00${o}`.slice(-3);s=s.replace(/0+$/g,""),n+=`.${s}`}}return n+="Z",n}function D(r){return r.match(/^[0-9]{12}Z$/)||r.match(/^[0-9]{12}[.][0-9]*Z$/)?r.match(/^[0-4]/)?`20${r}`:`19${r}`:r}function gt(r){return r.replace(/%/g,"")}function at(r){return r.replace(/(..)/g,"%$1")}function pt(r){let t=encodeURIComponent(r),e="";for(let n=0;n<t.length;n++)t[n]==="%"?(e=e+t.substr(n,3),n=n+2):e=`${e}%${$(t[n])}`;return e}function w(r){let t=r,e="malformed IPv6 address";if(!t.match(/^[0-9A-Fa-f:]+$/))throw e;t=t.toLowerCase();let n=t.split(":").length-1;if(n<2)throw e;let i=":".repeat(7-n+2);t=t.replace("::",i);let o=t.split(":");if(o.length!==8)throw e;for(let s=0;s<8;s++)o[s]=`0000${o[s]}`.slice(-4);return o.join("")}function I(r){let t=r;if(!t.match(/^[0-9A-Fa-f]{32}$/))throw new Error(`malformed IPv6 address: ${t}`);t=t.toLowerCase();let e=t.match(/.{1,4}/g)||[];e=e.map(o=>o.replace(/^0+/,"")),e=e.map(o=>o===""?"0":o),t=`:${e.join(":")}:`;let n=t.match(/:(0:){2,}/g);if(n==null)return t.slice(1,-1);let i=n.sort().slice(-1)[0];return t=t.replace(i.substr(0,i.length-1),":"),t.substr(0,2)!=="::"&&(t=t.substr(1)),t.substr(-2,2)!=="::"&&(t=t.substr(0,t.length-1)),t}function z(r){let t=new Error("malformed hex value");if(!r.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw t;if(r.length===8){let e;try{return e=`${parseInt(r.substr(0,2),16)}.${parseInt(r.substr(2,2),16)}.${parseInt(r.substr(4,2),16)}.${parseInt(r.substr(6,2),16)}`,e}catch{throw t}}else if(r.length===16)try{return`${z(r.substr(0,8))}/${A(r.substr(8))}`}catch{throw t}else{if(r.length===32)return I(r);if(r.length===64)try{return`${I(r.substr(0,32))}/${A(r.substr(32))}`}catch{throw t}else return r}}function M(r){let t=r,e=new Error("malformed IP address");if(t=t.toLowerCase(),!t.match(/^[0-9a-f.:/]+$/))throw e;if(t.match(/^[0-9.]+$/)){let n=t.split(".");if(n.length!==4)throw e;let i="";try{for(let o=0;o<4;o++){let s=parseInt(n[o]);i+=`0${s.toString(16)}`.slice(-2)}return i}catch{throw e}}else if(t.match(/^[0-9.]+\/[0-9]+$/)){let n=t.split("/");return M(n[0])+B(parseInt(n[1]),32)}else{if(t.match(/^[0-9a-f:]+$/)&&t.indexOf(":")!==-1)return w(t);if(t.match(/^[0-9a-f:]+\/[0-9]+$/)&&t.indexOf(":")!==-1){let n=t.split("/");return w(n[0])+B(parseInt(n[1]),128)}else throw e}}function A(r){let t=new Error("malformed mask"),e;try{e=parseInt(r,16).toString(2)}catch{throw t}if(!e.match(/^1*0*$/))throw t;return e.replace(/0+$/,"").length}function B(r,t){if(t===32&&r===0)return"00000000";if(t===128&&r===0)return"00000000000000000000000000000000";let e=Array(r+1).join("1")+Array(t-r+1).join("0");return parseInt(e,2).toString(16)}function ht(r){function t(i){let o=parseInt(i.substr(0,2),16),s=parseInt(i.substr(2),16);if(o===0&&s<128)return String.fromCharCode(s);if(o<8){let h=192|(o&7)<<3|(s&192)>>6,l=128|s&63;return c(h.toString(16)+l.toString(16))}let f=224|(o&240)>>4,u=128|(o&15)<<2|(s&192)>>6,g=128|s&63;return c(f.toString(16)+u.toString(16)+g.toString(16))}let e=r.match(/.{4}/g);return e==null?"":e.map(t).join("")}var vt="typepki-strconv 0.4.0 kjur.github.io/typepki-strconv";export{st as ArrayBuffertohex,E as BAtohex,Q as BAtos,vt as VERSION,Y as aryval,ot as b64nltohex,b as b64tob64u,a as b64tohex,nt as b64topem,j as b64toutf8,p as b64utob64,Z as b64utohex,k as b64utoutf8,_ as binstrtobitstr,O as bitstrtobinstr,ct as datetozulu,pt as encodeURIComponentAll,d as foldnl,it as hextoArrayBuffer,K as hextoBA,x as hextob64,F as hextob64u,z as hextoip,I as hextoipv6,rt as hextopem,L as hextorstr,at as hextouricmp,c as hextoutf8,S as inttobitstr,B as ipnetmask,A as ipprefixlen,M as iptohex,w as ipv6tohex,U as isBase64,J as isBase64URL,q as ishex,W as iso88591hextoutf8,ut as msectozulu,P as namearraytobinstr,v as pemtob64,et as pemtohex,V as rstrtob64,G as rstrtohex,T as stoBA,$ as stohex,C as strpad,D as timetogen,ht as ucs2hextoutf8,gt as uricmptohex,N as utf8tob64,R as utf8tob64u,m as utf8tohex,X as utf8toiso88591hex,ft as zulutodate,y as zulutomsec,lt as zulutosec};
1
+ function m(r){return S(U(r))}function S(r){let t="";for(let e=0;e<r.length;e++){let n=r[e].toString(16);n.length===1&&(n=`0${n}`),t=t+n}return t}function N(r){let t=[];for(let e=0;e<r.length;e+=2)t.push(parseInt(r.slice(e,e+2),16));return t}function U(r){let t=new Array;for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function R(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}function k(r){return r.replace(/%/g,"")}function b(r){return r.replace(/(..)/g,"%$1")}function F(r){let t=encodeURIComponent(r),e="";for(let n=0;n<t.length;n++)t[n]==="%"?(e=e+t.substr(n,3),n=n+2):e=`${e}%${m(t[n])}`;return e}function a(r){return Buffer.from(r,"base64").toString("hex")}function x(r){return Buffer.from(r,"hex").toString("base64")}function c(r){try{return decodeURIComponent(b(r))}catch{throw new Error("malformed hexadecimal UTF-8 string")}}function $(r){return Buffer.from(r,"utf8").toString("hex")}function Z(r){return Buffer.from(r,"base64").toString("utf8")}function L(r){return Buffer.from(r,"utf8").toString("base64")}function G(r){return Buffer.from(p(r),"base64").toString("utf8")}function V(r){return d(Buffer.from(r,"utf8").toString("base64"))}function _(r){return a(p(r))}function O(r){return d(x(r))}function P(r){let t="";for(let e=0;e<r.length;e+=2){let n=parseInt(r.substr(e,2),16);t+=String.fromCharCode(n)}return t}function Y(r){let t="";for(let e=0;e<r.length;e++)t+=`0${r.charCodeAt(e).toString(16)}`.slice(-2);return t}function q(r){return Buffer.from(r).toString("base64")}function d(r){let t=r;return t=t.replace(/\=/g,""),t=t.replace(/\+/g,"-"),t=t.replace(/\//g,"_"),t}function p(r){let t=r;return t.length%4===2?t=`${t}==`:t.length%4===3&&(t=`${t}=`),t=t.replace(/-/g,"+"),t=t.replace(/_/g,"/"),t}var J=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return E(t)}catch{return null}};function K(r){if(typeof r!="string"||r.length%2!==0||!r.match(/^[0-9a-f]+$/))return null;try{let t=parseInt(r.substr(0,2),16);if(t<0||7<t)return null;let e=r.substr(2),n="";for(let i=0;i<e.length;i+=2){let o=e.substr(i,2),s=parseInt(o,16).toString(2);s=`0000000${s}`.slice(-8),n+=s}return n.substr(0,n.length-t)}catch{return null}}function E(r){if(typeof r!="number"||r<0)return null;let t=Number(r).toString(2),e=8-t.length%8;e===8&&(e=0),t=t+T("",e,"0");let n=parseInt(t,2).toString(16);return n.length%2===1&&(n=`0${n}`),`0${e}`+n}var T=(r,t,e)=>{let n=e===void 0?"0":e;return r.length>=t?r:new Array(t-r.length+1).join(n)+r};function Q(r,t){let e=0;for(let o=0;o<r.length;o++)e|=1<<t[r[o]];let n=e.toString(2),i="";for(let o=n.length-1;o>=0;o--)i+=n[o];return i}function W(r,t,e){let n=r,i=t.split(".");for(let o=0;o<i.length&&n;o++){let s=i[o];if(typeof n=="object"&&"length"in n&&s.match(/^[0-9]+$/))n=n[parseInt(s)];else if(typeof n=="object"&&s in n)n=n[s];else return e}return n||n===!1?n:e}function X(r){return!(r.length%2===1||r.match(/^[0-9a-f]+$/)==null)}function v(r){let t=r.replace(/\s+/g,"");return!!(t.match(/^[0-9A-Za-z+\/]+={0,3}$/)&&t.length%4===0)}function H(r){if(r.match(/[+/=]/))return!1;let t=p(r);return v(t)}function tt(r){return c(et(r))}function rt(r){return nt($(r))}function et(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++){let i=parseInt(t[n],16);161<=i&&i<=191?(e.push("c2"),e.push(t[n])):192<=i&&i<=255?(e.push("c3"),e.push((i-64).toString(16))):e.push(t[n])}return e.join("")}function nt(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++)if(t[n]==="c2")n++,e.push(t[n]);else if(t[n]==="c3"){n++;let i=parseInt(t[n],16)+64;e.push(i.toString(16))}else e.push(t[n]);return e.join("")}function ot(r,t,e=`\r
2
+ `){return`-----BEGIN ${t}-----${e}${y(x(r),64)}${e}-----END ${t}-----${e}`}function it(r,t){return a(D(r,t))}function D(r,t){let e=r;if(e.indexOf("-----BEGIN ")===-1)throw new Error("can't find PEM header");return t!==void 0?(e=e.replace(new RegExp(`^[^-]*-----BEGIN ${t}-----`),""),e=e.replace(new RegExp(`-----END ${t}-----[^-]*$`),"")):(e=e.replace(/^[^-]*-----BEGIN [^-]+-----/,""),e=e.replace(/-----END [^-]+-----[^-]*$/,"")),e.replace(/\s+/g,"")}function st(r,t,e=`\r
3
+ `){return`-----BEGIN ${t}-----${e}${y(r,64,e)}${e}-----END ${t}-----${e}`}function ut(r){let t=r.replace(/[^0-9A-Za-z\/+=]*/g,"");return a(t)}function y(r,t,e=`\r
4
+ `){let n=r;return n=n.replace(new RegExp(`(.{${t}})`,"g"),`$1${e}`),n=n.replace(/\s+$/,""),n}function lt(r){if(r.length%2!==0)throw"input is not even length";if(r.match(/^[0-9A-Fa-f]+$/)==null)throw"input is not hexadecimal";let t=new ArrayBuffer(r.length/2),e=new DataView(t);for(let n=0;n<r.length/2;n++)e.setUint8(n,parseInt(r.substr(n*2,2),16));return t}function ft(r){let t="",e=new DataView(r);for(let n=0;n<r.byteLength;n++)t+=`00${e.getUint8(n).toString(16)}`.slice(-2);return t}function w(r){let t=r,e,n,i,o,s,f,u,g,h;t=z(t);let l=t.match(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/);if(l)return e=parseInt(l[1]),n=parseInt(l[2])-1,i=parseInt(l[3]),o=parseInt(l[4]),s=parseInt(l[5]),f=parseInt(l[6]),u=0,g=l[7],g!==""&&(h=`${g.substr(1)}00`.substr(0,3),u=parseInt(h)),Date.UTC(e,n,i,o,s,f,u);throw new Error(`unsupported zulu format: ${t}`)}function ct(r){let t=new Date(r),e=`0000${t.getUTCFullYear()}`.slice(-4),n=`00${t.getUTCMonth()+1}`.slice(-2),i=`00${t.getUTCDate()}`.slice(-2),o=`00${t.getUTCHours()}`.slice(-2),s=`00${t.getUTCMinutes()}`.slice(-2),f=`00${t.getUTCSeconds()}`.slice(-2),u=`000${t.getUTCMilliseconds()}`.slice(-3);return u=u.replace(/0+$/,""),u=u!==""?`.${u}`:u,`${e+n+i+o+s+f+u}Z`}function gt(r){return Math.round(w(r)/1e3)}function at(r){return new Date(w(r))}function pt(r,t=!1,e=!1){let n,i=r.getUTCFullYear();if(t){if(i<1950||2049<i)throw new Error(`not proper year for UTCTime: ${i}`);n=`${i}`.slice(-2)}else n=`000${i}`.slice(-4);if(n+=`0${r.getUTCMonth()+1}`.slice(-2),n+=`0${r.getUTCDate()}`.slice(-2),n+=`0${r.getUTCHours()}`.slice(-2),n+=`0${r.getUTCMinutes()}`.slice(-2),n+=`0${r.getUTCSeconds()}`.slice(-2),e){let o=r.getUTCMilliseconds();if(o!==0){let s=`00${o}`.slice(-3);s=s.replace(/0+$/g,""),n+=`.${s}`}}return n+="Z",n}function z(r){return r.match(/^[0-9]{12}Z$/)||r.match(/^[0-9]{12}[.][0-9]*Z$/)?r.match(/^[0-4]/)?`20${r}`:`19${r}`:r}function I(r){let t=r,e="malformed IPv6 address";if(!t.match(/^[0-9A-Fa-f:]+$/))throw e;t=t.toLowerCase();let n=t.split(":").length-1;if(n<2)throw e;let i=":".repeat(7-n+2);t=t.replace("::",i);let o=t.split(":");if(o.length!==8)throw e;for(let s=0;s<8;s++)o[s]=`0000${o[s]}`.slice(-4);return o.join("")}function A(r){let t=r;if(!t.match(/^[0-9A-Fa-f]{32}$/))throw new Error(`malformed IPv6 address: ${t}`);t=t.toLowerCase();let e=t.match(/.{1,4}/g)||[];e=e.map(o=>o.replace(/^0+/,"")),e=e.map(o=>o===""?"0":o),t=`:${e.join(":")}:`;let n=t.match(/:(0:){2,}/g);if(n==null)return t.slice(1,-1);let i=n.sort().slice(-1)[0];return t=t.replace(i.substr(0,i.length-1),":"),t.substr(0,2)!=="::"&&(t=t.substr(1)),t.substr(-2,2)!=="::"&&(t=t.substr(0,t.length-1)),t}function M(r){let t=new Error("malformed hex value");if(!r.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw t;if(r.length===8){let e;try{return e=`${parseInt(r.substr(0,2),16)}.${parseInt(r.substr(2,2),16)}.${parseInt(r.substr(4,2),16)}.${parseInt(r.substr(6,2),16)}`,e}catch{throw t}}else if(r.length===16)try{return`${M(r.substr(0,8))}/${B(r.substr(8))}`}catch{throw t}else{if(r.length===32)return A(r);if(r.length===64)try{return`${A(r.substr(0,32))}/${B(r.substr(32))}`}catch{throw t}else return r}}function j(r){let t=r,e=new Error("malformed IP address");if(t=t.toLowerCase(),!t.match(/^[0-9a-f.:/]+$/))throw e;if(t.match(/^[0-9.]+$/)){let n=t.split(".");if(n.length!==4)throw e;let i="";try{for(let o=0;o<4;o++){let s=parseInt(n[o]);i+=`0${s.toString(16)}`.slice(-2)}return i}catch{throw e}}else if(t.match(/^[0-9.]+\/[0-9]+$/)){let n=t.split("/");return j(n[0])+C(parseInt(n[1]),32)}else{if(t.match(/^[0-9a-f:]+$/)&&t.indexOf(":")!==-1)return I(t);if(t.match(/^[0-9a-f:]+\/[0-9]+$/)&&t.indexOf(":")!==-1){let n=t.split("/");return I(n[0])+C(parseInt(n[1]),128)}else throw e}}function B(r){let t=new Error("malformed mask"),e;try{e=parseInt(r,16).toString(2)}catch{throw t}if(!e.match(/^1*0*$/))throw t;return e.replace(/0+$/,"").length}function C(r,t){if(t===32&&r===0)return"00000000";if(t===128&&r===0)return"00000000000000000000000000000000";let e=Array(r+1).join("1")+Array(t-r+1).join("0");return parseInt(e,2).toString(16)}function ht(r){function t(i){let o=parseInt(i.substr(0,2),16),s=parseInt(i.substr(2),16);if(o===0&&s<128)return String.fromCharCode(s);if(o<8){let h=192|(o&7)<<3|(s&192)>>6,l=128|s&63;return c(h.toString(16)+l.toString(16))}let f=224|(o&240)>>4,u=128|(o&15)<<2|(s&192)>>6,g=128|s&63;return c(f.toString(16)+u.toString(16)+g.toString(16))}let e=r.match(/.{4}/g);return e==null?"":e.map(t).join("")}function xt(r){return r.length%2===1?`0${r}`:r}var Mt="typepki-strconv 0.4.0 kjur.github.io/typepki-strconv";export{ft as ArrayBuffertohex,S as BAtohex,R as BAtos,Mt as VERSION,W as aryval,ut as b64nltohex,d as b64tob64u,a as b64tohex,st as b64topem,Z as b64toutf8,p as b64utob64,_ as b64utohex,G as b64utoutf8,J as binstrtobitstr,K as bitstrtobinstr,pt as datetozulu,F as encodeURIComponentAll,y as foldnl,xt as hexpad,lt as hextoArrayBuffer,N as hextoBA,x as hextob64,O as hextob64u,M as hextoip,A as hextoipv6,ot as hextopem,P as hextorstr,b as hextouricmp,c as hextoutf8,E as inttobitstr,C as ipnetmask,B as ipprefixlen,j as iptohex,I as ipv6tohex,v as isBase64,H as isBase64URL,X as ishex,tt as iso88591hextoutf8,ct as msectozulu,Q as namearraytobinstr,D as pemtob64,it as pemtohex,q as rstrtob64,Y as rstrtohex,U as stoBA,m as stohex,T as strpad,z as timetogen,ht as ucs2hextoutf8,k as uricmptohex,L as utf8tob64,V as utf8tob64u,$ as utf8tohex,rt as utf8toiso88591hex,at as zulutodate,w as zulutomsec,gt as zulutosec};
@@ -1,4 +1,4 @@
1
- "use strict";var U=Object.defineProperty;var Ut=Object.getOwnPropertyDescriptor;var Et=Object.getOwnPropertyNames;var Tt=Object.prototype.hasOwnProperty;var l=(r,t)=>()=>(r&&(t=r(r=0)),t);var vt=(r,t)=>{for(var e in t)U(r,e,{get:t[e],enumerable:!0})},Dt=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Et(t))!Tt.call(r,o)&&o!==e&&U(r,o,{get:()=>t[o],enumerable:!(n=Ut(t,o))||n.enumerable});return r};var zt=r=>Dt(U({},"__esModule",{value:!0}),r);function a(r){return Buffer.from(r,"base64").toString("hex")}function m(r){return Buffer.from(r,"hex").toString("base64")}function Z(r){return Buffer.from(r,"base64").toString("utf8")}function F(r){return Buffer.from(r,"utf8").toString("base64")}function L(r){return Buffer.from(p(r),"base64").toString("utf8")}function G(r){return d(Buffer.from(r,"utf8").toString("base64"))}function c(r){return Buffer.from(r,"hex").toString("utf8")}function $(r){return Buffer.from(r,"utf8").toString("hex")}function V(r){return a(p(r))}function _(r){return d(m(r))}function O(r){let t="";for(let e=0;e<r.length;e+=2){let n=parseInt(r.substr(e,2),16);t+=String.fromCharCode(n)}return t}function P(r){let t="";for(let e=0;e<r.length;e++)t+=`0${r.charCodeAt(e).toString(16)}`.slice(-2);return t}function Y(r){return Buffer.from(r).toString("base64")}function d(r){let t=r;return t=t.replace(/\=/g,""),t=t.replace(/\+/g,"-"),t=t.replace(/\//g,"_"),t}function p(r){let t=r;return t.length%4===2?t=`${t}==`:t.length%4===3&&(t=`${t}=`),t=t.replace(/-/g,"+"),t=t.replace(/_/g,"/"),t}function J(r){if(typeof r!="string"||r.length%2!==0||!r.match(/^[0-9a-f]+$/))return null;try{let t=parseInt(r.substr(0,2),16);if(t<0||7<t)return null;let e=r.substr(2),n="";for(let o=0;o<e.length;o+=2){let i=e.substr(o,2),s=parseInt(i,16).toString(2);s=`0000000${s}`.slice(-8),n+=s}return n.substr(0,n.length-t)}catch{return null}}function E(r){if(typeof r!="number"||r<0)return null;let t=Number(r).toString(2),e=8-t.length%8;e===8&&(e=0),t=t+T("",e,"0");let n=parseInt(t,2).toString(16);return n.length%2===1&&(n=`0${n}`),`0${e}`+n}function K(r,t){let e=0;for(let i=0;i<r.length;i++)e|=1<<t[r[i]];let n=e.toString(2),o="";for(let i=n.length-1;i>=0;i--)o+=n[i];return o}function Q(r,t,e){let n=r,o=t.split(".");for(let i=0;i<o.length&&n;i++){let s=o[i];if(typeof n=="object"&&"length"in n&&s.match(/^[0-9]+$/))n=n[parseInt(s)];else if(typeof n=="object"&&s in n)n=n[s];else return e}return n||n===!1?n:e}var q,T,h=l(()=>{"use strict";q=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return E(t)}catch{return null}};T=(r,t,e)=>{let n=e===void 0?"0":e;return r.length>=t?r:new Array(t-r.length+1).join(n)+r}});function W(r){return!(r.length%2===1||r.match(/^[0-9a-f]+$/)==null)}function v(r){let t=r.replace(/\s+/g,"");return!!(t.match(/^[0-9A-Za-z+\/]+={0,3}$/)&&t.length%4===0)}function X(r){if(r.match(/[+/=]/))return!1;let t=p(r);return v(t)}var H=l(()=>{"use strict";h()});function y(r){return D(z(r))}function D(r){let t="";for(let e=0;e<r.length;e++){let n=r[e].toString(16);n.length===1&&(n=`0${n}`),t=t+n}return t}function tt(r){let t=[];for(let e=0;e<r.length;e+=2)t.push(parseInt(r.slice(e,e+2),16));return t}function z(r){let t=new Array;for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function rt(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}var M=l(()=>{"use strict"});function et(r){return c(Mt(r))}function nt(r){return jt($(r))}function Mt(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++){let o=parseInt(t[n],16);161<=o&&o<=191?(e.push("c2"),e.push(t[n])):192<=o&&o<=255?(e.push("c3"),e.push((o-64).toString(16))):e.push(t[n])}return e.join("")}function jt(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++)if(t[n]==="c2")n++,e.push(t[n]);else if(t[n]==="c3"){n++;let o=parseInt(t[n],16)+64;e.push(o.toString(16))}else e.push(t[n]);return e.join("")}var ot=l(()=>{"use strict";h()});function it(r,t,e=`\r
2
- `){return`-----BEGIN ${t}-----${e}${w(m(r),64)}${e}-----END ${t}-----${e}`}function st(r,t){return a(j(r,t))}function j(r,t){let e=r;if(e.indexOf("-----BEGIN ")===-1)throw new Error("can't find PEM header");return t!==void 0?(e=e.replace(new RegExp(`^[^-]*-----BEGIN ${t}-----`),""),e=e.replace(new RegExp(`-----END ${t}-----[^-]*$`),"")):(e=e.replace(/^[^-]*-----BEGIN [^-]+-----/,""),e=e.replace(/-----END [^-]+-----[^-]*$/,"")),e.replace(/\s+/g,"")}function ut(r,t,e=`\r
3
- `){return`-----BEGIN ${t}-----${e}${w(r,64,e)}${e}-----END ${t}-----${e}`}function lt(r){let t=r.replace(/[^0-9A-Za-z\/+=]*/g,"");return a(t)}function w(r,t,e=`\r
4
- `){let n=r;return n=n.replace(new RegExp(`(.{${t}})`,"g"),`$1${e}`),n=n.replace(/\s+$/,""),n}var ft=l(()=>{"use strict";h()});function ct(r){if(r.length%2!==0)throw"input is not even length";if(r.match(/^[0-9A-Fa-f]+$/)==null)throw"input is not hexadecimal";let t=new ArrayBuffer(r.length/2),e=new DataView(t);for(let n=0;n<r.length/2;n++)e.setUint8(n,parseInt(r.substr(n*2,2),16));return t}function gt(r){let t="",e=new DataView(r);for(let n=0;n<r.byteLength;n++)t+=`00${e.getUint8(n).toString(16)}`.slice(-2);return t}var at=l(()=>{"use strict"});function I(r){let t=r,e,n,o,i,s,g,u,x,b;t=N(t);let f=t.match(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/);if(f)return e=parseInt(f[1]),n=parseInt(f[2])-1,o=parseInt(f[3]),i=parseInt(f[4]),s=parseInt(f[5]),g=parseInt(f[6]),u=0,x=f[7],x!==""&&(b=`${x.substr(1)}00`.substr(0,3),u=parseInt(b)),Date.UTC(e,n,o,i,s,g,u);throw new Error(`unsupported zulu format: ${t}`)}function pt(r){let t=new Date(r),e=`0000${t.getUTCFullYear()}`.slice(-4),n=`00${t.getUTCMonth()+1}`.slice(-2),o=`00${t.getUTCDate()}`.slice(-2),i=`00${t.getUTCHours()}`.slice(-2),s=`00${t.getUTCMinutes()}`.slice(-2),g=`00${t.getUTCSeconds()}`.slice(-2),u=`000${t.getUTCMilliseconds()}`.slice(-3);return u=u.replace(/0+$/,""),u=u!==""?`.${u}`:u,`${e+n+o+i+s+g+u}Z`}function ht(r){return Math.round(I(r)/1e3)}function xt(r){return new Date(I(r))}function mt(r,t=!1,e=!1){let n,o=r.getUTCFullYear();if(t){if(o<1950||2049<o)throw new Error(`not proper year for UTCTime: ${o}`);n=`${o}`.slice(-2)}else n=`000${o}`.slice(-4);if(n+=`0${r.getUTCMonth()+1}`.slice(-2),n+=`0${r.getUTCDate()}`.slice(-2),n+=`0${r.getUTCHours()}`.slice(-2),n+=`0${r.getUTCMinutes()}`.slice(-2),n+=`0${r.getUTCSeconds()}`.slice(-2),e){let i=r.getUTCMilliseconds();if(i!==0){let s=`00${i}`.slice(-3);s=s.replace(/0+$/g,""),n+=`.${s}`}}return n+="Z",n}function N(r){return r.match(/^[0-9]{12}Z$/)||r.match(/^[0-9]{12}[.][0-9]*Z$/)?r.match(/^[0-4]/)?`20${r}`:`19${r}`:r}var bt=l(()=>{"use strict"});function $t(r){return r.replace(/%/g,"")}function dt(r){return r.replace(/(..)/g,"%$1")}function yt(r){let t=encodeURIComponent(r),e="";for(let n=0;n<t.length;n++)t[n]==="%"?(e=e+t.substr(n,3),n=n+2):e=`${e}%${y(t[n])}`;return e}var wt=l(()=>{"use strict";M()});function A(r){let t=r,e="malformed IPv6 address";if(!t.match(/^[0-9A-Fa-f:]+$/))throw e;t=t.toLowerCase();let n=t.split(":").length-1;if(n<2)throw e;let o=":".repeat(7-n+2);t=t.replace("::",o);let i=t.split(":");if(i.length!==8)throw e;for(let s=0;s<8;s++)i[s]=`0000${i[s]}`.slice(-4);return i.join("")}function B(r){let t=r;if(!t.match(/^[0-9A-Fa-f]{32}$/))throw new Error(`malformed IPv6 address: ${t}`);t=t.toLowerCase();let e=t.match(/.{1,4}/g)||[];e=e.map(i=>i.replace(/^0+/,"")),e=e.map(i=>i===""?"0":i),t=`:${e.join(":")}:`;let n=t.match(/:(0:){2,}/g);if(n==null)return t.slice(1,-1);let o=n.sort().slice(-1)[0];return t=t.replace(o.substr(0,o.length-1),":"),t.substr(0,2)!=="::"&&(t=t.substr(1)),t.substr(-2,2)!=="::"&&(t=t.substr(0,t.length-1)),t}function k(r){let t=new Error("malformed hex value");if(!r.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw t;if(r.length===8){let e;try{return e=`${parseInt(r.substr(0,2),16)}.${parseInt(r.substr(2,2),16)}.${parseInt(r.substr(4,2),16)}.${parseInt(r.substr(6,2),16)}`,e}catch{throw t}}else if(r.length===16)try{return`${k(r.substr(0,8))}/${S(r.substr(8))}`}catch{throw t}else{if(r.length===32)return B(r);if(r.length===64)try{return`${B(r.substr(0,32))}/${S(r.substr(32))}`}catch{throw t}else return r}}function R(r){let t=r,e=new Error("malformed IP address");if(t=t.toLowerCase(),!t.match(/^[0-9a-f.:/]+$/))throw e;if(t.match(/^[0-9.]+$/)){let n=t.split(".");if(n.length!==4)throw e;let o="";try{for(let i=0;i<4;i++){let s=parseInt(n[i]);o+=`0${s.toString(16)}`.slice(-2)}return o}catch{throw e}}else if(t.match(/^[0-9.]+\/[0-9]+$/)){let n=t.split("/");return R(n[0])+C(parseInt(n[1]),32)}else{if(t.match(/^[0-9a-f:]+$/)&&t.indexOf(":")!==-1)return A(t);if(t.match(/^[0-9a-f:]+\/[0-9]+$/)&&t.indexOf(":")!==-1){let n=t.split("/");return A(n[0])+C(parseInt(n[1]),128)}else throw e}}function S(r){let t=new Error("malformed mask"),e;try{e=parseInt(r,16).toString(2)}catch{throw t}if(!e.match(/^1*0*$/))throw t;return e.replace(/0+$/,"").length}function C(r,t){if(t===32&&r===0)return"00000000";if(t===128&&r===0)return"00000000000000000000000000000000";let e=Array(r+1).join("1")+Array(t-r+1).join("0");return parseInt(e,2).toString(16)}var It=l(()=>{"use strict"});function At(r){function t(o){let i=parseInt(o.substr(0,2),16),s=parseInt(o.substr(2),16);if(i===0&&s<128)return String.fromCharCode(s);if(i<8){let b=192|(i&7)<<3|(s&192)>>6,f=128|s&63;return c(b.toString(16)+f.toString(16))}let g=224|(i&240)>>4,u=128|(i&15)<<2|(s&192)>>6,x=128|s&63;return c(g.toString(16)+u.toString(16)+x.toString(16))}let e=r.match(/.{4}/g);return e==null?"":e.map(t).join("")}var Bt=l(()=>{"use strict";h()});var St={};vt(St,{ArrayBuffertohex:()=>gt,BAtohex:()=>D,BAtos:()=>rt,VERSION:()=>Nt,aryval:()=>Q,b64nltohex:()=>lt,b64tob64u:()=>d,b64tohex:()=>a,b64topem:()=>ut,b64toutf8:()=>Z,b64utob64:()=>p,b64utohex:()=>V,b64utoutf8:()=>L,binstrtobitstr:()=>q,bitstrtobinstr:()=>J,datetozulu:()=>mt,encodeURIComponentAll:()=>yt,foldnl:()=>w,hextoArrayBuffer:()=>ct,hextoBA:()=>tt,hextob64:()=>m,hextob64u:()=>_,hextoip:()=>k,hextoipv6:()=>B,hextopem:()=>it,hextorstr:()=>O,hextouricmp:()=>dt,hextoutf8:()=>c,inttobitstr:()=>E,ipnetmask:()=>C,ipprefixlen:()=>S,iptohex:()=>R,ipv6tohex:()=>A,isBase64:()=>v,isBase64URL:()=>X,ishex:()=>W,iso88591hextoutf8:()=>et,msectozulu:()=>pt,namearraytobinstr:()=>K,pemtob64:()=>j,pemtohex:()=>st,rstrtob64:()=>Y,rstrtohex:()=>P,stoBA:()=>z,stohex:()=>y,strpad:()=>T,timetogen:()=>N,ucs2hextoutf8:()=>At,uricmptohex:()=>$t,utf8tob64:()=>F,utf8tob64u:()=>G,utf8tohex:()=>$,utf8toiso88591hex:()=>nt,zulutodate:()=>xt,zulutomsec:()=>I,zulutosec:()=>ht});var Nt,Ct=l(()=>{"use strict";H();M();h();ot();ft();at();bt();wt();It();Bt();Nt="typepki-strconv 0.4.0 kjur.github.io/typepki-strconv"});module.exports=(Ct(),zt(St));
1
+ "use strict";var E=Object.defineProperty;var Tt=Object.getOwnPropertyDescriptor;var vt=Object.getOwnPropertyNames;var Dt=Object.prototype.hasOwnProperty;var l=(r,t)=>()=>(r&&(t=r(r=0)),t);var zt=(r,t)=>{for(var e in t)E(r,e,{get:t[e],enumerable:!0})},Mt=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vt(t))!Dt.call(r,o)&&o!==e&&E(r,o,{get:()=>t[o],enumerable:!(n=Tt(t,o))||n.enumerable});return r};var jt=r=>Mt(E({},"__esModule",{value:!0}),r);function $(r){return T(v(r))}function T(r){let t="";for(let e=0;e<r.length;e++){let n=r[e].toString(16);n.length===1&&(n=`0${n}`),t=t+n}return t}function L(r){let t=[];for(let e=0;e<r.length;e+=2)t.push(parseInt(r.slice(e,e+2),16));return t}function v(r){let t=new Array;for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function G(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}var D=l(()=>{"use strict"});function V(r){return r.replace(/%/g,"")}function d(r){return r.replace(/(..)/g,"%$1")}function _(r){let t=encodeURIComponent(r),e="";for(let n=0;n<t.length;n++)t[n]==="%"?(e=e+t.substr(n,3),n=n+2):e=`${e}%${$(t[n])}`;return e}var z=l(()=>{"use strict";D()});function a(r){return Buffer.from(r,"base64").toString("hex")}function m(r){return Buffer.from(r,"hex").toString("base64")}function c(r){try{return decodeURIComponent(d(r))}catch{throw new Error("malformed hexadecimal UTF-8 string")}}function y(r){return Buffer.from(r,"utf8").toString("hex")}function O(r){return Buffer.from(r,"base64").toString("utf8")}function P(r){return Buffer.from(r,"utf8").toString("base64")}function Y(r){return Buffer.from(p(r),"base64").toString("utf8")}function q(r){return w(Buffer.from(r,"utf8").toString("base64"))}function J(r){return a(p(r))}function K(r){return w(m(r))}function Q(r){let t="";for(let e=0;e<r.length;e+=2){let n=parseInt(r.substr(e,2),16);t+=String.fromCharCode(n)}return t}function W(r){let t="";for(let e=0;e<r.length;e++)t+=`0${r.charCodeAt(e).toString(16)}`.slice(-2);return t}function X(r){return Buffer.from(r).toString("base64")}function w(r){let t=r;return t=t.replace(/\=/g,""),t=t.replace(/\+/g,"-"),t=t.replace(/\//g,"_"),t}function p(r){let t=r;return t.length%4===2?t=`${t}==`:t.length%4===3&&(t=`${t}=`),t=t.replace(/-/g,"+"),t=t.replace(/_/g,"/"),t}function tt(r){if(typeof r!="string"||r.length%2!==0||!r.match(/^[0-9a-f]+$/))return null;try{let t=parseInt(r.substr(0,2),16);if(t<0||7<t)return null;let e=r.substr(2),n="";for(let o=0;o<e.length;o+=2){let i=e.substr(o,2),s=parseInt(i,16).toString(2);s=`0000000${s}`.slice(-8),n+=s}return n.substr(0,n.length-t)}catch{return null}}function M(r){if(typeof r!="number"||r<0)return null;let t=Number(r).toString(2),e=8-t.length%8;e===8&&(e=0),t=t+j("",e,"0");let n=parseInt(t,2).toString(16);return n.length%2===1&&(n=`0${n}`),`0${e}`+n}function rt(r,t){let e=0;for(let i=0;i<r.length;i++)e|=1<<t[r[i]];let n=e.toString(2),o="";for(let i=n.length-1;i>=0;i--)o+=n[i];return o}function et(r,t,e){let n=r,o=t.split(".");for(let i=0;i<o.length&&n;i++){let s=o[i];if(typeof n=="object"&&"length"in n&&s.match(/^[0-9]+$/))n=n[parseInt(s)];else if(typeof n=="object"&&s in n)n=n[s];else return e}return n||n===!1?n:e}var H,j,h=l(()=>{"use strict";z();H=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return M(t)}catch{return null}};j=(r,t,e)=>{let n=e===void 0?"0":e;return r.length>=t?r:new Array(t-r.length+1).join(n)+r}});function nt(r){return!(r.length%2===1||r.match(/^[0-9a-f]+$/)==null)}function N(r){let t=r.replace(/\s+/g,"");return!!(t.match(/^[0-9A-Za-z+\/]+={0,3}$/)&&t.length%4===0)}function ot(r){if(r.match(/[+/=]/))return!1;let t=p(r);return N(t)}var it=l(()=>{"use strict";h()});function st(r){return c(Nt(r))}function ut(r){return Rt(y(r))}function Nt(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++){let o=parseInt(t[n],16);161<=o&&o<=191?(e.push("c2"),e.push(t[n])):192<=o&&o<=255?(e.push("c3"),e.push((o-64).toString(16))):e.push(t[n])}return e.join("")}function Rt(r){let t=r.match(/.{1,2}/g);if(t==null)return"";let e=[];for(let n=0;n<t.length;n++)if(t[n]==="c2")n++,e.push(t[n]);else if(t[n]==="c3"){n++;let o=parseInt(t[n],16)+64;e.push(o.toString(16))}else e.push(t[n]);return e.join("")}var lt=l(()=>{"use strict";h()});function ft(r,t,e=`\r
2
+ `){return`-----BEGIN ${t}-----${e}${I(m(r),64)}${e}-----END ${t}-----${e}`}function ct(r,t){return a(R(r,t))}function R(r,t){let e=r;if(e.indexOf("-----BEGIN ")===-1)throw new Error("can't find PEM header");return t!==void 0?(e=e.replace(new RegExp(`^[^-]*-----BEGIN ${t}-----`),""),e=e.replace(new RegExp(`-----END ${t}-----[^-]*$`),"")):(e=e.replace(/^[^-]*-----BEGIN [^-]+-----/,""),e=e.replace(/-----END [^-]+-----[^-]*$/,"")),e.replace(/\s+/g,"")}function gt(r,t,e=`\r
3
+ `){return`-----BEGIN ${t}-----${e}${I(r,64,e)}${e}-----END ${t}-----${e}`}function at(r){let t=r.replace(/[^0-9A-Za-z\/+=]*/g,"");return a(t)}function I(r,t,e=`\r
4
+ `){let n=r;return n=n.replace(new RegExp(`(.{${t}})`,"g"),`$1${e}`),n=n.replace(/\s+$/,""),n}var pt=l(()=>{"use strict";h()});function ht(r){if(r.length%2!==0)throw"input is not even length";if(r.match(/^[0-9A-Fa-f]+$/)==null)throw"input is not hexadecimal";let t=new ArrayBuffer(r.length/2),e=new DataView(t);for(let n=0;n<r.length/2;n++)e.setUint8(n,parseInt(r.substr(n*2,2),16));return t}function xt(r){let t="",e=new DataView(r);for(let n=0;n<r.byteLength;n++)t+=`00${e.getUint8(n).toString(16)}`.slice(-2);return t}var mt=l(()=>{"use strict"});function A(r){let t=r,e,n,o,i,s,g,u,x,b;t=k(t);let f=t.match(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/);if(f)return e=parseInt(f[1]),n=parseInt(f[2])-1,o=parseInt(f[3]),i=parseInt(f[4]),s=parseInt(f[5]),g=parseInt(f[6]),u=0,x=f[7],x!==""&&(b=`${x.substr(1)}00`.substr(0,3),u=parseInt(b)),Date.UTC(e,n,o,i,s,g,u);throw new Error(`unsupported zulu format: ${t}`)}function bt(r){let t=new Date(r),e=`0000${t.getUTCFullYear()}`.slice(-4),n=`00${t.getUTCMonth()+1}`.slice(-2),o=`00${t.getUTCDate()}`.slice(-2),i=`00${t.getUTCHours()}`.slice(-2),s=`00${t.getUTCMinutes()}`.slice(-2),g=`00${t.getUTCSeconds()}`.slice(-2),u=`000${t.getUTCMilliseconds()}`.slice(-3);return u=u.replace(/0+$/,""),u=u!==""?`.${u}`:u,`${e+n+o+i+s+g+u}Z`}function $t(r){return Math.round(A(r)/1e3)}function dt(r){return new Date(A(r))}function yt(r,t=!1,e=!1){let n,o=r.getUTCFullYear();if(t){if(o<1950||2049<o)throw new Error(`not proper year for UTCTime: ${o}`);n=`${o}`.slice(-2)}else n=`000${o}`.slice(-4);if(n+=`0${r.getUTCMonth()+1}`.slice(-2),n+=`0${r.getUTCDate()}`.slice(-2),n+=`0${r.getUTCHours()}`.slice(-2),n+=`0${r.getUTCMinutes()}`.slice(-2),n+=`0${r.getUTCSeconds()}`.slice(-2),e){let i=r.getUTCMilliseconds();if(i!==0){let s=`00${i}`.slice(-3);s=s.replace(/0+$/g,""),n+=`.${s}`}}return n+="Z",n}function k(r){return r.match(/^[0-9]{12}Z$/)||r.match(/^[0-9]{12}[.][0-9]*Z$/)?r.match(/^[0-4]/)?`20${r}`:`19${r}`:r}var wt=l(()=>{"use strict"});function B(r){let t=r,e="malformed IPv6 address";if(!t.match(/^[0-9A-Fa-f:]+$/))throw e;t=t.toLowerCase();let n=t.split(":").length-1;if(n<2)throw e;let o=":".repeat(7-n+2);t=t.replace("::",o);let i=t.split(":");if(i.length!==8)throw e;for(let s=0;s<8;s++)i[s]=`0000${i[s]}`.slice(-4);return i.join("")}function C(r){let t=r;if(!t.match(/^[0-9A-Fa-f]{32}$/))throw new Error(`malformed IPv6 address: ${t}`);t=t.toLowerCase();let e=t.match(/.{1,4}/g)||[];e=e.map(i=>i.replace(/^0+/,"")),e=e.map(i=>i===""?"0":i),t=`:${e.join(":")}:`;let n=t.match(/:(0:){2,}/g);if(n==null)return t.slice(1,-1);let o=n.sort().slice(-1)[0];return t=t.replace(o.substr(0,o.length-1),":"),t.substr(0,2)!=="::"&&(t=t.substr(1)),t.substr(-2,2)!=="::"&&(t=t.substr(0,t.length-1)),t}function F(r){let t=new Error("malformed hex value");if(!r.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw t;if(r.length===8){let e;try{return e=`${parseInt(r.substr(0,2),16)}.${parseInt(r.substr(2,2),16)}.${parseInt(r.substr(4,2),16)}.${parseInt(r.substr(6,2),16)}`,e}catch{throw t}}else if(r.length===16)try{return`${F(r.substr(0,8))}/${S(r.substr(8))}`}catch{throw t}else{if(r.length===32)return C(r);if(r.length===64)try{return`${C(r.substr(0,32))}/${S(r.substr(32))}`}catch{throw t}else return r}}function Z(r){let t=r,e=new Error("malformed IP address");if(t=t.toLowerCase(),!t.match(/^[0-9a-f.:/]+$/))throw e;if(t.match(/^[0-9.]+$/)){let n=t.split(".");if(n.length!==4)throw e;let o="";try{for(let i=0;i<4;i++){let s=parseInt(n[i]);o+=`0${s.toString(16)}`.slice(-2)}return o}catch{throw e}}else if(t.match(/^[0-9.]+\/[0-9]+$/)){let n=t.split("/");return Z(n[0])+U(parseInt(n[1]),32)}else{if(t.match(/^[0-9a-f:]+$/)&&t.indexOf(":")!==-1)return B(t);if(t.match(/^[0-9a-f:]+\/[0-9]+$/)&&t.indexOf(":")!==-1){let n=t.split("/");return B(n[0])+U(parseInt(n[1]),128)}else throw e}}function S(r){let t=new Error("malformed mask"),e;try{e=parseInt(r,16).toString(2)}catch{throw t}if(!e.match(/^1*0*$/))throw t;return e.replace(/0+$/,"").length}function U(r,t){if(t===32&&r===0)return"00000000";if(t===128&&r===0)return"00000000000000000000000000000000";let e=Array(r+1).join("1")+Array(t-r+1).join("0");return parseInt(e,2).toString(16)}var It=l(()=>{"use strict"});function At(r){function t(o){let i=parseInt(o.substr(0,2),16),s=parseInt(o.substr(2),16);if(i===0&&s<128)return String.fromCharCode(s);if(i<8){let b=192|(i&7)<<3|(s&192)>>6,f=128|s&63;return c(b.toString(16)+f.toString(16))}let g=224|(i&240)>>4,u=128|(i&15)<<2|(s&192)>>6,x=128|s&63;return c(g.toString(16)+u.toString(16)+x.toString(16))}let e=r.match(/.{4}/g);return e==null?"":e.map(t).join("")}var Bt=l(()=>{"use strict";h()});function Ct(r){return r.length%2===1?`0${r}`:r}var St=l(()=>{"use strict"});var Ut={};zt(Ut,{ArrayBuffertohex:()=>xt,BAtohex:()=>T,BAtos:()=>G,VERSION:()=>kt,aryval:()=>et,b64nltohex:()=>at,b64tob64u:()=>w,b64tohex:()=>a,b64topem:()=>gt,b64toutf8:()=>O,b64utob64:()=>p,b64utohex:()=>J,b64utoutf8:()=>Y,binstrtobitstr:()=>H,bitstrtobinstr:()=>tt,datetozulu:()=>yt,encodeURIComponentAll:()=>_,foldnl:()=>I,hexpad:()=>Ct,hextoArrayBuffer:()=>ht,hextoBA:()=>L,hextob64:()=>m,hextob64u:()=>K,hextoip:()=>F,hextoipv6:()=>C,hextopem:()=>ft,hextorstr:()=>Q,hextouricmp:()=>d,hextoutf8:()=>c,inttobitstr:()=>M,ipnetmask:()=>U,ipprefixlen:()=>S,iptohex:()=>Z,ipv6tohex:()=>B,isBase64:()=>N,isBase64URL:()=>ot,ishex:()=>nt,iso88591hextoutf8:()=>st,msectozulu:()=>bt,namearraytobinstr:()=>rt,pemtob64:()=>R,pemtohex:()=>ct,rstrtob64:()=>X,rstrtohex:()=>W,stoBA:()=>v,stohex:()=>$,strpad:()=>j,timetogen:()=>k,ucs2hextoutf8:()=>At,uricmptohex:()=>V,utf8tob64:()=>P,utf8tob64u:()=>q,utf8tohex:()=>y,utf8toiso88591hex:()=>ut,zulutodate:()=>dt,zulutomsec:()=>A,zulutosec:()=>$t});var kt,Et=l(()=>{"use strict";it();D();h();lt();pt();mt();wt();z();It();Bt();St();kt="typepki-strconv 0.4.0 kjur.github.io/typepki-strconv"});module.exports=(Et(),jt(Ut));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typepki-strconv",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "author": "Kenji Urushima <kenji.urushima@gmail.com>",
5
5
  "description": "TypeScript string converters and utilities sub module for TypePKI library (alpha version)",
6
6
  "homepage": "https://kjur.github.io/typepki-strconv",
package/src/conv.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { hextouricmp } from "./conv_uricmp.mts";
2
+
1
3
  // ==== hex / base64 ======================================
2
4
  export function b64tohex(b64: string): string {
3
5
  return Buffer.from(b64, "base64").toString("hex");
@@ -7,6 +9,29 @@ export function hextob64(hex: string): string {
7
9
  return Buffer.from(hex, "hex").toString("base64");
8
10
  }
9
11
 
12
+ // ==== hex / utf8 ========================================
13
+ /**
14
+ * convert hexadecimal string to UTF-8 string
15
+ * @param h - hexadecimal string
16
+ * @return UTF-8 string
17
+ * @throws Error if hexadecimal can't decoded as UTF-8 string
18
+ * @example
19
+ * hextoutf8("616263") -> "abc"
20
+ * hextoutf8("616161e38182e38184e38186") -> "aaaあいう"
21
+ * hextoutf8("6161ff") -> throws malformed error
22
+ */
23
+ export function hextoutf8(h: string): string {
24
+ try {
25
+ return decodeURIComponent(hextouricmp(h));
26
+ } catch (ex) {
27
+ throw new Error("malformed hexadecimal UTF-8 string");
28
+ }
29
+ }
30
+
31
+ export function utf8tohex(u8: string): string {
32
+ return Buffer.from(u8, "utf8").toString("hex");
33
+ }
34
+
10
35
  // ==== utf8 / base64 =====================================
11
36
  export function b64toutf8(b64: string): string {
12
37
  return Buffer.from(b64, "base64").toString("utf8");
@@ -24,16 +49,6 @@ export function b64utoutf8(b64u: string): string {
24
49
  export function utf8tob64u(u8: string): string {
25
50
  return b64tob64u(Buffer.from(u8, "utf8").toString("base64"));
26
51
  }
27
-
28
- // ==== hex / utf8 ========================================
29
- export function hextoutf8(hex: string): string {
30
- return Buffer.from(hex, "hex").toString("utf8");
31
- }
32
-
33
- export function utf8tohex(u8: string): string {
34
- return Buffer.from(u8, "utf8").toString("hex");
35
- }
36
-
37
52
  // ==== hex / base64u =====================================
38
53
  export function b64utohex(b64u: string): string {
39
54
  return b64tohex(b64utob64(b64u));
package/src/conv.test.mts CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  hextob64,
13
13
  hextob64u,
14
14
  hextorstr,
15
+ hextoutf8,
15
16
  inttobitstr,
16
17
  namearraytobinstr,
17
18
  rstrtob64,
@@ -97,3 +98,13 @@ test("rstrtohex", () => {
97
98
  test("rstrtob64", () => {
98
99
  expect(rstrtob64("aaa")).toBe("YWFh");
99
100
  });
101
+
102
+ // ==== hex / utf8 =====================================
103
+ test("hextoutf8", () => {
104
+ expect(hextoutf8("616161")).toBe("aaa");
105
+ expect(hextoutf8("616161e38182e38184e38186")).toBe("aaaあいう");
106
+ expect(hextoutf8("e381bbe38192")).toBe("ほげ");
107
+ expect(() => {
108
+ hextoutf8("6161ff");
109
+ }).toThrow(/malformed hexadecimal UTF-8/);
110
+ });
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
 
3
- import { encodeURIComponentAll, hextouricmp, uricmptohex } from "./index.mts";
3
+ import { encodeURIComponentAll, hextouricmp, uricmptohex, hextoutf8 } from "./index.mts";
4
4
 
5
5
  test("uricmptohex", () => {
6
6
  expect(uricmptohex("%67%68")).toBe("6768");
@@ -0,0 +1,11 @@
1
+ /**
2
+ * zero padding for hexadecimal string
3
+ * @param s - odd or even length hexadecimal string
4
+ * @return even length zero padded hexadecimal string
5
+ * @example
6
+ * hexpad("1") -> "01"
7
+ * hexpad("ab3c") -> "ab3c"
8
+ */
9
+ export function hexpad(s: string): string {
10
+ return (s.length % 2 === 1) ? `0${s}` : s;
11
+ }
@@ -0,0 +1,7 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { hexpad } from "./index.mts";
3
+
4
+ test("hexpad", () => {
5
+ expect(hexpad("1234")).toBe("1234");
6
+ expect(hexpad("234")).toBe("0234");
7
+ });
@@ -0,0 +1 @@
1
+ import { hexpad } from "./index.mts";
package/src/index.mts CHANGED
@@ -101,3 +101,6 @@ export { ipv6tohex, hextoipv6, hextoip, iptohex, ipprefixlen, ipnetmask };
101
101
 
102
102
  import { ucs2hextoutf8 } from "./conv_ucs2.mts";
103
103
  export { ucs2hextoutf8 };
104
+
105
+ import { hexpad } from "./hexutil.mts";
106
+ export { hexpad };