typepki-strconv 0.1.0 → 0.2.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,6 +1,8 @@
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/)
5
+
4
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.
5
7
 
6
8
  The 'typepki-strconv' is a TypeScript string converters and utilities sub module for TypePKI library.
@@ -9,6 +11,7 @@ Following string types are supported:
9
11
  - Base64 and Base64URL encoded string
10
12
  - hexadecimal string
11
13
  - ArrayBuffer
14
+ - byte array
12
15
  - Zule time
13
16
  - UTF8 string
14
17
  - raw string
@@ -8,10 +8,22 @@
8
8
  export declare function stohex(s: string): string;
9
9
  /**
10
10
  * convert an array of bytes(Number) to hexadecimal string.
11
- * @param a - a array of bytes
11
+ * @param a - an array of byte
12
12
  * @return hexadecimal string
13
+ * @see {@link hextoBA}
14
+ * @example
15
+ * hextoBA([97, 97, 97]) -> "616161"
13
16
  */
14
17
  export declare function BAtohex(a: Array<number>): string;
18
+ /**
19
+ * convert an hexadecimal string to array of numbers.
20
+ * @param h - a hexadecimal string
21
+ * @return array of numbers
22
+ * @see {@link BAtohex}
23
+ * @example
24
+ * hextoBA("616161") -> [97, 97, 97]
25
+ */
26
+ export declare function hextoBA(h: string): Array<number>;
15
27
  /**
16
28
  * convert a string to an array of character codes
17
29
  * @param s - string
@@ -1 +1 @@
1
- {"version":3,"file":"conv_ba.d.mts","sourceRoot":"","sources":["../../src/conv_ba.mts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAExC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAQhD;AAGD;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAM9C;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAM9C"}
1
+ {"version":3,"file":"conv_ba.d.mts","sourceRoot":"","sources":["../../src/conv_ba.mts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAQhD;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAMhD;AAGD;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAM9C;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAM9C"}
@@ -1,7 +1,7 @@
1
1
  declare const VERSION: string;
2
2
  export { VERSION };
3
- import { BAtohex, BAtos, stoBA, stohex } from "./conv_ba.mts";
4
- export { stohex, BAtohex, stoBA, BAtos };
3
+ import { BAtohex, BAtos, hextoBA, stoBA, stohex } from "./conv_ba.mts";
4
+ export { stohex, BAtohex, hextoBA, stoBA, BAtos };
5
5
  import { Dictionary, aryval, b64tob64u, b64tohex, b64toutf8, b64utob64, b64utohex, b64utoutf8, binstrtobitstr, bitstrtobinstr, hextob64, hextob64u, hextorstr, hextoutf8, inttobitstr, namearraytobinstr, rstrtob64, rstrtohex, strpad, utf8tob64, utf8tob64u, utf8tohex } from "./conv.mts";
6
6
  export { b64tohex, hextob64, b64toutf8, utf8tob64, b64utoutf8, utf8tob64u, hextoutf8, utf8tohex, b64utohex, hextob64u, b64tob64u, b64utob64, hextorstr, rstrtohex, binstrtobitstr, bitstrtobinstr, inttobitstr, strpad, namearraytobinstr, aryval, rstrtob64, };
7
7
  export type { Dictionary };
@@ -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,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAEzC,OAAO,EACL,UAAU,EACV,MAAM,EACN,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,SAAS,EACT,SAAS,EACT,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,MAAM,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,cAAc,EACd,cAAc,EACd,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,MAAM,EACN,SAAS,GACV,CAAC;AACF,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;AAEhD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;AAE9C,OAAO,EACL,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAEhF,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAE3D,OAAO,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,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"}
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,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAElD,OAAO,EACL,UAAU,EACV,MAAM,EACN,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,SAAS,EACT,SAAS,EACT,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,MAAM,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,cAAc,EACd,cAAc,EACd,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,MAAM,EACN,SAAS,GACV,CAAC;AACF,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;AAEhD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;AAE9C,OAAO,EACL,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAEhF,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAE3D,OAAO,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,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"}
@@ -1,4 +1,4 @@
1
- function x(r){return C(B(r))}function C(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 B(r){let t=new Array;for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function z(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}function a(r){return Buffer.from(r,"base64").toString("hex")}function h(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($(r),"base64").toString("utf8")}function F(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 R(r){return a($(r))}function Z(r){return b(h(r))}function G(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 V(r){let t="";for(let e=0;e<r.length;e++)t+=`0${r.charCodeAt(e).toString(16)}`.slice(-2);return t}function _(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 $(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 L=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return E(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 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+U("",e,"0");let n=parseInt(t,2).toString(16);return n.length%2===1&&(n=`0${n}`),`0${e}`+n}var U=(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 c(K(r))}function J(r){return Q(m(r))}function K(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 Q(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 W(r,t,e=`\r
2
- `){return`-----BEGIN ${t}-----${e}${d(h(r),64)}${e}-----END ${t}-----${e}`}function X(r,t){return a(T(r,t))}function T(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 H(r,t,e=`\r
3
- `){return`-----BEGIN ${t}-----${e}${d(r,64,e)}${e}-----END ${t}-----${e}`}function tt(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 rt(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 et(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,p;t=v(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!==""&&(p=`${g.substr(1)}00`.substr(0,3),u=parseInt(p)),Date.UTC(e,n,i,o,s,f,u);throw new Error(`unsupported zulu format: ${t}`)}function nt(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 ot(r){return Math.round(y(r)/1e3)}function it(r){return new Date(y(r))}function st(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 v(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 ut(r){return r.replace(/%/g,"")}function lt(r){return r.replace(/(..)/g,"%$1")}function ft(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}%${x(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 D(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`${D(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])+S(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])+S(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 S(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 ct(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 p=192|(o&7)<<3|(s&192)>>6,l=128|s&63;return c(p.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 St="typepki-strconv 0.1.0 kjur.github.io/typepki-strconv";export{et as ArrayBuffertohex,C as BAtohex,z as BAtos,St as VERSION,Y as aryval,tt as b64nltohex,b as b64tob64u,a as b64tohex,H as b64topem,j as b64toutf8,$ as b64utob64,R as b64utohex,k as b64utoutf8,L as binstrtobitstr,O as bitstrtobinstr,st as datetozulu,ft as encodeURIComponentAll,d as foldnl,rt as hextoArrayBuffer,h as hextob64,Z as hextob64u,D as hextoip,I as hextoipv6,W as hextopem,G as hextorstr,lt as hextouricmp,c as hextoutf8,E as inttobitstr,S as ipnetmask,A as ipprefixlen,M as iptohex,w as ipv6tohex,q as iso88591hextoutf8,nt as msectozulu,P as namearraytobinstr,T as pemtob64,X as pemtohex,_ as rstrtob64,V as rstrtohex,B as stoBA,x as stohex,U as strpad,v as timetogen,ct as ucs2hextoutf8,ut as uricmptohex,N as utf8tob64,F as utf8tob64u,m as utf8tohex,J as utf8toiso88591hex,it as zulutodate,y as zulutomsec,ot as zulutosec};
1
+ function x(r){return B(C(r))}function B(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 z(r){let t=[];for(let e=0;e<r.length;e+=2)t.push(parseInt(r.slice(e,e+2),16));return t}function C(r){let t=new Array;for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function j(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}function a(r){return Buffer.from(r,"base64").toString("hex")}function h(r){return Buffer.from(r,"hex").toString("base64")}function N(r){return Buffer.from(r,"base64").toString("utf8")}function k(r){return Buffer.from(r,"utf8").toString("base64")}function F(r){return Buffer.from($(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($(r))}function G(r){return b(h(r))}function V(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 _(r){let t="";for(let e=0;e<r.length;e++)t+=`0${r.charCodeAt(e).toString(16)}`.slice(-2);return t}function L(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 $(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 O=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return E(t)}catch{return null}};function P(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+U("",e,"0");let n=parseInt(t,2).toString(16);return n.length%2===1&&(n=`0${n}`),`0${e}`+n}var U=(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 Y(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 q(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 J(r){return c(Q(r))}function K(r){return W(m(r))}function Q(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 W(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 X(r,t,e=`\r
2
+ `){return`-----BEGIN ${t}-----${e}${d(h(r),64)}${e}-----END ${t}-----${e}`}function H(r,t){return a(T(r,t))}function T(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 tt(r,t,e=`\r
3
+ `){return`-----BEGIN ${t}-----${e}${d(r,64,e)}${e}-----END ${t}-----${e}`}function rt(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 et(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 nt(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,p;t=v(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!==""&&(p=`${g.substr(1)}00`.substr(0,3),u=parseInt(p)),Date.UTC(e,n,i,o,s,f,u);throw new Error(`unsupported zulu format: ${t}`)}function ot(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 it(r){return Math.round(y(r)/1e3)}function st(r){return new Date(y(r))}function ut(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 v(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 lt(r){return r.replace(/%/g,"")}function ft(r){return r.replace(/(..)/g,"%$1")}function ct(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}%${x(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 D(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`${D(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])+S(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])+S(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 S(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 gt(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 p=192|(o&7)<<3|(s&192)>>6,l=128|s&63;return c(p.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 Bt="typepki-strconv 0.2.0 kjur.github.io/typepki-strconv";export{nt as ArrayBuffertohex,B as BAtohex,j as BAtos,Bt as VERSION,q as aryval,rt as b64nltohex,b as b64tob64u,a as b64tohex,tt as b64topem,N as b64toutf8,$ as b64utob64,Z as b64utohex,F as b64utoutf8,O as binstrtobitstr,P as bitstrtobinstr,ut as datetozulu,ct as encodeURIComponentAll,d as foldnl,et as hextoArrayBuffer,z as hextoBA,h as hextob64,G as hextob64u,D as hextoip,I as hextoipv6,X as hextopem,V as hextorstr,ft as hextouricmp,c as hextoutf8,E as inttobitstr,S as ipnetmask,A as ipprefixlen,M as iptohex,w as ipv6tohex,J as iso88591hextoutf8,ot as msectozulu,Y as namearraytobinstr,T as pemtob64,H as pemtohex,L as rstrtob64,_ as rstrtohex,C as stoBA,x as stohex,U as strpad,v as timetogen,gt as ucs2hextoutf8,lt as uricmptohex,k as utf8tob64,R as utf8tob64u,m as utf8tohex,K as utf8toiso88591hex,st as zulutodate,y as zulutomsec,it as zulutosec};
@@ -1,4 +1,4 @@
1
- "use strict";var E=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var St=Object.prototype.hasOwnProperty;var f=(r,t)=>()=>(r&&(t=r(r=0)),t);var Ct=(r,t)=>{for(var e in t)E(r,e,{get:t[e],enumerable:!0})},Bt=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of At(t))!St.call(r,o)&&o!==e&&E(r,o,{get:()=>t[o],enumerable:!(n=It(t,o))||n.enumerable});return r};var Et=r=>Bt(E({},"__esModule",{value:!0}),r);function b(r){return U(T(r))}function U(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 T(r){let t=new Array;for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function F(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}var v=f(()=>{"use strict"});function a(r){return Buffer.from(r,"base64").toString("hex")}function h(r){return Buffer.from(r,"hex").toString("base64")}function R(r){return Buffer.from(r,"base64").toString("utf8")}function Z(r){return Buffer.from(r,"utf8").toString("base64")}function G(r){return Buffer.from(y(r),"base64").toString("utf8")}function V(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 _(r){return a(y(r))}function L(r){return d(h(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 y(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 D(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+M("",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,M,x=f(()=>{"use strict";q=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return D(t)}catch{return null}};M=(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 c(Ut(r))}function X(r){return Tt($(r))}function Ut(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 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 o=parseInt(t[n],16)+64;e.push(o.toString(16))}else e.push(t[n]);return e.join("")}var H=f(()=>{"use strict";x()});function tt(r,t,e=`\r
2
- `){return`-----BEGIN ${t}-----${e}${w(h(r),64)}${e}-----END ${t}-----${e}`}function rt(r,t){return a(z(r,t))}function z(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 et(r,t,e=`\r
3
- `){return`-----BEGIN ${t}-----${e}${w(r,64,e)}${e}-----END ${t}-----${e}`}function nt(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 ot=f(()=>{"use strict";x()});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}var ut=f(()=>{"use strict"});function I(r){let t=r,e,n,o,i,s,g,u,p,m;t=j(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,o=parseInt(l[3]),i=parseInt(l[4]),s=parseInt(l[5]),g=parseInt(l[6]),u=0,p=l[7],p!==""&&(m=`${p.substr(1)}00`.substr(0,3),u=parseInt(m)),Date.UTC(e,n,o,i,s,g,u);throw new Error(`unsupported zulu format: ${t}`)}function lt(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 ft(r){return Math.round(I(r)/1e3)}function ct(r){return new Date(I(r))}function gt(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 j(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 at=f(()=>{"use strict"});function pt(r){return r.replace(/%/g,"")}function ht(r){return r.replace(/(..)/g,"%$1")}function xt(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}%${b(t[n])}`;return e}var mt=f(()=>{"use strict";v()});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 S(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 N(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`${N(r.substr(0,8))}/${C(r.substr(8))}`}catch{throw t}else{if(r.length===32)return S(r);if(r.length===64)try{return`${S(r.substr(0,32))}/${C(r.substr(32))}`}catch{throw t}else return r}}function k(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 k(n[0])+B(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])+B(parseInt(n[1]),128)}else throw e}}function C(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)}var bt=f(()=>{"use strict"});function $t(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 m=192|(i&7)<<3|(s&192)>>6,l=128|s&63;return c(m.toString(16)+l.toString(16))}let g=224|(i&240)>>4,u=128|(i&15)<<2|(s&192)>>6,p=128|s&63;return c(g.toString(16)+u.toString(16)+p.toString(16))}let e=r.match(/.{4}/g);return e==null?"":e.map(t).join("")}var dt=f(()=>{"use strict";x()});var yt={};Ct(yt,{ArrayBuffertohex:()=>st,BAtohex:()=>U,BAtos:()=>F,VERSION:()=>vt,aryval:()=>Q,b64nltohex:()=>nt,b64tob64u:()=>d,b64tohex:()=>a,b64topem:()=>et,b64toutf8:()=>R,b64utob64:()=>y,b64utohex:()=>_,b64utoutf8:()=>G,binstrtobitstr:()=>q,bitstrtobinstr:()=>J,datetozulu:()=>gt,encodeURIComponentAll:()=>xt,foldnl:()=>w,hextoArrayBuffer:()=>it,hextob64:()=>h,hextob64u:()=>L,hextoip:()=>N,hextoipv6:()=>S,hextopem:()=>tt,hextorstr:()=>O,hextouricmp:()=>ht,hextoutf8:()=>c,inttobitstr:()=>D,ipnetmask:()=>B,ipprefixlen:()=>C,iptohex:()=>k,ipv6tohex:()=>A,iso88591hextoutf8:()=>W,msectozulu:()=>lt,namearraytobinstr:()=>K,pemtob64:()=>z,pemtohex:()=>rt,rstrtob64:()=>Y,rstrtohex:()=>P,stoBA:()=>T,stohex:()=>b,strpad:()=>M,timetogen:()=>j,ucs2hextoutf8:()=>$t,uricmptohex:()=>pt,utf8tob64:()=>Z,utf8tob64u:()=>V,utf8tohex:()=>$,utf8toiso88591hex:()=>X,zulutodate:()=>ct,zulutomsec:()=>I,zulutosec:()=>ft});var vt,wt=f(()=>{"use strict";v();x();H();ot();ut();at();mt();bt();dt();vt="typepki-strconv 0.1.0 kjur.github.io/typepki-strconv"});module.exports=(wt(),Et(yt));
1
+ "use strict";var E=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var Bt=Object.prototype.hasOwnProperty;var f=(r,t)=>()=>(r&&(t=r(r=0)),t);var Ct=(r,t)=>{for(var e in t)E(r,e,{get:t[e],enumerable:!0})},Et=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of St(t))!Bt.call(r,o)&&o!==e&&E(r,o,{get:()=>t[o],enumerable:!(n=At(t,o))||n.enumerable});return r};var Ut=r=>Et(E({},"__esModule",{value:!0}),r);function b(r){return U(T(r))}function U(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 F(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 R(r){let t="";for(let e=0;e<r.length;e++)t=t+String.fromCharCode(r[e]);return t}var v=f(()=>{"use strict"});function a(r){return Buffer.from(r,"base64").toString("hex")}function h(r){return Buffer.from(r,"hex").toString("base64")}function Z(r){return Buffer.from(r,"base64").toString("utf8")}function G(r){return Buffer.from(r,"utf8").toString("base64")}function V(r){return Buffer.from(y(r),"base64").toString("utf8")}function _(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 L(r){return a(y(r))}function O(r){return d(h(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 y(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 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 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 D(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+M("",e,"0");let n=parseInt(t,2).toString(16);return n.length%2===1&&(n=`0${n}`),`0${e}`+n}function Q(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 W(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 J,M,x=f(()=>{"use strict";J=r=>{if(r.match(/^[01]+$/)==null)return null;try{let t=parseInt(r,2);return D(t)}catch{return null}};M=(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 X(r){return c(Tt(r))}function H(r){return vt($(r))}function Tt(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 vt(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 tt=f(()=>{"use strict";x()});function rt(r,t,e=`\r
2
+ `){return`-----BEGIN ${t}-----${e}${w(h(r),64)}${e}-----END ${t}-----${e}`}function et(r,t){return a(z(r,t))}function z(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}${w(r,64,e)}${e}-----END ${t}-----${e}`}function ot(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 it=f(()=>{"use strict";x()});function st(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 ut(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 lt=f(()=>{"use strict"});function I(r){let t=r,e,n,o,i,s,g,u,p,m;t=j(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,o=parseInt(l[3]),i=parseInt(l[4]),s=parseInt(l[5]),g=parseInt(l[6]),u=0,p=l[7],p!==""&&(m=`${p.substr(1)}00`.substr(0,3),u=parseInt(m)),Date.UTC(e,n,o,i,s,g,u);throw new Error(`unsupported zulu format: ${t}`)}function ft(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 ct(r){return Math.round(I(r)/1e3)}function gt(r){return new Date(I(r))}function at(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 j(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 pt=f(()=>{"use strict"});function ht(r){return r.replace(/%/g,"")}function xt(r){return r.replace(/(..)/g,"%$1")}function mt(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}%${b(t[n])}`;return e}var bt=f(()=>{"use strict";v()});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 S(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 N(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`${N(r.substr(0,8))}/${B(r.substr(8))}`}catch{throw t}else{if(r.length===32)return S(r);if(r.length===64)try{return`${S(r.substr(0,32))}/${B(r.substr(32))}`}catch{throw t}else return r}}function k(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 k(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 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)}var $t=f(()=>{"use strict"});function dt(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 m=192|(i&7)<<3|(s&192)>>6,l=128|s&63;return c(m.toString(16)+l.toString(16))}let g=224|(i&240)>>4,u=128|(i&15)<<2|(s&192)>>6,p=128|s&63;return c(g.toString(16)+u.toString(16)+p.toString(16))}let e=r.match(/.{4}/g);return e==null?"":e.map(t).join("")}var yt=f(()=>{"use strict";x()});var wt={};Ct(wt,{ArrayBuffertohex:()=>ut,BAtohex:()=>U,BAtos:()=>R,VERSION:()=>Dt,aryval:()=>W,b64nltohex:()=>ot,b64tob64u:()=>d,b64tohex:()=>a,b64topem:()=>nt,b64toutf8:()=>Z,b64utob64:()=>y,b64utohex:()=>L,b64utoutf8:()=>V,binstrtobitstr:()=>J,bitstrtobinstr:()=>K,datetozulu:()=>at,encodeURIComponentAll:()=>mt,foldnl:()=>w,hextoArrayBuffer:()=>st,hextoBA:()=>F,hextob64:()=>h,hextob64u:()=>O,hextoip:()=>N,hextoipv6:()=>S,hextopem:()=>rt,hextorstr:()=>P,hextouricmp:()=>xt,hextoutf8:()=>c,inttobitstr:()=>D,ipnetmask:()=>C,ipprefixlen:()=>B,iptohex:()=>k,ipv6tohex:()=>A,iso88591hextoutf8:()=>X,msectozulu:()=>ft,namearraytobinstr:()=>Q,pemtob64:()=>z,pemtohex:()=>et,rstrtob64:()=>q,rstrtohex:()=>Y,stoBA:()=>T,stohex:()=>b,strpad:()=>M,timetogen:()=>j,ucs2hextoutf8:()=>dt,uricmptohex:()=>ht,utf8tob64:()=>G,utf8tob64u:()=>_,utf8tohex:()=>$,utf8toiso88591hex:()=>H,zulutodate:()=>gt,zulutomsec:()=>I,zulutosec:()=>ct});var Dt,It=f(()=>{"use strict";v();x();tt();it();lt();pt();bt();$t();yt();Dt="typepki-strconv 0.2.0 kjur.github.io/typepki-strconv"});module.exports=(It(),Ut(wt));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typepki-strconv",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "Kenji Urushima <kenji.urushima@gmail.com>",
5
5
  "description": "TypeScript string converters and utilities sub module for TypePKI library (beta)",
6
6
  "homepage": "https://kjur.github.io/typepki-strconv",
package/src/conv_ba.mts CHANGED
@@ -11,8 +11,11 @@ export function stohex(s: string): string {
11
11
 
12
12
  /**
13
13
  * convert an array of bytes(Number) to hexadecimal string.
14
- * @param a - a array of bytes
14
+ * @param a - an array of byte
15
15
  * @return hexadecimal string
16
+ * @see {@link hextoBA}
17
+ * @example
18
+ * hextoBA([97, 97, 97]) -> "616161"
16
19
  */
17
20
  export function BAtohex(a: Array<number>): string {
18
21
  let s = "";
@@ -24,6 +27,22 @@ export function BAtohex(a: Array<number>): string {
24
27
  return s;
25
28
  }
26
29
 
30
+ /**
31
+ * convert an hexadecimal string to array of numbers.
32
+ * @param h - a hexadecimal string
33
+ * @return array of numbers
34
+ * @see {@link BAtohex}
35
+ * @example
36
+ * hextoBA("616161") -> [97, 97, 97]
37
+ */
38
+ export function hextoBA(h: string): Array<number> {
39
+ const a: Array<number> = [];
40
+ for (let i = 0; i < h.length; i += 2) {
41
+ a.push(parseInt(h.slice(i, i + 2), 16));
42
+ }
43
+ return a;
44
+ }
45
+
27
46
  // ==== string / byte array ================================
28
47
  /**
29
48
  * convert a string to an array of character codes
@@ -0,0 +1,10 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { BAtohex, hextoBA } from "./conv_ba.mts";
3
+
4
+ test("BAtohex", () => {
5
+ expect(BAtohex([97, 97, 97])).toBe("616161");
6
+ });
7
+
8
+ test("hextoBA", () => {
9
+ expect(hextoBA("616161")).toEqual([97, 97, 97]);
10
+ });
package/src/index.mts CHANGED
@@ -1,8 +1,8 @@
1
- const VERSION: string = "typepki-strconv 0.1.0 kjur.github.io/typepki-strconv";
1
+ const VERSION: string = "typepki-strconv 0.2.0 kjur.github.io/typepki-strconv";
2
2
  export { VERSION };
3
3
 
4
- import { BAtohex, BAtos, stoBA, stohex } from "./conv_ba.mts";
5
- export { stohex, BAtohex, stoBA, BAtos };
4
+ import { BAtohex, BAtos, hextoBA, stoBA, stohex } from "./conv_ba.mts";
5
+ export { stohex, BAtohex, hextoBA, stoBA, BAtos };
6
6
 
7
7
  import {
8
8
  Dictionary,