From 741b5987ad875900bd4c17f7c36dfee62c7f82d9 Mon Sep 17 00:00:00 2001 From: Kenji Urushima Date: Thu, 10 Mar 2022 08:33:32 +0900 Subject: [PATCH] 10.5.9 release --- ChangeLog.txt | 7 +- Makefile | 14 +- api/files.html | 4 +- api/symbols/src/asn1-1.0.js.html | 2 +- api/symbols/src/asn1cades-1.0.js.html | 2 +- api/symbols/src/asn1cms-1.0.js.html | 2 +- api/symbols/src/asn1csr-1.0.js.html | 10 +- api/symbols/src/asn1hex-1.1.js.html | 2 +- api/symbols/src/asn1ocsp-1.0.js.html | 2 +- api/symbols/src/asn1tsp-1.0.js.html | 2 +- api/symbols/src/asn1x509-1.0.js.html | 2 +- api/symbols/src/base64x-1.1.js.html | 2011 ++++++++++---------- api/symbols/src/crypto-1.1.js.html | 2 +- api/symbols/src/dsa-2.0.js.html | 2 +- api/symbols/src/ecdsa-modified-1.0.js.html | 2 +- api/symbols/src/ecparam-1.0.js.html | 2 +- api/symbols/src/jws-3.3.js.html | 2 +- api/symbols/src/jwsjs-2.0.js.html | 2 +- api/symbols/src/keyutil-1.0.js.html | 2 +- api/symbols/src/nodeutil-1.0.js.html | 2 +- api/symbols/src/rsapem-1.1.js.html | 2 +- api/symbols/src/rsasign-1.2.js.html | 2 +- api/symbols/src/x509-1.1.js.html | 2 +- api/symbols/src/x509crl.js.html | 2 +- bower.json | 2 +- jsrsasign-all-min.js | 6 +- jsrsasign-jwths-min.js | 4 +- jsrsasign-rsa-min.js | 4 +- min/asn1csr-1.0.min.js | 2 +- min/base64x-1.1.min.js | 2 +- npm/lib/jsrsasign-all-min.js | 6 +- npm/lib/jsrsasign-jwths-min.js | 4 +- npm/lib/jsrsasign-rsa-min.js | 4 +- npm/lib/jsrsasign.js | 6 +- npm/package.json | 2 +- src/base64x-1.1.js | 9 +- test/qunit-do-base64x.html | 2 + 37 files changed, 1077 insertions(+), 1060 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 55cc4fd2..79e64b16 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,9 +1,14 @@ ChangeLog for jsrsasign -* Changes from 10.5.8 to next version +small fix +* Changes from 10.5.8 to 10.5.9 version + - src/base64x.js + - fix zulutosec (#538) - src/asn1csr.js - fix CSRUtil.getParam (#544) + - test/qunit-do-{base64x,asn1csr}.html + - test case update for above updates. OCSP CertID and X509 class update * Changes from 10.5.7 to 10.5.8 (2022-Feb-25) diff --git a/Makefile b/Makefile index 2b3ce5f7..893473fe 100644 --- a/Makefile +++ b/Makefile @@ -91,4 +91,16 @@ gitadd-release: git add ChangeLog.txt Makefile bower.json jsrsasign-*-min.js min/*.js src/*.js npm/package.json npm/lib/jsrsasign*.js npm/lib/{header,footer,lib}.js src/*.js test/qunit-do-*.html test/x509crl.html README.md npm/README.md tool/*.html npm_util/*.* npm_util/lib/*.* npm/test/t_*.js gitadd: gitadd-all-doc gitadd-release - @echo done \ No newline at end of file + @echo done + +rsync-test: + rsync -n -av --include="[a-z]*.js" --exclude="*" src/ ../../_gitpg/jsrsasign/src + rsync -n -av --include="[a-z]*.min.js" --exclude="*" min/ ../../_gitpg/jsrsasign/min + rsync -n -av --include="[a-z]*.html" --exclude="*" test/ ../../_gitpg/jsrsasign/test + +rsync: + rsync -av --include="[a-z]*.js" --exclude="*" src/ ../../_gitpg/jsrsasign/src + rsync -av --include="[a-z]*.min.js" --exclude="*" min/ ../../_gitpg/jsrsasign/min + rsync -av --include="[a-z]*.html" --exclude="*" test/ ../../_gitpg/jsrsasign/test + + diff --git a/api/files.html b/api/files.html index ebdf3c3c..c31e6dd2 100644 --- a/api/files.html +++ b/api/files.html @@ -582,7 +582,7 @@

asn1csr-1.0.js

Version:
-
jsrsasign 10.1.0 asn1csr 2.0.3 (2020-Nov-18)
+
jsrsasign 10.1.0 asn1csr 2.0.4 (2022-Mar-08)
@@ -677,7 +677,7 @@

base64x-1.1.js

Version:
-
jsrsasign 10.5.4 base64x 1.1.21 (2022-Feb-14)
+
jsrsasign 10.5.9 base64x 1.1.22 (2022-Mar-10)
diff --git a/api/symbols/src/asn1-1.0.js.html b/api/symbols/src/asn1-1.0.js.html index 0256dd45..ae74c0f5 100644 --- a/api/symbols/src/asn1-1.0.js.html +++ b/api/symbols/src/asn1-1.0.js.html @@ -1840,4 +1840,4 @@ 1833 if (params !== undefined) this.setByParam(params); 1834 }; 1835 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); -1836 \ No newline at end of file +1836 diff --git a/api/symbols/src/asn1cades-1.0.js.html b/api/symbols/src/asn1cades-1.0.js.html index 077a6a84..43ac5474 100644 --- a/api/symbols/src/asn1cades-1.0.js.html +++ b/api/symbols/src/asn1cades-1.0.js.html @@ -950,4 +950,4 @@ 943 return r; 944 }; 945 -946 \ No newline at end of file +946 diff --git a/api/symbols/src/asn1cms-1.0.js.html b/api/symbols/src/asn1cms-1.0.js.html index 1569f0ee..857940ef 100644 --- a/api/symbols/src/asn1cms-1.0.js.html +++ b/api/symbols/src/asn1cms-1.0.js.html @@ -3257,4 +3257,4 @@ 3250 return {array: a, sortflag: false}; 3251 }; 3252 }; -3253 \ No newline at end of file +3253 diff --git a/api/symbols/src/asn1csr-1.0.js.html b/api/symbols/src/asn1csr-1.0.js.html index 603b9df8..d265a389 100644 --- a/api/symbols/src/asn1csr-1.0.js.html +++ b/api/symbols/src/asn1csr-1.0.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
  1 /* asn1csr-2.0.3.js (c) 2015-2020 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* asn1csr-2.0.4.js (c) 2015-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
   2  */
   3 /*
   4  * asn1csr.js - ASN.1 DER encoder classes for PKCS#10 CSR
@@ -23,7 +23,7 @@
  16  * @fileOverview
  17  * @name asn1csr-1.0.js
  18  * @author Kenji Urushima kenji.urushima@gmail.com
- 19  * @version jsrsasign 10.1.0 asn1csr 2.0.3 (2020-Nov-18)
+ 19  * @version jsrsasign 10.1.0 asn1csr 2.0.4 (2022-Mar-08)
  20  * @since jsrsasign 4.9.0
  21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  22  */
@@ -426,8 +426,8 @@
 419  */
 420 KJUR.asn1.csr.CSRUtil.getParam = function(sPEM) {
 421     var _ASN1HEX = ASN1HEX,
-422 	_getV = _ASN1HEX.getV;
-423 	_getIdxbyList = _ASN1HEX.getIdxbyList;
+422 	_getV = _ASN1HEX.getV,
+423 	_getIdxbyList = _ASN1HEX.getIdxbyList,
 424 	_getTLVbyList = _ASN1HEX.getTLVbyList,
 425 	_getTLVbyListEx = _ASN1HEX.getTLVbyListEx,
 426 	_getVbyListEx = _ASN1HEX.getVbyListEx;
@@ -488,4 +488,4 @@
 481 };
 482 
 483 
-484 
\ No newline at end of file +484
diff --git a/api/symbols/src/asn1hex-1.1.js.html b/api/symbols/src/asn1hex-1.1.js.html index 5723b22b..49617196 100644 --- a/api/symbols/src/asn1hex-1.1.js.html +++ b/api/symbols/src/asn1hex-1.1.js.html @@ -1354,4 +1354,4 @@ 1347 return name; 1348 }; 1349 -1350 \ No newline at end of file +1350 diff --git a/api/symbols/src/asn1ocsp-1.0.js.html b/api/symbols/src/asn1ocsp-1.0.js.html index 433d698c..307f505e 100644 --- a/api/symbols/src/asn1ocsp-1.0.js.html +++ b/api/symbols/src/asn1ocsp-1.0.js.html @@ -2076,4 +2076,4 @@ 2069 }; 2070 }; 2071 -2072 \ No newline at end of file +2072 diff --git a/api/symbols/src/asn1tsp-1.0.js.html b/api/symbols/src/asn1tsp-1.0.js.html index 0095c7e5..06d3a775 100644 --- a/api/symbols/src/asn1tsp-1.0.js.html +++ b/api/symbols/src/asn1tsp-1.0.js.html @@ -1475,4 +1475,4 @@ 1468 } 1469 }; 1470 }; -1471 \ No newline at end of file +1471 diff --git a/api/symbols/src/asn1x509-1.0.js.html b/api/symbols/src/asn1x509-1.0.js.html index 4fa4e124..b7e73dcd 100644 --- a/api/symbols/src/asn1x509-1.0.js.html +++ b/api/symbols/src/asn1x509-1.0.js.html @@ -4720,4 +4720,4 @@ 4713 return cert.getPEM(); 4714 }; 4715 -4716 \ No newline at end of file +4716 diff --git a/api/symbols/src/base64x-1.1.js.html b/api/symbols/src/base64x-1.1.js.html index d7b1c71d..72b62edd 100644 --- a/api/symbols/src/base64x-1.1.js.html +++ b/api/symbols/src/base64x-1.1.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
  1 /* base64x-1.1.21 (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* base64x-1.1.22 (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
   2  */
   3 /*
   4  * base64x.js - Base64url and supplementary functions for Tom Wu's base64.js library
@@ -23,7 +23,7 @@
  16  * @fileOverview
  17  * @name base64x-1.1.js
  18  * @author Kenji Urushima kenji.urushima@gmail.com
- 19  * @version jsrsasign 10.5.4 base64x 1.1.21 (2022-Feb-14)
+ 19  * @version jsrsasign 10.5.9 base64x 1.1.22 (2022-Mar-10)
  20  * @since jsrsasign 2.1
  21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  22  */
@@ -631,7 +631,7 @@
 624 	}
 625 	return Date.UTC(year, month, day, hour, min, sec, msec);
 626     }
-627     throw "unsupported zulu format: " + s;
+627     throw new Error("unsupported zulu format: " + s);
 628 }
 629 
 630 /**
@@ -654,1006 +654,1005 @@
 647  * zulutosec("20071231235959Z")       → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
 648  */
 649 function zulutosec(s) {
-650     var msec = zulutomsec(s);
-651     return ~~(msec / 1000);
-652 }
-653 
-654 // ==== zulu / Date =================================
-655 
-656 /**
-657  * GeneralizedTime or UTCTime string to Date object<br>
-658  * @name zulutodate
-659  * @function
-660  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
-661  * @return {Date} Date object for specified time
-662  * @since jsrsasign 7.1.3 base64x 1.1.9
-663  * @description
-664  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
-665  * UTCTime string (i.e. YYMMDDHHmmSSZ) to Date object.
-666  * Argument string may have fraction of seconds and
-667  * its length is one or more digits such as "20170410235959.1234567Z".
-668  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
-669  * If year "YY" is equal or greater than 50 then it is 19YY.
-670  * @example
-671  * zulutodate(  "071231235959Z").toUTCString()   → "Mon, 31 Dec 2007 23:59:59 GMT"
-672  * zulutodate(  "071231235959.1Z").toUTCString() → "Mon, 31 Dec 2007 23:59:59 GMT"
-673  * zulutodate("20071231235959Z").toUTCString()   → "Mon, 31 Dec 2007 23:59:59 GMT"
-674  * zulutodate(  "071231235959.34").getMilliseconds() → 340
-675  */
-676 function zulutodate(s) {
-677     return new Date(zulutomsec(s));
-678 }
-679 
-680 // ==== Date / zulu =================================
-681 
-682 /**
-683  * Date object to zulu time string<br>
-684  * @name datetozulu
-685  * @function
-686  * @param {Date} d Date object for specified time
-687  * @param {Boolean} flagUTCTime if this is true year will be YY otherwise YYYY
-688  * @param {Boolean} flagMilli if this is true result concludes milliseconds
-689  * @return {String} GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
-690  * @since jsrsasign 7.2.0 base64x 1.1.11
-691  * @description
-692  * This function converts from Date object to GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
-693  * UTCTime string (i.e. YYMMDDHHmmSSZ).
-694  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
-695  * If year "YY" is equal or greater than 50 then it is 19YY.
-696  * If flagMilli is true its result concludes milliseconds such like
-697  * "20170520235959.42Z". 
-698  * @example
-699  * d = new Date(Date.UTC(2017,4,20,23,59,59,670));
-700  * datetozulu(d) → "20170520235959Z"
-701  * datetozulu(d, true) → "170520235959Z"
-702  * datetozulu(d, false, true) → "20170520235959.67Z"
-703  */
-704 function datetozulu(d, flagUTCTime, flagMilli) {
-705     var s;
-706     var year = d.getUTCFullYear();
-707     if (flagUTCTime) {
-708 	if (year < 1950 || 2049 < year) 
-709 	    throw "not proper year for UTCTime: " + year;
-710 	s = ("" + year).slice(-2);
-711     } else {
-712 	s = ("000" + year).slice(-4);
-713     }
-714     s += ("0" + (d.getUTCMonth() + 1)).slice(-2);
-715     s += ("0" + d.getUTCDate()).slice(-2);
-716     s += ("0" + d.getUTCHours()).slice(-2);
-717     s += ("0" + d.getUTCMinutes()).slice(-2);
-718     s += ("0" + d.getUTCSeconds()).slice(-2);
-719     if (flagMilli) {
-720 	var milli = d.getUTCMilliseconds();
-721 	if (milli !== 0) {
-722 	    milli = ("00" + milli).slice(-3);
-723 	    milli = milli.replace(/0+$/g, "");
-724 	    s += "." + milli;
-725 	}
-726     }
-727     s += "Z";
-728     return s;
-729 }
-730 
-731 // ==== URIComponent / hex ================================
-732 /**
-733  * convert a URLComponent string such like "%67%68" to a hexadecimal string.<br/>
-734  * @name uricmptohex
-735  * @function
-736  * @param {String} s URIComponent string such like "%67%68"
-737  * @return {String} hexadecimal string
-738  * @since 1.1
-739  */
-740 function uricmptohex(s) {
-741   return s.replace(/%/g, "");
-742 }
-743 
-744 /**
-745  * convert a hexadecimal string to a URLComponent string such like "%67%68".<br/>
-746  * @name hextouricmp
-747  * @function
-748  * @param {String} s hexadecimal string
-749  * @return {String} URIComponent string such like "%67%68"
-750  * @since 1.1
-751  */
-752 function hextouricmp(s) {
-753   return s.replace(/(..)/g, "%$1");
-754 }
-755 
-756 // ==== hex / ipv6 =================================
-757 
-758 /**
-759  * convert any IPv6 address to a 16 byte hexadecimal string
-760  * @function
-761  * @param s string of IPv6 address
-762  * @return {String} 16 byte hexadecimal string of IPv6 address
-763  * @description
-764  * This function converts any IPv6 address representation string
-765  * to a 16 byte hexadecimal string of address.
-766  * @example
-767  * 
-768  */
-769 function ipv6tohex(s) {
-770   var msgMalformedAddress = "malformed IPv6 address";
-771   if (! s.match(/^[0-9A-Fa-f:]+$/))
-772     throw msgMalformedAddress;
-773 
-774   // 1. downcase
-775   s = s.toLowerCase();
-776 
-777   // 2. expand ::
-778   var num_colon = s.split(':').length - 1;
-779   if (num_colon < 2) throw msgMalformedAddress;
-780   var colon_replacer = ':'.repeat(7 - num_colon + 2);
-781   s = s.replace('::', colon_replacer);
-782 
-783   // 3. fill zero
-784   var a = s.split(':');
-785   if (a.length != 8) throw msgMalformedAddress;
-786   for (var i = 0; i < 8; i++) {
-787     a[i] = ("0000" + a[i]).slice(-4);
-788   }
-789   return a.join('');
-790 }
-791 
-792 /**
-793  * convert a 16 byte hexadecimal string to RFC 5952 canonicalized IPv6 address<br/>
-794  * @name hextoipv6
-795  * @function
-796  * @param {String} s hexadecimal string of 16 byte IPv6 address
-797  * @return {String} IPv6 address string canonicalized by RFC 5952
-798  * @since jsrsasign 8.0.10 base64x 1.1.13
-799  * @description
-800  * This function converts a 16 byte hexadecimal string to 
-801  * <a href="https://tools.ietf.org/html/rfc5952">RFC 5952</a>
-802  * canonicalized IPv6 address string.
-803  * @example
-804  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
-805  * hextoip("871020010db8000000000000000000") &rarr raise exception
-806  * hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception
-807  */
-808 function hextoipv6(s) {
-809   if (! s.match(/^[0-9A-Fa-f]{32}$/))
-810     throw "malformed IPv6 address octet";
-811 
-812   // 1. downcase
-813   s = s.toLowerCase();
-814 
-815   // 2. split 4
-816   var a = s.match(/.{1,4}/g);
-817 
-818   // 3. trim leading 0
-819   for (var i = 0; i < 8; i++) {
-820     a[i] = a[i].replace(/^0+/, "");
-821     if (a[i] == '') a[i] = '0';
-822   }
-823   s = ":" + a.join(":") + ":";
-824 
-825   // 4. find shrinkables :0:0:...
-826   var aZero = s.match(/:(0:){2,}/g);
-827 
-828   // 5. no shrinkable
-829   if (aZero === null) return s.slice(1, -1);
-830 
-831   // 6. find max length :0:0:...
-832   var item = '';
-833   for (var i = 0; i < aZero.length; i++) {
-834     if (aZero[i].length > item.length) item = aZero[i];
-835   }
-836 
-837   // 7. shrink
-838   s = s.replace(item, '::');
-839   return s.slice(1, -1);
-840 }
-841 
-842 // ==== hex / ip =================================
-843 
-844 /**
-845  * convert a hexadecimal string to IP addresss<br/>
-846  * @name hextoip
-847  * @function
-848  * @param {String} s hexadecimal string of IP address
-849  * @return {String} IP address string
-850  * @since jsrsasign 8.0.10 base64x 1.1.13
-851  * @description
-852  * This function converts a hexadecimal string of IPv4 or 
-853  * IPv6 address to IPv4 or IPv6 address string.
-854  * If byte length is not 4 nor 16, this returns a
-855  * hexadecimal string without conversion.
-856  * @see {@link hextoipv6}
-857  * @example
-858  * hextoip("c0a80101") &rarr "192.168.1.1"
-859  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
-860  * hextoip("c0a801010203") &rarr "c0a801010203" // 6 bytes
-861  * hextoip("zzz")) &rarr raise exception because of not hexadecimal
-862  */
-863 function hextoip(s) {
-864   var malformedMsg = "malformed hex value";
-865   if (! s.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))
-866     throw malformedMsg;
-867   if (s.length == 8) { // ipv4
-868     var ip;
-869     try {
-870       ip = parseInt(s.substr(0, 2), 16) + "." +
-871            parseInt(s.substr(2, 2), 16) + "." +
-872            parseInt(s.substr(4, 2), 16) + "." +
-873            parseInt(s.substr(6, 2), 16);
-874       return ip;
-875     } catch (ex) {
-876       throw malformedMsg;
-877     }
-878   } else if (s.length == 32) {
-879     return hextoipv6(s);
-880   } else {
-881     return s;
-882   }
-883 }
-884 
-885 /**
-886  * convert IPv4/v6 addresss to a hexadecimal string<br/>
-887  * @name iptohex
-888  * @function
-889  * @param {String} s IPv4/v6 address string
-890  * @return {String} hexadecimal string of IP address
-891  * @since jsrsasign 8.0.12 base64x 1.1.14
-892  * @description
-893  * This function converts IPv4 or IPv6 address string to
-894  * a hexadecimal string of IPv4 or IPv6 address.
-895  * @example
-896  * iptohex("192.168.1.1") &rarr "c0a80101"
-897  * iptohex("2001:db8::4") &rarr "871020010db8000000000000000000000004"
-898  * iptohex("zzz")) &rarr raise exception
-899  */
-900 function iptohex(s) {
-901   var malformedMsg = "malformed IP address";
-902   s = s.toLowerCase(s);
-903 
-904   if (s.match(/^[0-9.]+$/)) {
-905     var a = s.split(".");
-906     if (a.length !== 4) throw malformedMsg;
-907     var hex = "";
-908     try {
-909       for (var i = 0; i < 4; i++) {
-910         var d = parseInt(a[i]);
-911         hex += ("0" + d.toString(16)).slice(-2);
-912       }
-913       return hex;
-914     } catch(ex) {
-915       throw malformedMsg;
-916     }
-917   } else if (s.match(/^[0-9a-f:]+$/) && s.indexOf(":") !== -1) {
-918     return ipv6tohex(s);
-919   } else {
-920     throw malformedMsg;
-921   }
-922 }
-923 
-924 // ==== ucs2hex / utf8 ==============================
-925 
-926 /**
-927  * convert UCS-2 hexadecimal stirng to UTF-8 string<br/>
-928  * @name ucs2hextoutf8
-929  * @function
-930  * @param {String} s hexadecimal string of UCS-2 string (ex. "0066")
-931  * @return {String} UTF-8 string
-932  * @since jsrsasign 10.1.13 base64x 1.1.20
-933  * @description
-934  * This function converts hexadecimal value of UCS-2 string to 
-935  * UTF-8 string.
-936  * @example
-937  * ucs2hextoutf8("006600fc0072") &rarr "für"
-938  */
-939 /*
-940 See: http://nomenclator.la.coocan.jp/unicode/ucs_utf.htm
-941 UCS-2 to UTF-8
-942 UCS-2 code point | UCS-2 bytes       | UTF-8 bytes
-943 U+0000 .. U+007F | 00000000-0xxxxxxx | 0xxxxxxx (1 byte)
-944 U+0080 .. U+07FF | 00000xxx-xxyyyyyy | 110xxxxx 10yyyyyy (2 byte)
-945 U+0800 .. U+FFFF | xxxxyyyy-yyzzzzzz | 1110xxxx 10yyyyyy 10zzzzzz (3 byte)
-946  */
-947 function ucs2hextoutf8(s) {
-948     function _conv(s) {
-949 	var i1 = parseInt(s.substr(0, 2), 16);
-950 	var i2 = parseInt(s.substr(2), 16);
-951 	if (i1 == 0 & i2 < 0x80) { // 1 byte
-952 	    return String.fromCharCode(i2);
-953 	}
-954 	if (i1 < 8) { // 2 bytes
-955 	    var u1 = 0xc0 | ((i1 & 0x07) << 3) | ((i2 & 0xc0) >> 6);
-956 	    var u2 = 0x80 | (i2 & 0x3f);
-957 	    return hextoutf8(u1.toString(16) + u2.toString(16));
-958 	}
-959 	// 3 bytes
-960 	var u1 = 0xe0 | ((i1 & 0xf0) >> 4);
-961 	var u2 = 0x80 | ((i1 & 0x0f) << 2) | ((i2 & 0xc0) >> 6);
-962 	var u3 = 0x80 | (i2 & 0x3f);
-963 	return hextoutf8(u1.toString(16) + u2.toString(16) + u3.toString(16));
-964     }
-965     var a = s.match(/.{4}/g);
-966     var a2 = a.map(_conv);
-967     return a2.join("");
-968 }
-969 
-970 // ==== URIComponent ================================
-971 /**
-972  * convert UTFa hexadecimal string to a URLComponent string such like "%67%68".<br/>
-973  * Note that these "<code>0-9A-Za-z!'()*-._~</code>" characters will not
-974  * converted to "%xx" format by builtin 'encodeURIComponent()' function.
-975  * However this 'encodeURIComponentAll()' function will convert 
-976  * all of characters into "%xx" format.
-977  * @name encodeURIComponentAll
-978  * @function
-979  * @param {String} s hexadecimal string
-980  * @return {String} URIComponent string such like "%67%68"
-981  * @since 1.1
-982  */
-983 function encodeURIComponentAll(u8) {
-984   var s = encodeURIComponent(u8);
-985   var s2 = "";
-986   for (var i = 0; i < s.length; i++) {
-987     if (s[i] == "%") {
-988       s2 = s2 + s.substr(i, 3);
-989       i = i + 2;
-990     } else {
-991       s2 = s2 + "%" + stohex(s[i]);
-992     }
-993   }
-994   return s2;
-995 }
-996 
-997 // ==== new lines ================================
-998 /**
-999  * convert all DOS new line("\r\n") to UNIX new line("\n") in 
-1000  * a String "s".
-1001  * @name newline_toUnix
-1002  * @function
-1003  * @param {String} s string 
-1004  * @return {String} converted string
-1005  */
-1006 function newline_toUnix(s) {
-1007     s = s.replace(/\r\n/mg, "\n");
-1008     return s;
-1009 }
-1010 
-1011 /**
-1012  * convert all UNIX new line("\r\n") to DOS new line("\n") in 
-1013  * a String "s".
-1014  * @name newline_toDos
-1015  * @function
-1016  * @param {String} s string 
-1017  * @return {String} converted string
-1018  */
-1019 function newline_toDos(s) {
-1020     s = s.replace(/\r\n/mg, "\n");
-1021     s = s.replace(/\n/mg, "\r\n");
-1022     return s;
-1023 }
-1024 
-1025 // ==== string type checker ===================
-1026 
-1027 /**
-1028  * check whether a string is an integer string or not<br/>
-1029  * @name isInteger
-1030  * @memberOf KJUR.lang.String
-1031  * @function
-1032  * @static
-1033  * @param {String} s input string
-1034  * @return {Boolean} true if a string "s" is an integer string otherwise false
-1035  * @since base64x 1.1.7 jsrsasign 5.0.13
-1036  * @example
-1037  * KJUR.lang.String.isInteger("12345") → true
-1038  * KJUR.lang.String.isInteger("123ab") → false
-1039  */
-1040 KJUR.lang.String.isInteger = function(s) {
-1041     if (s.match(/^[0-9]+$/)) {
-1042 	return true;
-1043     } else if (s.match(/^-[0-9]+$/)) {
-1044 	return true;
-1045     } else {
-1046 	return false;
-1047     }
-1048 };
-1049 
-1050 /**
-1051  * check whether a string is an hexadecimal string or not (DEPRECATED)<br/>
-1052  * @name isHex
-1053  * @memberOf KJUR.lang.String
-1054  * @function
-1055  * @static
-1056  * @param {String} s input string
-1057  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
-1058  * @since base64x 1.1.7 jsrsasign 5.0.13
-1059  * @deprecated from 10.0.6. please use {@link ishex}
-1060  * @see ishex
-1061  * @example
-1062  * KJUR.lang.String.isHex("1234") → true
-1063  * KJUR.lang.String.isHex("12ab") → true
-1064  * KJUR.lang.String.isHex("12AB") → true
-1065  * KJUR.lang.String.isHex("12ZY") → false
-1066  * KJUR.lang.String.isHex("121") → false -- odd length
-1067  */
-1068 KJUR.lang.String.isHex = function(s) {
-1069     return ishex(s);
-1070 };
-1071 
-1072 /**
-1073  * check whether a string is an hexadecimal string or not<br/>
-1074  * @name ishex
-1075  * @function
-1076  * @static
-1077  * @param {String} s input string
-1078  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
-1079  * @since base64x 1.1.7 jsrsasign 5.0.13
-1080  * @example
-1081  * ishex("1234") → true
-1082  * ishex("12ab") → true
-1083  * ishex("12AB") → true
-1084  * ishex("12ZY") → false
-1085  * ishex("121") → false -- odd length
-1086  */
-1087 function ishex(s) {
-1088     if (s.length % 2 == 0 &&
-1089 	(s.match(/^[0-9a-f]+$/) || s.match(/^[0-9A-F]+$/))) {
-1090 	return true;
-1091     } else {
-1092 	return false;
-1093     }
-1094 };
-1095 
-1096 /**
-1097  * check whether a string is a base64 encoded string or not<br/>
-1098  * Input string can conclude new lines or space characters.
-1099  * @name isBase64
-1100  * @memberOf KJUR.lang.String
-1101  * @function
-1102  * @static
-1103  * @param {String} s input string
-1104  * @return {Boolean} true if a string "s" is a base64 encoded string otherwise false
-1105  * @since base64x 1.1.7 jsrsasign 5.0.13
-1106  * @example
-1107  * KJUR.lang.String.isBase64("YWE=") → true
-1108  * KJUR.lang.String.isBase64("YW_=") → false
-1109  * KJUR.lang.String.isBase64("YWE") → false -- length shall be multiples of 4
-1110  */
-1111 KJUR.lang.String.isBase64 = function(s) {
-1112     s = s.replace(/\s+/g, "");
-1113     if (s.match(/^[0-9A-Za-z+\/]+={0,3}$/) && s.length % 4 == 0) {
-1114 	return true;
-1115     } else {
-1116 	return false;
-1117     }
-1118 };
-1119 
-1120 /**
-1121  * check whether a string is a base64url encoded string or not<br/>
-1122  * Input string can conclude new lines or space characters.
-1123  * @name isBase64URL
-1124  * @memberOf KJUR.lang.String
-1125  * @function
-1126  * @static
-1127  * @param {String} s input string
-1128  * @return {Boolean} true if a string "s" is a base64url encoded string otherwise false
-1129  * @since base64x 1.1.7 jsrsasign 5.0.13
-1130  * @example
-1131  * KJUR.lang.String.isBase64URL("YWE") → true
-1132  * KJUR.lang.String.isBase64URL("YW-") → true
-1133  * KJUR.lang.String.isBase64URL("YW+") → false
-1134  */
-1135 KJUR.lang.String.isBase64URL = function(s) {
-1136     if (s.match(/[+/=]/)) return false;
-1137     s = b64utob64(s);
-1138     return KJUR.lang.String.isBase64(s);
-1139 };
-1140 
-1141 /**
-1142  * check whether a string is a string of integer array or not<br/>
-1143  * Input string can conclude new lines or space characters.
-1144  * @name isIntegerArray
-1145  * @memberOf KJUR.lang.String
-1146  * @function
-1147  * @static
-1148  * @param {String} s input string
-1149  * @return {Boolean} true if a string "s" is a string of integer array otherwise false
-1150  * @since base64x 1.1.7 jsrsasign 5.0.13
-1151  * @example
-1152  * KJUR.lang.String.isIntegerArray("[1,2,3]") → true
-1153  * KJUR.lang.String.isIntegerArray("  [1, 2, 3  ] ") → true
-1154  * KJUR.lang.String.isIntegerArray("[a,2]") → false
-1155  */
-1156 KJUR.lang.String.isIntegerArray = function(s) {
-1157     s = s.replace(/\s+/g, "");
-1158     if (s.match(/^\[[0-9,]+\]$/)) {
-1159 	return true;
-1160     } else {
-1161 	return false;
-1162     }
-1163 };
-1164 
-1165 /**
-1166  * check whether a string consists of PrintableString characters<br/>
-1167  * @name isPrintable
-1168  * @memberOf KJUR.lang.String
-1169  * @function
-1170  * @static
-1171  * @param {String} s input string
-1172  * @return {Boolean} true if a string "s" consists of PrintableString characters
-1173  * @since jsrsasign 9.0.0 base64x 1.1.16
-1174  * A PrintableString consists of following characters
-1175  * <pre>
-1176  * 0-9A-Za-z '()+,-./:=?
-1177  * </pre>
-1178  * This method returns false when other characters than above.
-1179  * Otherwise it returns true.
-1180  * @example
-1181  * KJUR.lang.String.isPrintable("abc") → true
-1182  * KJUR.lang.String.isPrintable("abc@") → false
-1183  * KJUR.lang.String.isPrintable("あいう") → false
-1184  */
-1185 KJUR.lang.String.isPrintable = function(s) {
-1186     if (s.match(/^[0-9A-Za-z '()+,-./:=?]*$/) !== null) return true;
-1187     return false;
-1188 };
-1189 
-1190 /**
-1191  * check whether a string consists of IAString characters<br/>
-1192  * @name isIA5
-1193  * @memberOf KJUR.lang.String
-1194  * @function
-1195  * @static
-1196  * @param {String} s input string
-1197  * @return {Boolean} true if a string "s" consists of IA5String characters
-1198  * @since jsrsasign 9.0.0 base64x 1.1.16
-1199  * A IA5String consists of following characters
-1200  * <pre>
-1201  * %x00-21/%x23-7F (i.e. ASCII characters excludes double quote(%x22)
-1202  * </pre>
-1203  * This method returns false when other characters than above.
-1204  * Otherwise it returns true.
-1205  * @example
-1206  * KJUR.lang.String.isIA5("abc") → true
-1207  * KJUR.lang.String.isIA5('"abc"') → false
-1208  * KJUR.lang.String.isIA5("あいう") → false
-1209  */
-1210 KJUR.lang.String.isIA5 = function(s) {
-1211     if (s.match(/^[\x20-\x21\x23-\x7f]*$/) !== null) return true;
-1212     return false;
-1213 };
-1214 
-1215 /**
-1216  * check whether a string is RFC 822 mail address<br/>
-1217  * @name isMail
-1218  * @memberOf KJUR.lang.String
-1219  * @function
-1220  * @static
-1221  * @param {String} s input string
-1222  * @return {Boolean} true if a string "s" RFC 822 mail address
-1223  * @since jsrsasign 9.0.0 base64x 1.1.16
-1224  * This static method will check string s is RFC 822 compliant mail address.
-1225  * @example
-1226  * KJUR.lang.String.isMail("abc") → false
-1227  * KJUR.lang.String.isMail("abc@example") → false
-1228  * KJUR.lang.String.isMail("abc@example.com") → true
-1229  */
-1230 KJUR.lang.String.isMail = function(s) {
-1231     if (s.match(/^[A-Za-z0-9]{1}[A-Za-z0-9_.-]*@{1}[A-Za-z0-9_.-]{1,}\.[A-Za-z0-9]{1,}$/) !== null) return true;
-1232     return false;
-1233 };
-1234 
-1235 // ==== others ================================
-1236 
-1237 /**
-1238  * canonicalize hexadecimal string of positive integer<br/>
-1239  * @name hextoposhex
-1240  * @function
-1241  * @param {String} s hexadecimal string 
-1242  * @return {String} canonicalized hexadecimal string of positive integer
-1243  * @since base64x 1.1.10 jsrsasign 7.1.4
-1244  * @description
-1245  * This method canonicalize a hexadecimal string of positive integer
-1246  * for two's complement representation.
-1247  * Canonicalized hexadecimal string of positive integer will be:
-1248  * <ul>
-1249  * <li>Its length is always even.</li>
-1250  * <li>If odd length it will be padded with leading zero.<li>
-1251  * <li>If it is even length and its first character is "8" or greater,
-1252  * it will be padded with "00" to make it positive integer.</li>
-1253  * </ul>
-1254  * @example
-1255  * hextoposhex("abcd") → "00abcd"
-1256  * hextoposhex("1234") → "1234"
-1257  * hextoposhex("12345") → "012345"
-1258  */
-1259 function hextoposhex(s) {
-1260     if (s.length % 2 == 1) return "0" + s;
-1261     if (s.substr(0, 1) > "7") return "00" + s;
-1262     return s;
-1263 }
-1264 
-1265 /**
-1266  * convert string of integer array to hexadecimal string.<br/>
-1267  * @name intarystrtohex
-1268  * @function
-1269  * @param {String} s string of integer array
-1270  * @return {String} hexadecimal string
-1271  * @since base64x 1.1.6 jsrsasign 5.0.2
-1272  * @throws "malformed integer array string: *" for wrong input
-1273  * @description
-1274  * This function converts a string of JavaScript integer array to
-1275  * a hexadecimal string. Each integer value shall be in a range 
-1276  * from 0 to 255 otherwise it raise exception. Input string can
-1277  * have extra space or newline string so that they will be ignored.
-1278  * 
-1279  * @example
-1280  * intarystrtohex(" [123, 34, 101, 34, 58] ")
-1281  * → 7b2265223a (i.e. '{"e":' as string)
-1282  */
-1283 function intarystrtohex(s) {
-1284   s = s.replace(/^\s*\[\s*/, '');
-1285   s = s.replace(/\s*\]\s*$/, '');
-1286   s = s.replace(/\s*/g, '');
-1287   try {
-1288     var hex = s.split(/,/).map(function(element, index, array) {
-1289       var i = parseInt(element);
-1290       if (i < 0 || 255 < i) throw "integer not in range 0-255";
-1291       var hI = ("00" + i.toString(16)).slice(-2);
-1292       return hI;
-1293     }).join('');
-1294     return hex;
-1295   } catch(ex) {
-1296     throw "malformed integer array string: " + ex;
-1297   }
-1298 }
-1299 
-1300 /**
-1301  * find index of string where two string differs
-1302  * @name strdiffidx
-1303  * @function
-1304  * @param {String} s1 string to compare
-1305  * @param {String} s2 string to compare
-1306  * @return {Number} string index of where character differs. Return -1 if same.
-1307  * @since jsrsasign 4.9.0 base64x 1.1.5
-1308  * @example
-1309  * strdiffidx("abcdefg", "abcd4fg") -> 4
-1310  * strdiffidx("abcdefg", "abcdefg") -> -1
-1311  * strdiffidx("abcdefg", "abcdef") -> 6
-1312  * strdiffidx("abcdefgh", "abcdef") -> 6
-1313  */
-1314 var strdiffidx = function(s1, s2) {
-1315     var n = s1.length;
-1316     if (s1.length > s2.length) n = s2.length;
-1317     for (var i = 0; i < n; i++) {
-1318 	if (s1.charCodeAt(i) != s2.charCodeAt(i)) return i;
-1319     }
-1320     if (s1.length != s2.length) return n;
-1321     return -1; // same
-1322 };
-1323 
-1324 // ==== hex / oid =================================
-1325 
-1326 /**
-1327  * get hexadecimal value of object identifier from dot noted oid value
-1328  * @name oidtohex
-1329  * @function
-1330  * @param {String} oidString dot noted string of object identifier
-1331  * @return {String} hexadecimal value of object identifier
-1332  * @since jsrsasign 10.1.0 base64x 1.1.18
-1333  * @see hextooid
-1334  * @see ASN1HEX.hextooidstr
-1335  * @see KJUR.asn1.ASN1Util.oidIntToHex
-1336  * @description
-1337  * This static method converts from object identifier value string.
-1338  * to hexadecimal string representation of it.
-1339  * {@link hextooid} is a reverse function of this.
-1340  * @example
-1341  * oidtohex("2.5.4.6") → "550406"
-1342  */
-1343 function oidtohex(oidString) {
-1344     var itox = function(i) {
-1345         var h = i.toString(16);
-1346         if (h.length == 1) h = '0' + h;
-1347         return h;
-1348     };
-1349 
-1350     var roidtox = function(roid) {
-1351         var h = '';
-1352         var bi = parseInt(roid, 10);
-1353         var b = bi.toString(2);
-1354 
-1355         var padLen = 7 - b.length % 7;
-1356         if (padLen == 7) padLen = 0;
-1357         var bPad = '';
-1358         for (var i = 0; i < padLen; i++) bPad += '0';
-1359         b = bPad + b;
-1360         for (var i = 0; i < b.length - 1; i += 7) {
-1361             var b8 = b.substr(i, 7);
-1362             if (i != b.length - 7) b8 = '1' + b8;
-1363             h += itox(parseInt(b8, 2));
-1364         }
-1365         return h;
-1366     };
-1367     
-1368     try {
-1369 	if (! oidString.match(/^[0-9.]+$/)) return null;
-1370     
-1371 	var h = '';
-1372 	var a = oidString.split('.');
-1373 	var i0 = parseInt(a[0], 10) * 40 + parseInt(a[1], 10);
-1374 	h += itox(i0);
-1375 	a.splice(0, 2);
-1376 	for (var i = 0; i < a.length; i++) {
-1377             h += roidtox(a[i]);
-1378 	}
-1379 	return h;
-1380     } catch(ex) {
-1381 	return null;
-1382     }
-1383 };
-1384 
-1385 /**
-1386  * get oid string from hexadecimal value of object identifier<br/>
-1387  * @name hextooid
-1388  * @function
-1389  * @param {String} h hexadecimal value of object identifier
-1390  * @return {String} dot noted string of object identifier (ex. "1.2.3.4")
-1391  * @since jsrsasign 10.1.0 base64x 1.1.18
-1392  * @see oidtohex
-1393  * @see ASN1HEX.hextooidstr
-1394  * @see KJUR.asn1.ASN1Util.oidIntToHex
-1395  * @description
-1396  * This static method converts from hexadecimal object identifier value 
-1397  * to dot noted OID value (ex. "1.2.3.4").
-1398  * {@link oidtohex} is a reverse function of this.
-1399  * @example
-1400  * hextooid("550406") → "2.5.4.6"
-1401  */
-1402 function hextooid(h) {
-1403     if (! ishex(h)) return null;
-1404     try {
-1405 	var a = [];
-1406 
-1407 	// a[0], a[1]
-1408 	var hex0 = h.substr(0, 2);
-1409 	var i0 = parseInt(hex0, 16);
-1410 	a[0] = new String(Math.floor(i0 / 40));
-1411 	a[1] = new String(i0 % 40);
-1412 
-1413 	// a[2]..a[n]
-1414 	var hex1 = h.substr(2);
-1415 	var b = [];
-1416 	for (var i = 0; i < hex1.length / 2; i++) {
-1417 	    b.push(parseInt(hex1.substr(i * 2, 2), 16));
-1418 	}
-1419 	var c = [];
-1420 	var cbin = "";
-1421 	for (var i = 0; i < b.length; i++) {
-1422             if (b[i] & 0x80) {
-1423 		cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7);
-1424             } else {
-1425 		cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7);
-1426 		c.push(new String(parseInt(cbin, 2)));
-1427 		cbin = "";
-1428             }
-1429 	}
-1430 
-1431 	var s = a.join(".");
-1432 	if (c.length > 0) s = s + "." + c.join(".");
-1433 	return s;
-1434     } catch(ex) {
-1435 	return null;
-1436     }
-1437 };
-1438 
-1439 /**
-1440  * string padding<br/>
-1441  * @name strpad
-1442  * @function
-1443  * @param {String} s input string
-1444  * @param {Number} len output string length
-1445  * @param {String} padchar padding character (default is "0")
-1446  * @return {String} padded string
-1447  * @since jsrsasign 10.1.0 base64x 1.1.18
-1448  * @example
-1449  * strpad("1234", 10, "0") → "0000001234"
-1450  * strpad("1234", 10, " ") → "      1234"
-1451  * strpad("1234", 10)      → "0000001234"
-1452  */
-1453 var strpad = function(s, len, padchar) {
-1454     if (padchar == undefined) padchar = "0";
-1455     if (s.length >= len) return s;
-1456     return new Array(len - s.length + 1).join(padchar) + s;
-1457 };
-1458 
-1459 // ==== bitstr hex / int =================================
-1460 
-1461 /**
-1462  * convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value<br/>
-1463  * @name bitstrtoint
-1464  * @function
-1465  * @param {String} h hexadecimal string of ASN.1 BitString value with unused bit
-1466  * @return {Number} positive integer value of the BitString
-1467  * @since jsrsasign 10.1.3 base64x 1.1.19
-1468  * @see inttobitstr
-1469  * @see KJUR.asn1.DERBitString
-1470  * @see ASN1HEX.getInt
-1471  * 
-1472  * @description
-1473  * This function converts from hexadecimal string of ASN.1 BitString
-1474  * value with unused bit to its integer value. <br/>
-1475  * When an improper hexadecimal string of BitString value
-1476  * is applied, this returns -1.
-1477  * 
-1478  * @example
-1479  * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25
-1480  * bitstrtoint("03c8") → 25
-1481  * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02
-1482  * //   11111111111110b → 16382
-1483  * bitstrtoint("02fff8") → 16382
-1484  * bitstrtoint("05a0") → 5 (=101b)
-1485  * bitstrtoint("ff00") → -1 // for improper BitString value
-1486  * bitstrtoint("05a0").toString(2) → "101"
-1487  * bitstrtoint("07a080").toString(2) → "101000001"
-1488  */
-1489 function bitstrtoint(h) {
-1490     if (h.length % 2 != 0) return -1; 
-1491     h = h.toLowerCase();
-1492     if (h.match(/^[0-9a-f]+$/) == null) return -1;
-1493     try {
-1494 	var hUnusedbit = h.substr(0, 2);
-1495 	if (hUnusedbit == "00")
-1496 	    return parseInt(h.substr(2), 16);
-1497 	var iUnusedbit = parseInt(hUnusedbit, 16);
-1498 	if (iUnusedbit > 7) return -1;
-1499 	var hValue = h.substr(2);
-1500 	var bValue = parseInt(hValue, 16).toString(2);
-1501 	if (bValue == "0") bValue = "00000000";
-1502 	bValue = bValue.slice(0, 0 - iUnusedbit);
-1503 	var iValue = parseInt(bValue, 2);
-1504 	if (iValue == NaN) return -1;
-1505 	return iValue;
-1506     } catch(ex) {
-1507 	return -1;
-1508     }
-1509 };
-1510 
-1511 /**
-1512  * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit<br/>
-1513  * @name inttobitstr
-1514  * @function
-1515  * @param {Number} n integer value of ASN.1 BitString
-1516  * @return {String} hexadecimal string of ASN.1 BitString value with unused bit
-1517  * @since jsrsasign 10.1.3 base64x 1.1.19
-1518  * @see bitstrtoint
-1519  * @see KJUR.asn1.DERBitString
-1520  * @see ASN1HEX.getInt
-1521  * 
-1522  * @description
-1523  * This function converts from an integer value to 
-1524  * hexadecimal string of ASN.1 BitString value
-1525  * with unused bit. <br/>
-1526  * When "n" is not non-negative number, this returns null
-1527  * 
-1528  * @example
-1529  * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8"
-1530  * inttobitstr(25) → "03c8"
-1531  * inttobitstr(-3) → null
-1532  * inttobitstr("abc") → null
-1533  * inttobitstr(parseInt("11001", 2)) → "03c8"
-1534  * inttobitstr(parseInt("101", 2)) → "05a0"
-1535  * inttobitstr(parseInt("101000001", 2)) → "07a080"
-1536  */
-1537 function inttobitstr(n) {
-1538     if (typeof n != "number") return null;
-1539     if (n < 0) return null;
-1540     var bValue = Number(n).toString(2);
-1541     var iUnusedbit = 8 - bValue.length % 8;
-1542     if (iUnusedbit == 8) iUnusedbit = 0;
-1543     bValue = bValue + strpad("", iUnusedbit, "0");
-1544     var hValue = parseInt(bValue, 2).toString(16);
-1545     if (hValue.length % 2 == 1) hValue = "0" + hValue;
-1546     var hUnusedbit = "0" + iUnusedbit;
-1547     return hUnusedbit + hValue;
-1548 };
-1549 
-1550 // ==== bitstr hex / binary string =======================
-1551 
-1552 /**
-1553  * convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string<br/>
-1554  * @name bitstrtobinstr
-1555  * @function
-1556  * @param {string} h hexadecimal string of ASN.1 BitString value with unused bit
-1557  * @return {string} binary string
-1558  * @since jsrsasign 10.5.4 base64x 1.1.21
-1559  * @see binstrtobitstr
-1560  * @see inttobitstr
-1561  * 
-1562  * @description
-1563  * This function converts from hexadecimal string of ASN.1 BitString
-1564  * value with unused bit to its integer value. <br/>
-1565  * When an improper hexadecimal string of BitString value
-1566  * is applied, this returns null.
-1567  * 
-1568  * @example
-1569  * bitstrtobinstr("05a0") → "101"
-1570  * bitstrtobinstr("07a080") → "101000001"
-1571  * bitstrtoint(502) → null // non ASN.1 BitString value
-1572  * bitstrtoint("ff00") → -1 // for improper BitString value
-1573  */
-1574 function bitstrtobinstr(h) {
-1575     var n = bitstrtoint(h);
-1576     if (n == -1) return null;
-1577     return n.toString(2);
-1578 }
-1579 
-1580 /**
-1581  * convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit<br/>
-1582  * @name binstrtobitstr
-1583  * @function
-1584  * @param {string} s binary string (ex. "101")
-1585  * @return {string} hexadecimal string of ASN.1 BitString value with unused bit
-1586  * @since jsrsasign 10.5.4 base64x 1.1.21
-1587  * @see bitstrtobinstr
-1588  * @see inttobitstr
-1589  * @see KJUR.asn1.DERBitString
-1590  * 
-1591  * @description
-1592  * This function converts from an binary string (ex. "101") to 
-1593  * hexadecimal string of ASN.1 BitString value
-1594  * with unused bit (ex. "05a0"). <br/>
-1595  * When "s" is not binary string, this returns null.
-1596  * 
-1597  * @example
-1598  * binstrtobitstr("101") → "05a0"
-1599  * binstrtobitstr("11001") → "03c8"
-1600  * binstrtobitstr("101000001") → "07a080"
-1601  * binstrtobitstr(101) → null // not number
-1602  * binstrtobitstr("xyz") → null // not binary string
-1603  */
-1604 function binstrtobitstr(s) {
-1605     if (typeof s != "string") return null;
-1606     if (s.match(/^[01]+$/) == null) return null;
-1607     try {
-1608 	var n = parseInt(s, 2);
-1609 	return inttobitstr(n);
-1610     } catch(ex) {
-1611 	return null;
-1612     }
-1613 }
-1614 
-1615 // =======================================================
-1616 /**
-1617  * set class inheritance<br/>
-1618  * @name extendClass
-1619  * @function
-1620  * @param {Function} subClass sub class to set inheritance
-1621  * @param {Function} superClass super class to inherit
-1622  * @since jsrsasign 10.3.0 base64x 1.1.21
-1623  *
-1624  * @description
-1625  * This function extends a class and set an inheritance
-1626  * for member variables and methods.
-1627  *
-1628  * @example
-1629  * var Animal = function() {
-1630  *   this.hello = function(){console.log("Hello")};
-1631  *   this.name="Ani";
-1632  * };
-1633  * var Dog = function() {
-1634  *   Dog.superclass.constructor.call(this);
-1635  *   this.vow = function(){console.log("Vow wow")};
-1636  *   this.tail=true;
-1637  * };
-1638  * extendClass(Dog, Animal);
-1639  */
-1640 function extendClass(subClass, superClass) {
-1641     var F = function() {};
-1642     F.prototype = superClass.prototype;
-1643     subClass.prototype = new F();
-1644     subClass.prototype.constructor = subClass;
-1645     subClass.superclass = superClass.prototype;
-1646      
-1647     if (superClass.prototype.constructor == Object.prototype.constructor) {
-1648         superClass.prototype.constructor = superClass;
-1649     }
-1650 };
-1651 
-1652 
\ No newline at end of file +650
return Math.round(zulutomsec(s) / 1000.0); +651 } +652 +653 // ==== zulu / Date ================================= +654 +655 /** +656 * GeneralizedTime or UTCTime string to Date object<br> +657 * @name zulutodate +658 * @function +659 * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z) +660 * @return {Date} Date object for specified time +661 * @since jsrsasign 7.1.3 base64x 1.1.9 +662 * @description +663 * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or +664 * UTCTime string (i.e. YYMMDDHHmmSSZ) to Date object. +665 * Argument string may have fraction of seconds and +666 * its length is one or more digits such as "20170410235959.1234567Z". +667 * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY. +668 * If year "YY" is equal or greater than 50 then it is 19YY. +669 * @example +670 * zulutodate( "071231235959Z").toUTCString() → "Mon, 31 Dec 2007 23:59:59 GMT" +671 * zulutodate( "071231235959.1Z").toUTCString() → "Mon, 31 Dec 2007 23:59:59 GMT" +672 * zulutodate("20071231235959Z").toUTCString() → "Mon, 31 Dec 2007 23:59:59 GMT" +673 * zulutodate( "071231235959.34").getMilliseconds() → 340 +674 */ +675 function zulutodate(s) { +676 return new Date(zulutomsec(s)); +677 } +678 +679 // ==== Date / zulu ================================= +680 +681 /** +682 * Date object to zulu time string<br> +683 * @name datetozulu +684 * @function +685 * @param {Date} d Date object for specified time +686 * @param {Boolean} flagUTCTime if this is true year will be YY otherwise YYYY +687 * @param {Boolean} flagMilli if this is true result concludes milliseconds +688 * @return {String} GeneralizedTime or UTCTime string (ex. 20170412235959.384Z) +689 * @since jsrsasign 7.2.0 base64x 1.1.11 +690 * @description +691 * This function converts from Date object to GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or +692 * UTCTime string (i.e. YYMMDDHHmmSSZ). +693 * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY. +694 * If year "YY" is equal or greater than 50 then it is 19YY. +695 * If flagMilli is true its result concludes milliseconds such like +696 * "20170520235959.42Z". +697 * @example +698 * d = new Date(Date.UTC(2017,4,20,23,59,59,670)); +699 * datetozulu(d) → "20170520235959Z" +700 * datetozulu(d, true) → "170520235959Z" +701 * datetozulu(d, false, true) → "20170520235959.67Z" +702 */ +703 function datetozulu(d, flagUTCTime, flagMilli) { +704 var s; +705 var year = d.getUTCFullYear(); +706 if (flagUTCTime) { +707 if (year < 1950 || 2049 < year) +708 throw "not proper year for UTCTime: " + year; +709 s = ("" + year).slice(-2); +710 } else { +711 s = ("000" + year).slice(-4); +712 } +713 s += ("0" + (d.getUTCMonth() + 1)).slice(-2); +714 s += ("0" + d.getUTCDate()).slice(-2); +715 s += ("0" + d.getUTCHours()).slice(-2); +716 s += ("0" + d.getUTCMinutes()).slice(-2); +717 s += ("0" + d.getUTCSeconds()).slice(-2); +718 if (flagMilli) { +719 var milli = d.getUTCMilliseconds(); +720 if (milli !== 0) { +721 milli = ("00" + milli).slice(-3); +722 milli = milli.replace(/0+$/g, ""); +723 s += "." + milli; +724 } +725 } +726 s += "Z"; +727 return s; +728 } +729 +730 // ==== URIComponent / hex ================================ +731 /** +732 * convert a URLComponent string such like "%67%68" to a hexadecimal string.<br/> +733 * @name uricmptohex +734 * @function +735 * @param {String} s URIComponent string such like "%67%68" +736 * @return {String} hexadecimal string +737 * @since 1.1 +738 */ +739 function uricmptohex(s) { +740 return s.replace(/%/g, ""); +741 } +742 +743 /** +744 * convert a hexadecimal string to a URLComponent string such like "%67%68".<br/> +745 * @name hextouricmp +746 * @function +747 * @param {String} s hexadecimal string +748 * @return {String} URIComponent string such like "%67%68" +749 * @since 1.1 +750 */ +751 function hextouricmp(s) { +752 return s.replace(/(..)/g, "%$1"); +753 } +754 +755 // ==== hex / ipv6 ================================= +756 +757 /** +758 * convert any IPv6 address to a 16 byte hexadecimal string +759 * @function +760 * @param s string of IPv6 address +761 * @return {String} 16 byte hexadecimal string of IPv6 address +762 * @description +763 * This function converts any IPv6 address representation string +764 * to a 16 byte hexadecimal string of address. +765 * @example +766 * +767 */ +768 function ipv6tohex(s) { +769 var msgMalformedAddress = "malformed IPv6 address"; +770 if (! s.match(/^[0-9A-Fa-f:]+$/)) +771 throw msgMalformedAddress; +772 +773 // 1. downcase +774 s = s.toLowerCase(); +775 +776 // 2. expand :: +777 var num_colon = s.split(':').length - 1; +778 if (num_colon < 2) throw msgMalformedAddress; +779 var colon_replacer = ':'.repeat(7 - num_colon + 2); +780 s = s.replace('::', colon_replacer); +781 +782 // 3. fill zero +783 var a = s.split(':'); +784 if (a.length != 8) throw msgMalformedAddress; +785 for (var i = 0; i < 8; i++) { +786 a[i] = ("0000" + a[i]).slice(-4); +787 } +788 return a.join(''); +789 } +790 +791 /** +792 * convert a 16 byte hexadecimal string to RFC 5952 canonicalized IPv6 address<br/> +793 * @name hextoipv6 +794 * @function +795 * @param {String} s hexadecimal string of 16 byte IPv6 address +796 * @return {String} IPv6 address string canonicalized by RFC 5952 +797 * @since jsrsasign 8.0.10 base64x 1.1.13 +798 * @description +799 * This function converts a 16 byte hexadecimal string to +800 * <a href="https://tools.ietf.org/html/rfc5952">RFC 5952</a> +801 * canonicalized IPv6 address string. +802 * @example +803 * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4" +804 * hextoip("871020010db8000000000000000000") &rarr raise exception +805 * hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception +806 */ +807 function hextoipv6(s) { +808 if (! s.match(/^[0-9A-Fa-f]{32}$/)) +809 throw "malformed IPv6 address octet"; +810 +811 // 1. downcase +812 s = s.toLowerCase(); +813 +814 // 2. split 4 +815 var a = s.match(/.{1,4}/g); +816 +817 // 3. trim leading 0 +818 for (var i = 0; i < 8; i++) { +819 a[i] = a[i].replace(/^0+/, ""); +820 if (a[i] == '') a[i] = '0'; +821 } +822 s = ":" + a.join(":") + ":"; +823 +824 // 4. find shrinkables :0:0:... +825 var aZero = s.match(/:(0:){2,}/g); +826 +827 // 5. no shrinkable +828 if (aZero === null) return s.slice(1, -1); +829 +830 // 6. find max length :0:0:... +831 var item = ''; +832 for (var i = 0; i < aZero.length; i++) { +833 if (aZero[i].length > item.length) item = aZero[i]; +834 } +835 +836 // 7. shrink +837 s = s.replace(item, '::'); +838 return s.slice(1, -1); +839 } +840 +841 // ==== hex / ip ================================= +842 +843 /** +844 * convert a hexadecimal string to IP addresss<br/> +845 * @name hextoip +846 * @function +847 * @param {String} s hexadecimal string of IP address +848 * @return {String} IP address string +849 * @since jsrsasign 8.0.10 base64x 1.1.13 +850 * @description +851 * This function converts a hexadecimal string of IPv4 or +852 * IPv6 address to IPv4 or IPv6 address string. +853 * If byte length is not 4 nor 16, this returns a +854 * hexadecimal string without conversion. +855 * @see {@link hextoipv6} +856 * @example +857 * hextoip("c0a80101") &rarr "192.168.1.1" +858 * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4" +859 * hextoip("c0a801010203") &rarr "c0a801010203" // 6 bytes +860 * hextoip("zzz")) &rarr raise exception because of not hexadecimal +861 */ +862 function hextoip(s) { +863 var malformedMsg = "malformed hex value"; +864 if (! s.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)) +865 throw malformedMsg; +866 if (s.length == 8) { // ipv4 +867 var ip; +868 try { +869 ip = parseInt(s.substr(0, 2), 16) + "." + +870 parseInt(s.substr(2, 2), 16) + "." + +871 parseInt(s.substr(4, 2), 16) + "." + +872 parseInt(s.substr(6, 2), 16); +873 return ip; +874 } catch (ex) { +875 throw malformedMsg; +876 } +877 } else if (s.length == 32) { +878 return hextoipv6(s); +879 } else { +880 return s; +881 } +882 } +883 +884 /** +885 * convert IPv4/v6 addresss to a hexadecimal string<br/> +886 * @name iptohex +887 * @function +888 * @param {String} s IPv4/v6 address string +889 * @return {String} hexadecimal string of IP address +890 * @since jsrsasign 8.0.12 base64x 1.1.14 +891 * @description +892 * This function converts IPv4 or IPv6 address string to +893 * a hexadecimal string of IPv4 or IPv6 address. +894 * @example +895 * iptohex("192.168.1.1") &rarr "c0a80101" +896 * iptohex("2001:db8::4") &rarr "871020010db8000000000000000000000004" +897 * iptohex("zzz")) &rarr raise exception +898 */ +899 function iptohex(s) { +900 var malformedMsg = "malformed IP address"; +901 s = s.toLowerCase(s); +902 +903 if (s.match(/^[0-9.]+$/)) { +904 var a = s.split("."); +905 if (a.length !== 4) throw malformedMsg; +906 var hex = ""; +907 try { +908 for (var i = 0; i < 4; i++) { +909 var d = parseInt(a[i]); +910 hex += ("0" + d.toString(16)).slice(-2); +911 } +912 return hex; +913 } catch(ex) { +914 throw malformedMsg; +915 } +916 } else if (s.match(/^[0-9a-f:]+$/) && s.indexOf(":") !== -1) { +917 return ipv6tohex(s); +918 } else { +919 throw malformedMsg; +920 } +921 } +922 +923 // ==== ucs2hex / utf8 ============================== +924 +925 /** +926 * convert UCS-2 hexadecimal stirng to UTF-8 string<br/> +927 * @name ucs2hextoutf8 +928 * @function +929 * @param {String} s hexadecimal string of UCS-2 string (ex. "0066") +930 * @return {String} UTF-8 string +931 * @since jsrsasign 10.1.13 base64x 1.1.20 +932 * @description +933 * This function converts hexadecimal value of UCS-2 string to +934 * UTF-8 string. +935 * @example +936 * ucs2hextoutf8("006600fc0072") &rarr "für" +937 */ +938 /* +939 See: http://nomenclator.la.coocan.jp/unicode/ucs_utf.htm +940 UCS-2 to UTF-8 +941 UCS-2 code point | UCS-2 bytes | UTF-8 bytes +942 U+0000 .. U+007F | 00000000-0xxxxxxx | 0xxxxxxx (1 byte) +943 U+0080 .. U+07FF | 00000xxx-xxyyyyyy | 110xxxxx 10yyyyyy (2 byte) +944 U+0800 .. U+FFFF | xxxxyyyy-yyzzzzzz | 1110xxxx 10yyyyyy 10zzzzzz (3 byte) +945 */ +946 function ucs2hextoutf8(s) { +947 function _conv(s) { +948 var i1 = parseInt(s.substr(0, 2), 16); +949 var i2 = parseInt(s.substr(2), 16); +950 if (i1 == 0 & i2 < 0x80) { // 1 byte +951 return String.fromCharCode(i2); +952 } +953 if (i1 < 8) { // 2 bytes +954 var u1 = 0xc0 | ((i1 & 0x07) << 3) | ((i2 & 0xc0) >> 6); +955 var u2 = 0x80 | (i2 & 0x3f); +956 return hextoutf8(u1.toString(16) + u2.toString(16)); +957 } +958 // 3 bytes +959 var u1 = 0xe0 | ((i1 & 0xf0) >> 4); +960 var u2 = 0x80 | ((i1 & 0x0f) << 2) | ((i2 & 0xc0) >> 6); +961 var u3 = 0x80 | (i2 & 0x3f); +962 return hextoutf8(u1.toString(16) + u2.toString(16) + u3.toString(16)); +963 } +964 var a = s.match(/.{4}/g); +965 var a2 = a.map(_conv); +966 return a2.join(""); +967 } +968 +969 // ==== URIComponent ================================ +970 /** +971 * convert UTFa hexadecimal string to a URLComponent string such like "%67%68".<br/> +972 * Note that these "<code>0-9A-Za-z!'()*-._~</code>" characters will not +973 * converted to "%xx" format by builtin 'encodeURIComponent()' function. +974 * However this 'encodeURIComponentAll()' function will convert +975 * all of characters into "%xx" format. +976 * @name encodeURIComponentAll +977 * @function +978 * @param {String} s hexadecimal string +979 * @return {String} URIComponent string such like "%67%68" +980 * @since 1.1 +981 */ +982 function encodeURIComponentAll(u8) { +983 var s = encodeURIComponent(u8); +984 var s2 = ""; +985 for (var i = 0; i < s.length; i++) { +986 if (s[i] == "%") { +987 s2 = s2 + s.substr(i, 3); +988 i = i + 2; +989 } else { +990 s2 = s2 + "%" + stohex(s[i]); +991 } +992 } +993 return s2; +994 } +995 +996 // ==== new lines ================================ +997 /** +998 * convert all DOS new line("\r\n") to UNIX new line("\n") in +999 * a String "s". +1000 * @name newline_toUnix +1001 * @function +1002 * @param {String} s string +1003 * @return {String} converted string +1004 */ +1005 function newline_toUnix(s) { +1006 s = s.replace(/\r\n/mg, "\n"); +1007 return s; +1008 } +1009 +1010 /** +1011 * convert all UNIX new line("\r\n") to DOS new line("\n") in +1012 * a String "s". +1013 * @name newline_toDos +1014 * @function +1015 * @param {String} s string +1016 * @return {String} converted string +1017 */ +1018 function newline_toDos(s) { +1019 s = s.replace(/\r\n/mg, "\n"); +1020 s = s.replace(/\n/mg, "\r\n"); +1021 return s; +1022 } +1023 +1024 // ==== string type checker =================== +1025 +1026 /** +1027 * check whether a string is an integer string or not<br/> +1028 * @name isInteger +1029 * @memberOf KJUR.lang.String +1030 * @function +1031 * @static +1032 * @param {String} s input string +1033 * @return {Boolean} true if a string "s" is an integer string otherwise false +1034 * @since base64x 1.1.7 jsrsasign 5.0.13 +1035 * @example +1036 * KJUR.lang.String.isInteger("12345") → true +1037 * KJUR.lang.String.isInteger("123ab") → false +1038 */ +1039 KJUR.lang.String.isInteger = function(s) { +1040 if (s.match(/^[0-9]+$/)) { +1041 return true; +1042 } else if (s.match(/^-[0-9]+$/)) { +1043 return true; +1044 } else { +1045 return false; +1046 } +1047 }; +1048 +1049 /** +1050 * check whether a string is an hexadecimal string or not (DEPRECATED)<br/> +1051 * @name isHex +1052 * @memberOf KJUR.lang.String +1053 * @function +1054 * @static +1055 * @param {String} s input string +1056 * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false +1057 * @since base64x 1.1.7 jsrsasign 5.0.13 +1058 * @deprecated from 10.0.6. please use {@link ishex} +1059 * @see ishex +1060 * @example +1061 * KJUR.lang.String.isHex("1234") → true +1062 * KJUR.lang.String.isHex("12ab") → true +1063 * KJUR.lang.String.isHex("12AB") → true +1064 * KJUR.lang.String.isHex("12ZY") → false +1065 * KJUR.lang.String.isHex("121") → false -- odd length +1066 */ +1067 KJUR.lang.String.isHex = function(s) { +1068 return ishex(s); +1069 }; +1070 +1071 /** +1072 * check whether a string is an hexadecimal string or not<br/> +1073 * @name ishex +1074 * @function +1075 * @static +1076 * @param {String} s input string +1077 * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false +1078 * @since base64x 1.1.7 jsrsasign 5.0.13 +1079 * @example +1080 * ishex("1234") → true +1081 * ishex("12ab") → true +1082 * ishex("12AB") → true +1083 * ishex("12ZY") → false +1084 * ishex("121") → false -- odd length +1085 */ +1086 function ishex(s) { +1087 if (s.length % 2 == 0 && +1088 (s.match(/^[0-9a-f]+$/) || s.match(/^[0-9A-F]+$/))) { +1089 return true; +1090 } else { +1091 return false; +1092 } +1093 }; +1094 +1095 /** +1096 * check whether a string is a base64 encoded string or not<br/> +1097 * Input string can conclude new lines or space characters. +1098 * @name isBase64 +1099 * @memberOf KJUR.lang.String +1100 * @function +1101 * @static +1102 * @param {String} s input string +1103 * @return {Boolean} true if a string "s" is a base64 encoded string otherwise false +1104 * @since base64x 1.1.7 jsrsasign 5.0.13 +1105 * @example +1106 * KJUR.lang.String.isBase64("YWE=") → true +1107 * KJUR.lang.String.isBase64("YW_=") → false +1108 * KJUR.lang.String.isBase64("YWE") → false -- length shall be multiples of 4 +1109 */ +1110 KJUR.lang.String.isBase64 = function(s) { +1111 s = s.replace(/\s+/g, ""); +1112 if (s.match(/^[0-9A-Za-z+\/]+={0,3}$/) && s.length % 4 == 0) { +1113 return true; +1114 } else { +1115 return false; +1116 } +1117 }; +1118 +1119 /** +1120 * check whether a string is a base64url encoded string or not<br/> +1121 * Input string can conclude new lines or space characters. +1122 * @name isBase64URL +1123 * @memberOf KJUR.lang.String +1124 * @function +1125 * @static +1126 * @param {String} s input string +1127 * @return {Boolean} true if a string "s" is a base64url encoded string otherwise false +1128 * @since base64x 1.1.7 jsrsasign 5.0.13 +1129 * @example +1130 * KJUR.lang.String.isBase64URL("YWE") → true +1131 * KJUR.lang.String.isBase64URL("YW-") → true +1132 * KJUR.lang.String.isBase64URL("YW+") → false +1133 */ +1134 KJUR.lang.String.isBase64URL = function(s) { +1135 if (s.match(/[+/=]/)) return false; +1136 s = b64utob64(s); +1137 return KJUR.lang.String.isBase64(s); +1138 }; +1139 +1140 /** +1141 * check whether a string is a string of integer array or not<br/> +1142 * Input string can conclude new lines or space characters. +1143 * @name isIntegerArray +1144 * @memberOf KJUR.lang.String +1145 * @function +1146 * @static +1147 * @param {String} s input string +1148 * @return {Boolean} true if a string "s" is a string of integer array otherwise false +1149 * @since base64x 1.1.7 jsrsasign 5.0.13 +1150 * @example +1151 * KJUR.lang.String.isIntegerArray("[1,2,3]") → true +1152 * KJUR.lang.String.isIntegerArray(" [1, 2, 3 ] ") → true +1153 * KJUR.lang.String.isIntegerArray("[a,2]") → false +1154 */ +1155 KJUR.lang.String.isIntegerArray = function(s) { +1156 s = s.replace(/\s+/g, ""); +1157 if (s.match(/^\[[0-9,]+\]$/)) { +1158 return true; +1159 } else { +1160 return false; +1161 } +1162 }; +1163 +1164 /** +1165 * check whether a string consists of PrintableString characters<br/> +1166 * @name isPrintable +1167 * @memberOf KJUR.lang.String +1168 * @function +1169 * @static +1170 * @param {String} s input string +1171 * @return {Boolean} true if a string "s" consists of PrintableString characters +1172 * @since jsrsasign 9.0.0 base64x 1.1.16 +1173 * A PrintableString consists of following characters +1174 * <pre> +1175 * 0-9A-Za-z '()+,-./:=? +1176 * </pre> +1177 * This method returns false when other characters than above. +1178 * Otherwise it returns true. +1179 * @example +1180 * KJUR.lang.String.isPrintable("abc") → true +1181 * KJUR.lang.String.isPrintable("abc@") → false +1182 * KJUR.lang.String.isPrintable("あいう") → false +1183 */ +1184 KJUR.lang.String.isPrintable = function(s) { +1185 if (s.match(/^[0-9A-Za-z '()+,-./:=?]*$/) !== null) return true; +1186 return false; +1187 }; +1188 +1189 /** +1190 * check whether a string consists of IAString characters<br/> +1191 * @name isIA5 +1192 * @memberOf KJUR.lang.String +1193 * @function +1194 * @static +1195 * @param {String} s input string +1196 * @return {Boolean} true if a string "s" consists of IA5String characters +1197 * @since jsrsasign 9.0.0 base64x 1.1.16 +1198 * A IA5String consists of following characters +1199 * <pre> +1200 * %x00-21/%x23-7F (i.e. ASCII characters excludes double quote(%x22) +1201 * </pre> +1202 * This method returns false when other characters than above. +1203 * Otherwise it returns true. +1204 * @example +1205 * KJUR.lang.String.isIA5("abc") → true +1206 * KJUR.lang.String.isIA5('"abc"') → false +1207 * KJUR.lang.String.isIA5("あいう") → false +1208 */ +1209 KJUR.lang.String.isIA5 = function(s) { +1210 if (s.match(/^[\x20-\x21\x23-\x7f]*$/) !== null) return true; +1211 return false; +1212 }; +1213 +1214 /** +1215 * check whether a string is RFC 822 mail address<br/> +1216 * @name isMail +1217 * @memberOf KJUR.lang.String +1218 * @function +1219 * @static +1220 * @param {String} s input string +1221 * @return {Boolean} true if a string "s" RFC 822 mail address +1222 * @since jsrsasign 9.0.0 base64x 1.1.16 +1223 * This static method will check string s is RFC 822 compliant mail address. +1224 * @example +1225 * KJUR.lang.String.isMail("abc") → false +1226 * KJUR.lang.String.isMail("abc@example") → false +1227 * KJUR.lang.String.isMail("abc@example.com") → true +1228 */ +1229 KJUR.lang.String.isMail = function(s) { +1230 if (s.match(/^[A-Za-z0-9]{1}[A-Za-z0-9_.-]*@{1}[A-Za-z0-9_.-]{1,}\.[A-Za-z0-9]{1,}$/) !== null) return true; +1231 return false; +1232 }; +1233 +1234 // ==== others ================================ +1235 +1236 /** +1237 * canonicalize hexadecimal string of positive integer<br/> +1238 * @name hextoposhex +1239 * @function +1240 * @param {String} s hexadecimal string +1241 * @return {String} canonicalized hexadecimal string of positive integer +1242 * @since base64x 1.1.10 jsrsasign 7.1.4 +1243 * @description +1244 * This method canonicalize a hexadecimal string of positive integer +1245 * for two's complement representation. +1246 * Canonicalized hexadecimal string of positive integer will be: +1247 * <ul> +1248 * <li>Its length is always even.</li> +1249 * <li>If odd length it will be padded with leading zero.<li> +1250 * <li>If it is even length and its first character is "8" or greater, +1251 * it will be padded with "00" to make it positive integer.</li> +1252 * </ul> +1253 * @example +1254 * hextoposhex("abcd") → "00abcd" +1255 * hextoposhex("1234") → "1234" +1256 * hextoposhex("12345") → "012345" +1257 */ +1258 function hextoposhex(s) { +1259 if (s.length % 2 == 1) return "0" + s; +1260 if (s.substr(0, 1) > "7") return "00" + s; +1261 return s; +1262 } +1263 +1264 /** +1265 * convert string of integer array to hexadecimal string.<br/> +1266 * @name intarystrtohex +1267 * @function +1268 * @param {String} s string of integer array +1269 * @return {String} hexadecimal string +1270 * @since base64x 1.1.6 jsrsasign 5.0.2 +1271 * @throws "malformed integer array string: *" for wrong input +1272 * @description +1273 * This function converts a string of JavaScript integer array to +1274 * a hexadecimal string. Each integer value shall be in a range +1275 * from 0 to 255 otherwise it raise exception. Input string can +1276 * have extra space or newline string so that they will be ignored. +1277 * +1278 * @example +1279 * intarystrtohex(" [123, 34, 101, 34, 58] ") +1280 * → 7b2265223a (i.e. '{"e":' as string) +1281 */ +1282 function intarystrtohex(s) { +1283 s = s.replace(/^\s*\[\s*/, ''); +1284 s = s.replace(/\s*\]\s*$/, ''); +1285 s = s.replace(/\s*/g, ''); +1286 try { +1287 var hex = s.split(/,/).map(function(element, index, array) { +1288 var i = parseInt(element); +1289 if (i < 0 || 255 < i) throw "integer not in range 0-255"; +1290 var hI = ("00" + i.toString(16)).slice(-2); +1291 return hI; +1292 }).join(''); +1293 return hex; +1294 } catch(ex) { +1295 throw "malformed integer array string: " + ex; +1296 } +1297 } +1298 +1299 /** +1300 * find index of string where two string differs +1301 * @name strdiffidx +1302 * @function +1303 * @param {String} s1 string to compare +1304 * @param {String} s2 string to compare +1305 * @return {Number} string index of where character differs. Return -1 if same. +1306 * @since jsrsasign 4.9.0 base64x 1.1.5 +1307 * @example +1308 * strdiffidx("abcdefg", "abcd4fg") -> 4 +1309 * strdiffidx("abcdefg", "abcdefg") -> -1 +1310 * strdiffidx("abcdefg", "abcdef") -> 6 +1311 * strdiffidx("abcdefgh", "abcdef") -> 6 +1312 */ +1313 var strdiffidx = function(s1, s2) { +1314 var n = s1.length; +1315 if (s1.length > s2.length) n = s2.length; +1316 for (var i = 0; i < n; i++) { +1317 if (s1.charCodeAt(i) != s2.charCodeAt(i)) return i; +1318 } +1319 if (s1.length != s2.length) return n; +1320 return -1; // same +1321 }; +1322 +1323 // ==== hex / oid ================================= +1324 +1325 /** +1326 * get hexadecimal value of object identifier from dot noted oid value +1327 * @name oidtohex +1328 * @function +1329 * @param {String} oidString dot noted string of object identifier +1330 * @return {String} hexadecimal value of object identifier +1331 * @since jsrsasign 10.1.0 base64x 1.1.18 +1332 * @see hextooid +1333 * @see ASN1HEX.hextooidstr +1334 * @see KJUR.asn1.ASN1Util.oidIntToHex +1335 * @description +1336 * This static method converts from object identifier value string. +1337 * to hexadecimal string representation of it. +1338 * {@link hextooid} is a reverse function of this. +1339 * @example +1340 * oidtohex("2.5.4.6") → "550406" +1341 */ +1342 function oidtohex(oidString) { +1343 var itox = function(i) { +1344 var h = i.toString(16); +1345 if (h.length == 1) h = '0' + h; +1346 return h; +1347 }; +1348 +1349 var roidtox = function(roid) { +1350 var h = ''; +1351 var bi = parseInt(roid, 10); +1352 var b = bi.toString(2); +1353 +1354 var padLen = 7 - b.length % 7; +1355 if (padLen == 7) padLen = 0; +1356 var bPad = ''; +1357 for (var i = 0; i < padLen; i++) bPad += '0'; +1358 b = bPad + b; +1359 for (var i = 0; i < b.length - 1; i += 7) { +1360 var b8 = b.substr(i, 7); +1361 if (i != b.length - 7) b8 = '1' + b8; +1362 h += itox(parseInt(b8, 2)); +1363 } +1364 return h; +1365 }; +1366 +1367 try { +1368 if (! oidString.match(/^[0-9.]+$/)) return null; +1369 +1370 var h = ''; +1371 var a = oidString.split('.'); +1372 var i0 = parseInt(a[0], 10) * 40 + parseInt(a[1], 10); +1373 h += itox(i0); +1374 a.splice(0, 2); +1375 for (var i = 0; i < a.length; i++) { +1376 h += roidtox(a[i]); +1377 } +1378 return h; +1379 } catch(ex) { +1380 return null; +1381 } +1382 }; +1383 +1384 /** +1385 * get oid string from hexadecimal value of object identifier<br/> +1386 * @name hextooid +1387 * @function +1388 * @param {String} h hexadecimal value of object identifier +1389 * @return {String} dot noted string of object identifier (ex. "1.2.3.4") +1390 * @since jsrsasign 10.1.0 base64x 1.1.18 +1391 * @see oidtohex +1392 * @see ASN1HEX.hextooidstr +1393 * @see KJUR.asn1.ASN1Util.oidIntToHex +1394 * @description +1395 * This static method converts from hexadecimal object identifier value +1396 * to dot noted OID value (ex. "1.2.3.4"). +1397 * {@link oidtohex} is a reverse function of this. +1398 * @example +1399 * hextooid("550406") → "2.5.4.6" +1400 */ +1401 function hextooid(h) { +1402 if (! ishex(h)) return null; +1403 try { +1404 var a = []; +1405 +1406 // a[0], a[1] +1407 var hex0 = h.substr(0, 2); +1408 var i0 = parseInt(hex0, 16); +1409 a[0] = new String(Math.floor(i0 / 40)); +1410 a[1] = new String(i0 % 40); +1411 +1412 // a[2]..a[n] +1413 var hex1 = h.substr(2); +1414 var b = []; +1415 for (var i = 0; i < hex1.length / 2; i++) { +1416 b.push(parseInt(hex1.substr(i * 2, 2), 16)); +1417 } +1418 var c = []; +1419 var cbin = ""; +1420 for (var i = 0; i < b.length; i++) { +1421 if (b[i] & 0x80) { +1422 cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7); +1423 } else { +1424 cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7); +1425 c.push(new String(parseInt(cbin, 2))); +1426 cbin = ""; +1427 } +1428 } +1429 +1430 var s = a.join("."); +1431 if (c.length > 0) s = s + "." + c.join("."); +1432 return s; +1433 } catch(ex) { +1434 return null; +1435 } +1436 }; +1437 +1438 /** +1439 * string padding<br/> +1440 * @name strpad +1441 * @function +1442 * @param {String} s input string +1443 * @param {Number} len output string length +1444 * @param {String} padchar padding character (default is "0") +1445 * @return {String} padded string +1446 * @since jsrsasign 10.1.0 base64x 1.1.18 +1447 * @example +1448 * strpad("1234", 10, "0") → "0000001234" +1449 * strpad("1234", 10, " ") → " 1234" +1450 * strpad("1234", 10) → "0000001234" +1451 */ +1452 var strpad = function(s, len, padchar) { +1453 if (padchar == undefined) padchar = "0"; +1454 if (s.length >= len) return s; +1455 return new Array(len - s.length + 1).join(padchar) + s; +1456 }; +1457 +1458 // ==== bitstr hex / int ================================= +1459 +1460 /** +1461 * convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value<br/> +1462 * @name bitstrtoint +1463 * @function +1464 * @param {String} h hexadecimal string of ASN.1 BitString value with unused bit +1465 * @return {Number} positive integer value of the BitString +1466 * @since jsrsasign 10.1.3 base64x 1.1.19 +1467 * @see inttobitstr +1468 * @see KJUR.asn1.DERBitString +1469 * @see ASN1HEX.getInt +1470 * +1471 * @description +1472 * This function converts from hexadecimal string of ASN.1 BitString +1473 * value with unused bit to its integer value. <br/> +1474 * When an improper hexadecimal string of BitString value +1475 * is applied, this returns -1. +1476 * +1477 * @example +1478 * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25 +1479 * bitstrtoint("03c8") → 25 +1480 * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02 +1481 * // 11111111111110b → 16382 +1482 * bitstrtoint("02fff8") → 16382 +1483 * bitstrtoint("05a0") → 5 (=101b) +1484 * bitstrtoint("ff00") → -1 // for improper BitString value +1485 * bitstrtoint("05a0").toString(2) → "101" +1486 * bitstrtoint("07a080").toString(2) → "101000001" +1487 */ +1488 function bitstrtoint(h) { +1489 if (h.length % 2 != 0) return -1; +1490 h = h.toLowerCase(); +1491 if (h.match(/^[0-9a-f]+$/) == null) return -1; +1492 try { +1493 var hUnusedbit = h.substr(0, 2); +1494 if (hUnusedbit == "00") +1495 return parseInt(h.substr(2), 16); +1496 var iUnusedbit = parseInt(hUnusedbit, 16); +1497 if (iUnusedbit > 7) return -1; +1498 var hValue = h.substr(2); +1499 var bValue = parseInt(hValue, 16).toString(2); +1500 if (bValue == "0") bValue = "00000000"; +1501 bValue = bValue.slice(0, 0 - iUnusedbit); +1502 var iValue = parseInt(bValue, 2); +1503 if (iValue == NaN) return -1; +1504 return iValue; +1505 } catch(ex) { +1506 return -1; +1507 } +1508 }; +1509 +1510 /** +1511 * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit<br/> +1512 * @name inttobitstr +1513 * @function +1514 * @param {Number} n integer value of ASN.1 BitString +1515 * @return {String} hexadecimal string of ASN.1 BitString value with unused bit +1516 * @since jsrsasign 10.1.3 base64x 1.1.19 +1517 * @see bitstrtoint +1518 * @see KJUR.asn1.DERBitString +1519 * @see ASN1HEX.getInt +1520 * +1521 * @description +1522 * This function converts from an integer value to +1523 * hexadecimal string of ASN.1 BitString value +1524 * with unused bit. <br/> +1525 * When "n" is not non-negative number, this returns null +1526 * +1527 * @example +1528 * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8" +1529 * inttobitstr(25) → "03c8" +1530 * inttobitstr(-3) → null +1531 * inttobitstr("abc") → null +1532 * inttobitstr(parseInt("11001", 2)) → "03c8" +1533 * inttobitstr(parseInt("101", 2)) → "05a0" +1534 * inttobitstr(parseInt("101000001", 2)) → "07a080" +1535 */ +1536 function inttobitstr(n) { +1537 if (typeof n != "number") return null; +1538 if (n < 0) return null; +1539 var bValue = Number(n).toString(2); +1540 var iUnusedbit = 8 - bValue.length % 8; +1541 if (iUnusedbit == 8) iUnusedbit = 0; +1542 bValue = bValue + strpad("", iUnusedbit, "0"); +1543 var hValue = parseInt(bValue, 2).toString(16); +1544 if (hValue.length % 2 == 1) hValue = "0" + hValue; +1545 var hUnusedbit = "0" + iUnusedbit; +1546 return hUnusedbit + hValue; +1547 }; +1548 +1549 // ==== bitstr hex / binary string ======================= +1550 +1551 /** +1552 * convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string<br/> +1553 * @name bitstrtobinstr +1554 * @function +1555 * @param {string} h hexadecimal string of ASN.1 BitString value with unused bit +1556 * @return {string} binary string +1557 * @since jsrsasign 10.5.4 base64x 1.1.21 +1558 * @see binstrtobitstr +1559 * @see inttobitstr +1560 * +1561 * @description +1562 * This function converts from hexadecimal string of ASN.1 BitString +1563 * value with unused bit to its integer value. <br/> +1564 * When an improper hexadecimal string of BitString value +1565 * is applied, this returns null. +1566 * +1567 * @example +1568 * bitstrtobinstr("05a0") → "101" +1569 * bitstrtobinstr("07a080") → "101000001" +1570 * bitstrtoint(502) → null // non ASN.1 BitString value +1571 * bitstrtoint("ff00") → -1 // for improper BitString value +1572 */ +1573 function bitstrtobinstr(h) { +1574 var n = bitstrtoint(h); +1575 if (n == -1) return null; +1576 return n.toString(2); +1577 } +1578 +1579 /** +1580 * convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit<br/> +1581 * @name binstrtobitstr +1582 * @function +1583 * @param {string} s binary string (ex. "101") +1584 * @return {string} hexadecimal string of ASN.1 BitString value with unused bit +1585 * @since jsrsasign 10.5.4 base64x 1.1.21 +1586 * @see bitstrtobinstr +1587 * @see inttobitstr +1588 * @see KJUR.asn1.DERBitString +1589 * +1590 * @description +1591 * This function converts from an binary string (ex. "101") to +1592 * hexadecimal string of ASN.1 BitString value +1593 * with unused bit (ex. "05a0"). <br/> +1594 * When "s" is not binary string, this returns null. +1595 * +1596 * @example +1597 * binstrtobitstr("101") → "05a0" +1598 * binstrtobitstr("11001") → "03c8" +1599 * binstrtobitstr("101000001") → "07a080" +1600 * binstrtobitstr(101) → null // not number +1601 * binstrtobitstr("xyz") → null // not binary string +1602 */ +1603 function binstrtobitstr(s) { +1604 if (typeof s != "string") return null; +1605 if (s.match(/^[01]+$/) == null) return null; +1606 try { +1607 var n = parseInt(s, 2); +1608 return inttobitstr(n); +1609 } catch(ex) { +1610 return null; +1611 } +1612 } +1613 +1614 // ======================================================= +1615 /** +1616 * set class inheritance<br/> +1617 * @name extendClass +1618 * @function +1619 * @param {Function} subClass sub class to set inheritance +1620 * @param {Function} superClass super class to inherit +1621 * @since jsrsasign 10.3.0 base64x 1.1.21 +1622 * +1623 * @description +1624 * This function extends a class and set an inheritance +1625 * for member variables and methods. +1626 * +1627 * @example +1628 * var Animal = function() { +1629 * this.hello = function(){console.log("Hello")}; +1630 * this.name="Ani"; +1631 * }; +1632 * var Dog = function() { +1633 * Dog.superclass.constructor.call(this); +1634 * this.vow = function(){console.log("Vow wow")}; +1635 * this.tail=true; +1636 * }; +1637 * extendClass(Dog, Animal); +1638 */ +1639 function extendClass(subClass, superClass) { +1640 var F = function() {}; +1641 F.prototype = superClass.prototype; +1642 subClass.prototype = new F(); +1643 subClass.prototype.constructor = subClass; +1644 subClass.superclass = superClass.prototype; +1645 +1646 if (superClass.prototype.constructor == Object.prototype.constructor) { +1647 superClass.prototype.constructor = superClass; +1648 } +1649 }; +1650 +1651
diff --git a/api/symbols/src/crypto-1.1.js.html b/api/symbols/src/crypto-1.1.js.html index f4f8ceb4..7184e7f8 100644 --- a/api/symbols/src/crypto-1.1.js.html +++ b/api/symbols/src/crypto-1.1.js.html @@ -1527,4 +1527,4 @@ 1520 '608648016503040302': 'SHA256withDSA', // 2.16.840.1.101.3.4.3.2 1521 }; 1522 }; -1523 \ No newline at end of file +1523 diff --git a/api/symbols/src/dsa-2.0.js.html b/api/symbols/src/dsa-2.0.js.html index 5d7195e2..89a7fc8c 100644 --- a/api/symbols/src/dsa-2.0.js.html +++ b/api/symbols/src/dsa-2.0.js.html @@ -381,4 +381,4 @@ 374 this.setPublicHex(hP, hQ, hG, hY); 375 }; 376 } -377 \ No newline at end of file +377 diff --git a/api/symbols/src/ecdsa-modified-1.0.js.html b/api/symbols/src/ecdsa-modified-1.0.js.html index 04d5b49d..2f5e7d27 100644 --- a/api/symbols/src/ecdsa-modified-1.0.js.html +++ b/api/symbols/src/ecdsa-modified-1.0.js.html @@ -905,4 +905,4 @@ 898 899 900 -901 \ No newline at end of file +901 diff --git a/api/symbols/src/ecparam-1.0.js.html b/api/symbols/src/ecparam-1.0.js.html index b8c31671..9ecefea7 100644 --- a/api/symbols/src/ecparam-1.0.js.html +++ b/api/symbols/src/ecparam-1.0.js.html @@ -254,4 +254,4 @@ 247 "011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", // gy 248 ["NIST P-521", "P-521"]); // alias 249 -250 \ No newline at end of file +250 diff --git a/api/symbols/src/jws-3.3.js.html b/api/symbols/src/jws-3.3.js.html index 1925cf4e..dd002376 100644 --- a/api/symbols/src/jws-3.3.js.html +++ b/api/symbols/src/jws-3.3.js.html @@ -1096,4 +1096,4 @@ 1089 return year + mon + day + hour + min + sec + "Z"; 1090 }; 1091 -1092 \ No newline at end of file +1092 diff --git a/api/symbols/src/jwsjs-2.0.js.html b/api/symbols/src/jwsjs-2.0.js.html index a2332aec..d1da36b9 100644 --- a/api/symbols/src/jwsjs-2.0.js.html +++ b/api/symbols/src/jwsjs-2.0.js.html @@ -309,4 +309,4 @@ 302 }; 303 }; 304 -305 \ No newline at end of file +305 diff --git a/api/symbols/src/keyutil-1.0.js.html b/api/symbols/src/keyutil-1.0.js.html index c06d5934..896214b4 100644 --- a/api/symbols/src/keyutil-1.0.js.html +++ b/api/symbols/src/keyutil-1.0.js.html @@ -1935,4 +1935,4 @@ 1928 KEYUTIL.getJWKFromKey = function(keyObj) { 1929 return KEYUTIL.getJWK(keyObj, true, true, true, true); 1930 } -1931 \ No newline at end of file +1931 diff --git a/api/symbols/src/nodeutil-1.0.js.html b/api/symbols/src/nodeutil-1.0.js.html index 0b6f30f3..d351c94f 100644 --- a/api/symbols/src/nodeutil-1.0.js.html +++ b/api/symbols/src/nodeutil-1.0.js.html @@ -183,4 +183,4 @@ 176 console.log(s + JSON.stringify(json, null, " ")); 177 } 178 -179 \ No newline at end of file +179 diff --git a/api/symbols/src/rsapem-1.1.js.html b/api/symbols/src/rsapem-1.1.js.html index 3a9c10cb..6eb68f53 100644 --- a/api/symbols/src/rsapem-1.1.js.html +++ b/api/symbols/src/rsapem-1.1.js.html @@ -190,4 +190,4 @@ 183 hPub = x.getPublicKeyHex(); 184 this.readPKCS8PubKeyHex(hPub); 185 }; -186 \ No newline at end of file +186 diff --git a/api/symbols/src/rsasign-1.2.js.html b/api/symbols/src/rsasign-1.2.js.html index 3aa60c52..0df5debc 100644 --- a/api/symbols/src/rsasign-1.2.js.html +++ b/api/symbols/src/rsasign-1.2.js.html @@ -427,4 +427,4 @@ 420 * @class key of RSA public key algorithm 421 * @description Tom Wu's RSA Key class and extension 422 */ -423 \ No newline at end of file +423 diff --git a/api/symbols/src/x509-1.1.js.html b/api/symbols/src/x509-1.1.js.html index 98a82cd8..433c8932 100644 --- a/api/symbols/src/x509-1.1.js.html +++ b/api/symbols/src/x509-1.1.js.html @@ -3148,4 +3148,4 @@ 3141 "encipherOnly", 3142 "decipherOnly" 3143 ]; -3144 \ No newline at end of file +3144 diff --git a/api/symbols/src/x509crl.js.html b/api/symbols/src/x509crl.js.html index 3b6c7d4f..390ab5ac 100644 --- a/api/symbols/src/x509crl.js.html +++ b/api/symbols/src/x509crl.js.html @@ -514,4 +514,4 @@ 507 this._setPos(); 508 } 509 }; -510 \ No newline at end of file +510 diff --git a/bower.json b/bower.json index 6e4388bc..5bad284a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kjur-jsrsasign", - "version": "10.5.8", + "version": "10.5.9", "main": "jsrsasign-all-min.js", "description": "The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES, JWS and JWT in pure JavaScript.", "license": "MIT", diff --git a/jsrsasign-all-min.js b/jsrsasign-all-min.js index 65cb7c31..7a1dd596 100644 --- a/jsrsasign-all-min.js +++ b/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.5.8 (2022-02-25) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license + * jsrsasign(all) 10.5.9 (2022-03-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -223,9 +223,9 @@ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!K if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}if(typeof KJUR.asn1.cms=="undefined"||!KJUR.asn1.cms){KJUR.asn1.cms={}}KJUR.asn1.cms.Attribute=function(f){var e=Error,d=KJUR,c=d.asn1,b=c.DERSequence,a=c.DERSet,g=c.DERObjectIdentifier;this.params=null;this.typeOid=null;this.setByParam=function(h){this.params=h};this.getValueArray=function(){throw new e("not yet implemented abstract")};this.getEncodedHex=function(){var j=new g({oid:this.typeOid});var h=new a({array:this.getValueArray()});var i=new b({array:[j,h]});return i.getEncodedHex()}};extendClass(KJUR.asn1.cms.Attribute,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentType=function(c){var b=KJUR,a=b.asn1;a.cms.ContentType.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.3";this.getValueArray=function(){var d=new a.DERObjectIdentifier(this.params.type);return[d]};if(c!=undefined){this.setByParam(c)}};extendClass(KJUR.asn1.cms.ContentType,KJUR.asn1.cms.Attribute);KJUR.asn1.cms.MessageDigest=function(e){var b=KJUR,a=b.asn1,c=a.DEROctetString,d=a.cms;d.MessageDigest.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.4";this.getValueArray=function(){var f=new c(this.params);return[f]};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cms.MessageDigest,KJUR.asn1.cms.Attribute);KJUR.asn1.cms.SigningTime=function(c){var b=KJUR,a=b.asn1;a.cms.SigningTime.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.5";this.getValueArray=function(){var d=new a.x509.Time(this.params);return[d]};if(c!=undefined){this.setByParam(c)}};extendClass(KJUR.asn1.cms.SigningTime,KJUR.asn1.cms.Attribute);KJUR.asn1.cms.SigningCertificate=function(h){var e=Error,d=KJUR,c=d.asn1,b=c.DERSequence,g=c.cms,a=g.ESSCertID,f=d.crypto;g.SigningCertificate.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.12";this.getValueArray=function(){if(this.params==null||this.params==undefined||this.params.array==undefined){throw new e("parameter 'array' not specified")}var o=this.params.array;var k=[];for(var l=0;l0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;mf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--u){v=v.twice2D();v.z=f.ONE;if(t.testBit(u)){if(s.testBit(u)){v=v.add2D(y)}else{v=v.add2D(x)}}else{if(s.testBit(u)){v=v.add2D(w)}}}return v}this.getBigRandom=function(r){return new f(r.bitLength(),a).mod(r.subtract(f.ONE)).add(f.ONE)};this.setNamedCurve=function(r){this.ecparams=c.getByName(r);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=r};this.setPrivateKeyHex=function(r){this.isPrivate=true;this.prvKeyHex=r};this.setPublicKeyHex=function(r){this.isPublic=true;this.pubKeyHex=r};this.getPublicKeyXYHex=function(){var t=this.pubKeyHex;if(t.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var s=this.ecparams.keycharlen;if(t.length!==2+s*2){throw"malformed public key hex length"}var r={};r.x=t.substr(2,s);r.y=t.substr(2+s);return r};this.getShortNISTPCurveName=function(){var r=this.curveName;if(r==="secp256r1"||r==="NIST P-256"||r==="P-256"||r==="prime256v1"){return"P-256"}if(r==="secp384r1"||r==="NIST P-384"||r==="P-384"){return"P-384"}if(r==="secp521r1"||r==="NIST P-521"||r==="P-521"){return"P-521"}return null};this.generateKeyPairHex=function(){var s=this.ecparams.n;var u=this.getBigRandom(s);var r=this.ecparams.keycharlen;var t=("0000000000"+u.toString(16)).slice(-r);this.setPrivateKeyHex(t);var v=this.generatePublicKeyHex();return{ecprvhex:t,ecpubhex:v}};this.generatePublicKeyHex=function(){var u=new f(this.prvKeyHex,16);var w=this.ecparams.G.multiply(u);var t=w.getX().toBigInteger();var s=w.getY().toBigInteger();var r=this.ecparams.keycharlen;var y=("0000000000"+t.toString(16)).slice(-r);var v=("0000000000"+s.toString(16)).slice(-r);var x="04"+y+v;this.setPublicKeyHex(x);return x};this.signWithMessageHash=function(r){return this.signHex(r,this.prvKeyHex)};this.signHex=function(x,u){var A=new f(u,16);var v=this.ecparams.n;var z=new f(x.substring(0,this.ecparams.keycharlen),16);do{var w=this.getBigRandom(v);var B=this.ecparams.G;var y=B.multiply(w);var t=y.getX().toBigInteger().mod(v)}while(t.compareTo(f.ZERO)<=0);var C=w.modInverse(v).multiply(z.add(A.multiply(t))).mod(v);return m.biRSSigToASN1Sig(t,C)};this.sign=function(w,B){var z=B;var u=this.ecparams.n;var y=f.fromByteArrayUnsigned(w);do{var v=this.getBigRandom(u);var A=this.ecparams.G;var x=A.multiply(v);var t=x.getX().toBigInteger().mod(u)}while(t.compareTo(BigInteger.ZERO)<=0);var C=v.modInverse(u).multiply(y.add(z.multiply(t))).mod(u);return this.serializeSig(t,C)};this.verifyWithMessageHash=function(s,r){return this.verifyHex(s,r,this.pubKeyHex)};this.verifyHex=function(v,y,u){try{var t,B;var w=m.parseSigHex(y);t=w.r;B=w.s;var x=h.decodeFromHex(this.ecparams.curve,u);var z=new f(v.substring(0,this.ecparams.keycharlen),16);return this.verifyRaw(z,t,B,x)}catch(A){return false}};this.verify=function(z,A,u){var w,t;if(Bitcoin.Util.isArray(A)){var y=this.parseSig(A);w=y.r;t=y.s}else{if("object"===typeof A&&A.r&&A.s){w=A.r;t=A.s}else{throw"Invalid value for signature"}}var v;if(u instanceof ECPointFp){v=u}else{if(Bitcoin.Util.isArray(u)){v=h.decodeFrom(this.ecparams.curve,u)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var x=f.fromByteArrayUnsigned(z);return this.verifyRaw(x,w,t,v)};this.verifyRaw=function(z,t,E,y){var x=this.ecparams.n;var D=this.ecparams.G;if(t.compareTo(f.ONE)<0||t.compareTo(x)>=0){return false}if(E.compareTo(f.ONE)<0||E.compareTo(x)>=0){return false}var A=E.modInverse(x);var w=z.multiply(A).mod(x);var u=t.multiply(A).mod(x);var B=D.multiply(w).add(y.multiply(u));var C=B.getX().toBigInteger().mod(x);return C.equals(t)};this.serializeSig=function(v,u){var w=v.toByteArraySigned();var t=u.toByteArraySigned();var x=[];x.push(2);x.push(w.length);x=x.concat(w);x.push(2);x.push(t.length);x=x.concat(t);x.unshift(x.length);x.unshift(48);return x};this.parseSig=function(y){var x;if(y[0]!=48){throw new Error("Signature not a valid DERSequence")}x=2;if(y[x]!=2){throw new Error("First element in signature must be a DERInteger")}var w=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];if(y[x]!=2){throw new Error("Second element in signature must be a DERInteger")}var t=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];var v=f.fromByteArrayUnsigned(w);var u=f.fromByteArrayUnsigned(t);return{r:v,s:u}};this.parseSigCompact=function(w){if(w.length!==65){throw"Signature has the wrong length"}var t=w[0]-27;if(t<0||t>7){throw"Invalid signature type"}var x=this.ecparams.n;var v=f.fromByteArrayUnsigned(w.slice(1,33)).mod(x);var u=f.fromByteArrayUnsigned(w.slice(33,65)).mod(x);return{r:v,s:u,i:t}};this.readPKCS5PrvKeyHex=function(u){if(k(u)===false){throw new Error("not ASN.1 hex string")}var r,t,v;try{r=n(u,0,["[0]",0],"06");t=n(u,0,[1],"04");try{v=n(u,0,["[1]",0],"03")}catch(s){}}catch(s){throw new Error("malformed PKCS#1/5 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v);this.setPrivateKeyHex(t);this.isPublic=false};this.readPKCS8PrvKeyHex=function(v){if(k(v)===false){throw new j("not ASN.1 hex string")}var t,r,u,w;try{t=n(v,0,[1,0],"06");r=n(v,0,[1,1],"06");u=n(v,0,[2,0,1],"04");try{w=n(v,0,[2,0,"[1]",0],"03")}catch(s){}}catch(s){throw new j("malformed PKCS#8 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(w);this.setPrivateKeyHex(u);this.isPublic=false};this.readPKCS8PubKeyHex=function(u){if(k(u)===false){throw new j("not ASN.1 hex string")}var t,r,v;try{t=n(u,0,[0,0],"06");r=n(u,0,[0,1],"06");v=n(u,0,[1],"03")}catch(s){throw new j("malformed PKCS#8 ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v)};this.readCertPubKeyHex=function(t,v){if(k(t)===false){throw new j("not ASN.1 hex string")}var r,u;try{r=n(t,0,[0,5,0,1],"06");u=n(t,0,[0,5,1],"03")}catch(s){throw new j("malformed X.509 certificate ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(u)};if(e!==undefined){if(e.curve!==undefined){this.curveName=e.curve}}if(this.curveName===undefined){this.curveName=g}this.setNamedCurve(this.curveName);if(e!==undefined){if(e.prv!==undefined){this.setPrivateKeyHex(e.prv)}if(e.pub!==undefined){this.setPublicKeyHex(e.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(f){var j=ASN1HEX,i=j.getChildIdx,g=j.getV;j.checkStrictDER(f,0);if(f.substr(0,2)!="30"){throw new Error("signature is not a ASN.1 sequence")}var h=i(f,0);if(h.length!=2){throw new Error("signature shall have two elements")}var e=h[0];var d=h[1];if(f.substr(e,2)!="02"){throw new Error("1st item not ASN.1 integer")}if(f.substr(d,2)!="02"){throw new Error("2nd item not ASN.1 integer")}var c=g(f,e);var b=g(f,d);return{r:c,s:b}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(d){var e=KJUR.crypto.ECDSA.parseSigHexInHexRS(d);var b=e.r;var a=e.s;if(b.length>=130&&b.length<=134){if(b.length%2!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%2!=0){throw Error("unknown ECDSA sig s length error")}if(b.substr(0,2)=="00"){b=b.substr(2)}if(a.substr(0,2)=="00"){a=a.substr(2)}var c=Math.max(b.length,a.length);b=("000000"+b).slice(-c);a=("000000"+a).slice(-c);return b+a}if(b.substr(0,2)=="00"&&(b.length%32)==2){b=b.substr(2)}if(a.substr(0,2)=="00"&&(a.length%32)==2){a=a.substr(2)}if((b.length%32)==30){b="00"+b}if((a.length%32)==30){a="00"+a}if(b.length%32!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%32!=0){throw Error("unknown ECDSA sig s length error")}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if(a.length%4!=0){throw Error("unknown ECDSA concatinated r-s sig length error")}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(f,d){var c=KJUR.asn1;var b=new c.DERInteger({bigint:f});var a=new c.DERInteger({bigint:d});var e=new c.DERSequence({array:[b,a]});return e.getEncodedHex()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2b8104001f"){return"secp192k1"}if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040021"){return"secp224r1"}if(a==="2b81040022"){return"secp384r1"}if(a==="2b81040023"){return"secp521r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp224r1|NIST P-224|P-224|".indexOf(a)!==-1){return"secp224r1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}if("|secp521r1|NIST P-521|P-521|".indexOf(a)!==-1){return"secp521r1"}return null}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["keycharlen"]=Math.ceil(l/8)*2;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;v=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f0){var b=":"+n.join(":")+":";if(b.indexOf(":"+k+":")==-1){throw"algorithm '"+k+"' not accepted in the list"}}if(k!="none"&&B===null){throw"key shall be specified to verify."}if(typeof B=="string"&&B.indexOf("-----BEGIN ")!=-1){B=KEYUTIL.getKey(B)}if(z=="RS"||z=="PS"){if(!(B instanceof m)){throw"key shall be a RSAKey obj for RS* and PS* algs"}}if(z=="ES"){if(!(B instanceof p)){throw"key shall be a ECDSA obj for ES* algs"}}if(k=="none"){}var u=null;if(t.jwsalg2sigalg[l.alg]===undefined){throw"unsupported alg name: "+k}else{u=t.jwsalg2sigalg[k]}if(u=="none"){throw"not supported"}else{if(u.substr(0,4)=="Hmac"){var o=null;if(B===undefined){throw"hexadecimal key shall be specified for HMAC"}var j=new s({alg:u,pass:B});j.updateString(c);o=j.doFinal();return A==o}else{if(u.indexOf("withECDSA")!=-1){var h=null;try{h=p.concatSigToASN1Sig(A)}catch(v){return false}var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(h)}else{var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(A)}}}};KJUR.jws.JWS.parse=function(g){var c=g.split(".");var b={};var f,e,d;if(c.length!=2&&c.length!=3){throw"malformed sJWS: wrong number of '.' splitted elements"}f=c[0];e=c[1];if(c.length==3){d=c[2]}b.headerObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(f));b.payloadObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(e));b.headerPP=JSON.stringify(b.headerObj,null," ");if(b.payloadObj==null){b.payloadPP=b64utoutf8(e)}else{b.payloadPP=JSON.stringify(b.payloadObj,null," ")}if(d!==undefined){b.sigHex=b64utohex(d)}return b};KJUR.jws.JWS.verifyJWT=function(e,l,r){var d=KJUR,j=d.jws,o=j.JWS,n=o.readSafeJSONString,p=o.inArray,f=o.includedArray;var k=e.split(".");var c=k[0];var i=k[1];var q=c+"."+i;var m=b64utohex(k[2]);var h=n(b64utoutf8(c));var g=n(b64utoutf8(i));if(h.alg===undefined){return false}if(r.alg===undefined){throw"acceptField.alg shall be specified"}if(!p(h.alg,r.alg)){return false}if(g.iss!==undefined&&typeof r.iss==="object"){if(!p(g.iss,r.iss)){return false}}if(g.sub!==undefined&&typeof r.sub==="object"){if(!p(g.sub,r.sub)){return false}}if(g.aud!==undefined&&typeof r.aud==="object"){if(typeof g.aud=="string"){if(!p(g.aud,r.aud)){return false}}else{if(typeof g.aud=="object"){if(!f(g.aud,r.aud)){return false}}}}var b=j.IntDate.getNow();if(r.verifyAt!==undefined&&typeof r.verifyAt==="number"){b=r.verifyAt}if(r.gracePeriod===undefined||typeof r.gracePeriod!=="number"){r.gracePeriod=0}if(g.exp!==undefined&&typeof g.exp=="number"){if(g.exp+r.gracePeriod=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashHex(rstrtohex(d),c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{throw"Invalid RSA private key"}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;this.isPublic=false;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{throw"Invalid RSA private key in RSASetPrivateEx"}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);if(this.n.bitLength()==b){this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){if(b.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){if(e.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw new Error("ASN.1 length too long to represent by 8x: n = "+j.toString(16))}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.getEncodedHex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:o}}}else{return{"enum":parseInt(o,16)}}}else{if(A=="30"||A=="31"){j[c[A]]=r(v);return j}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(A)!=-1){var n=k(o);j[c[A]]={str:n};return j}else{if(A.match(/^8[0-9]$/)){var n=k(o);if(n==null|n==""|(n.match(/[\x00-\x1F\x7F-\x9F]/)!=null)|(n.match(/[\u0000-\u001F\u0080–\u009F]/)!=null)){return{tag:{tag:A,explicit:false,hex:o}}}else{return{tag:{tag:A,explicit:false,str:n}}}}else{if(A.match(/^a[0-9]$/)){try{if(!a(o)){throw"not encap"}return{tag:{tag:A,explicit:true,obj:f(o)}}}catch(x){return{tag:{tag:A,explicit:true,hex:o}}}}else{var y=new KJUR.asn1.ASN1Object();y.hV=o;var u=y.getLengthHexFromValue();return{asn1:{tlv:A+u+o}}}}}}}}}}}}}};ASN1HEX.isContextTag=function(c,b){c=c.toLowerCase();var f,e;try{f=parseInt(c,16)}catch(d){return -1}if(b===undefined){if((f&192)==128){return true}else{return false}}try{var a=b.match(/^\[[0-9]+\]$/);if(a==null){return false}e=parseInt(b.substr(1,b.length-1),10);if(e>31){return false}if(((f&192)==128)&&((f&31)==e)){return true}return false}catch(d){return false}};ASN1HEX.isASN1HEX=function(e){var d=ASN1HEX;if(e.length%2==1){return false}var c=d.getVblen(e,0);var b=e.substr(0,2);var f=d.getL(e,0);var a=e.length-b.length-f.length;if(a==c*2){return true}return false};ASN1HEX.checkStrictDER=function(g,o,d,c,r){var s=ASN1HEX;if(d===undefined){if(typeof g!="string"){throw new Error("not hex string")}g=g.toLowerCase();if(!KJUR.lang.String.isHex(g)){throw new Error("not hex string")}d=g.length;c=g.length/2;if(c<128){r=1}else{r=Math.ceil(c.toString(16))+1}}var k=s.getL(g,o);if(k.length>r*2){throw new Error("L of TLV too long: idx="+o)}var n=s.getVblen(g,o);if(n>c){throw new Error("value of L too long than hex: idx="+o)}var q=s.getTLV(g,o);var f=q.length-2-s.getL(g,o).length;if(f!==(n*2)){throw new Error("V string length and L's value not the same:"+f+"/"+(n*2))}if(o===0){if(g.length!=q.length){throw new Error("total length and TLV length unmatch:"+g.length+"!="+q.length)}}var b=g.substr(o,2);if(b==="02"){var a=s.getVidx(g,o);if(g.substr(a,2)=="00"&&g.charCodeAt(a+2)<56){throw new Error("not least zeros for DER INTEGER")}}if(parseInt(b,16)&32){var p=s.getVblen(g,o);var m=0;var l=s.getChildIdx(g,o);for(var e=0;ef.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f>24,(d&16711680)>>16,(d&65280)>>8,d&255]))));d+=1}return b}RSAKey.prototype.signPSS=function(e,a,d){var c=function(f){return KJUR.crypto.Util.hashHex(f,a)};var b=c(rstrtohex(e));if(d===undefined){d=-1}return this.signWithMessageHashPSS(b,a,d)};RSAKey.prototype.signWithMessageHashPSS=function(l,a,k){var b=hextorstr(l);var g=b.length;var m=this.n.bitLength()-1;var c=Math.ceil(m/8);var d;var o=function(i){return KJUR.crypto.Util.hashHex(i,a)};if(k===-1||k===undefined){k=g}else{if(k===-2){k=c-g-2}else{if(k<-2){throw new Error("invalid salt length")}}}if(c<(g+k+2)){throw new Error("data too long")}var f="";if(k>0){f=new Array(k);new SecureRandom().nextBytes(f);f=String.fromCharCode.apply(String,f)}var n=hextorstr(o(rstrtohex("\x00\x00\x00\x00\x00\x00\x00\x00"+b+f)));var j=[];for(d=0;d>(8*c-m))&255;q[0]&=~p;for(d=0;dk){return false}var j=this.doPublic(b);var i=j.toString(16);if(i.length+3!=k/4){return false}var e=i.replace(/^1f+00/,"");var g=_rsasign_getAlgNameAndHashFromHexDisgestInfo(e);if(g.length==0){return false}var d=g[0];var h=g[1];var a=function(m){return KJUR.crypto.Util.hashString(m,d)};var c=a(f);return(h==c)};RSAKey.prototype.verifyWithMessageHash=function(e,a){if(a.length!=Math.ceil(this.n.bitLength()/4)){return false}var b=parseBigInt(a,16);if(b.bitLength()>this.n.bitLength()){return 0}var h=this.doPublic(b);var g=h.toString(16).replace(/^1f+00/,"");var c=_rsasign_getAlgNameAndHashFromHexDisgestInfo(g);if(c.length==0){return false}var d=c[0];var f=c[1];return(f==e)};RSAKey.prototype.verifyPSS=function(c,b,a,f){var e=function(g){return KJUR.crypto.Util.hashHex(g,a)};var d=e(rstrtohex(c));if(f===undefined){f=-1}return this.verifyWithMessageHashPSS(d,b,a,f)};RSAKey.prototype.verifyWithMessageHashPSS=function(f,s,l,c){if(s.length!=Math.ceil(this.n.bitLength()/4)){return false}var k=new BigInteger(s,16);var r=function(i){return KJUR.crypto.Util.hashHex(i,l)};var j=hextorstr(f);var h=j.length;var g=this.n.bitLength()-1;var m=Math.ceil(g/8);var q;if(c===-1||c===undefined){c=h}else{if(c===-2){c=m-h-2}else{if(c<-2){throw new Error("invalid salt length")}}}if(m<(h+c+2)){throw new Error("data too long")}var a=this.doPublic(k).toByteArray();for(q=0;q>(8*m-g))&255;if((d.charCodeAt(0)&p)!==0){throw new Error("bits beyond keysize not zero")}var n=pss_mgf1_str(e,d.length,r);var o=[];for(q=0;qf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; \ No newline at end of file +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; \ No newline at end of file diff --git a/npm/lib/jsrsasign-all-min.js b/npm/lib/jsrsasign-all-min.js index 65cb7c31..7a1dd596 100644 --- a/npm/lib/jsrsasign-all-min.js +++ b/npm/lib/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.5.8 (2022-02-25) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license + * jsrsasign(all) 10.5.9 (2022-03-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -223,9 +223,9 @@ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!K if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}if(typeof KJUR.asn1.cms=="undefined"||!KJUR.asn1.cms){KJUR.asn1.cms={}}KJUR.asn1.cms.Attribute=function(f){var e=Error,d=KJUR,c=d.asn1,b=c.DERSequence,a=c.DERSet,g=c.DERObjectIdentifier;this.params=null;this.typeOid=null;this.setByParam=function(h){this.params=h};this.getValueArray=function(){throw new e("not yet implemented abstract")};this.getEncodedHex=function(){var j=new g({oid:this.typeOid});var h=new a({array:this.getValueArray()});var i=new b({array:[j,h]});return i.getEncodedHex()}};extendClass(KJUR.asn1.cms.Attribute,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentType=function(c){var b=KJUR,a=b.asn1;a.cms.ContentType.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.3";this.getValueArray=function(){var d=new a.DERObjectIdentifier(this.params.type);return[d]};if(c!=undefined){this.setByParam(c)}};extendClass(KJUR.asn1.cms.ContentType,KJUR.asn1.cms.Attribute);KJUR.asn1.cms.MessageDigest=function(e){var b=KJUR,a=b.asn1,c=a.DEROctetString,d=a.cms;d.MessageDigest.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.4";this.getValueArray=function(){var f=new c(this.params);return[f]};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cms.MessageDigest,KJUR.asn1.cms.Attribute);KJUR.asn1.cms.SigningTime=function(c){var b=KJUR,a=b.asn1;a.cms.SigningTime.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.5";this.getValueArray=function(){var d=new a.x509.Time(this.params);return[d]};if(c!=undefined){this.setByParam(c)}};extendClass(KJUR.asn1.cms.SigningTime,KJUR.asn1.cms.Attribute);KJUR.asn1.cms.SigningCertificate=function(h){var e=Error,d=KJUR,c=d.asn1,b=c.DERSequence,g=c.cms,a=g.ESSCertID,f=d.crypto;g.SigningCertificate.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.12";this.getValueArray=function(){if(this.params==null||this.params==undefined||this.params.array==undefined){throw new e("parameter 'array' not specified")}var o=this.params.array;var k=[];for(var l=0;l0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;mf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--u){v=v.twice2D();v.z=f.ONE;if(t.testBit(u)){if(s.testBit(u)){v=v.add2D(y)}else{v=v.add2D(x)}}else{if(s.testBit(u)){v=v.add2D(w)}}}return v}this.getBigRandom=function(r){return new f(r.bitLength(),a).mod(r.subtract(f.ONE)).add(f.ONE)};this.setNamedCurve=function(r){this.ecparams=c.getByName(r);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=r};this.setPrivateKeyHex=function(r){this.isPrivate=true;this.prvKeyHex=r};this.setPublicKeyHex=function(r){this.isPublic=true;this.pubKeyHex=r};this.getPublicKeyXYHex=function(){var t=this.pubKeyHex;if(t.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var s=this.ecparams.keycharlen;if(t.length!==2+s*2){throw"malformed public key hex length"}var r={};r.x=t.substr(2,s);r.y=t.substr(2+s);return r};this.getShortNISTPCurveName=function(){var r=this.curveName;if(r==="secp256r1"||r==="NIST P-256"||r==="P-256"||r==="prime256v1"){return"P-256"}if(r==="secp384r1"||r==="NIST P-384"||r==="P-384"){return"P-384"}if(r==="secp521r1"||r==="NIST P-521"||r==="P-521"){return"P-521"}return null};this.generateKeyPairHex=function(){var s=this.ecparams.n;var u=this.getBigRandom(s);var r=this.ecparams.keycharlen;var t=("0000000000"+u.toString(16)).slice(-r);this.setPrivateKeyHex(t);var v=this.generatePublicKeyHex();return{ecprvhex:t,ecpubhex:v}};this.generatePublicKeyHex=function(){var u=new f(this.prvKeyHex,16);var w=this.ecparams.G.multiply(u);var t=w.getX().toBigInteger();var s=w.getY().toBigInteger();var r=this.ecparams.keycharlen;var y=("0000000000"+t.toString(16)).slice(-r);var v=("0000000000"+s.toString(16)).slice(-r);var x="04"+y+v;this.setPublicKeyHex(x);return x};this.signWithMessageHash=function(r){return this.signHex(r,this.prvKeyHex)};this.signHex=function(x,u){var A=new f(u,16);var v=this.ecparams.n;var z=new f(x.substring(0,this.ecparams.keycharlen),16);do{var w=this.getBigRandom(v);var B=this.ecparams.G;var y=B.multiply(w);var t=y.getX().toBigInteger().mod(v)}while(t.compareTo(f.ZERO)<=0);var C=w.modInverse(v).multiply(z.add(A.multiply(t))).mod(v);return m.biRSSigToASN1Sig(t,C)};this.sign=function(w,B){var z=B;var u=this.ecparams.n;var y=f.fromByteArrayUnsigned(w);do{var v=this.getBigRandom(u);var A=this.ecparams.G;var x=A.multiply(v);var t=x.getX().toBigInteger().mod(u)}while(t.compareTo(BigInteger.ZERO)<=0);var C=v.modInverse(u).multiply(y.add(z.multiply(t))).mod(u);return this.serializeSig(t,C)};this.verifyWithMessageHash=function(s,r){return this.verifyHex(s,r,this.pubKeyHex)};this.verifyHex=function(v,y,u){try{var t,B;var w=m.parseSigHex(y);t=w.r;B=w.s;var x=h.decodeFromHex(this.ecparams.curve,u);var z=new f(v.substring(0,this.ecparams.keycharlen),16);return this.verifyRaw(z,t,B,x)}catch(A){return false}};this.verify=function(z,A,u){var w,t;if(Bitcoin.Util.isArray(A)){var y=this.parseSig(A);w=y.r;t=y.s}else{if("object"===typeof A&&A.r&&A.s){w=A.r;t=A.s}else{throw"Invalid value for signature"}}var v;if(u instanceof ECPointFp){v=u}else{if(Bitcoin.Util.isArray(u)){v=h.decodeFrom(this.ecparams.curve,u)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var x=f.fromByteArrayUnsigned(z);return this.verifyRaw(x,w,t,v)};this.verifyRaw=function(z,t,E,y){var x=this.ecparams.n;var D=this.ecparams.G;if(t.compareTo(f.ONE)<0||t.compareTo(x)>=0){return false}if(E.compareTo(f.ONE)<0||E.compareTo(x)>=0){return false}var A=E.modInverse(x);var w=z.multiply(A).mod(x);var u=t.multiply(A).mod(x);var B=D.multiply(w).add(y.multiply(u));var C=B.getX().toBigInteger().mod(x);return C.equals(t)};this.serializeSig=function(v,u){var w=v.toByteArraySigned();var t=u.toByteArraySigned();var x=[];x.push(2);x.push(w.length);x=x.concat(w);x.push(2);x.push(t.length);x=x.concat(t);x.unshift(x.length);x.unshift(48);return x};this.parseSig=function(y){var x;if(y[0]!=48){throw new Error("Signature not a valid DERSequence")}x=2;if(y[x]!=2){throw new Error("First element in signature must be a DERInteger")}var w=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];if(y[x]!=2){throw new Error("Second element in signature must be a DERInteger")}var t=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];var v=f.fromByteArrayUnsigned(w);var u=f.fromByteArrayUnsigned(t);return{r:v,s:u}};this.parseSigCompact=function(w){if(w.length!==65){throw"Signature has the wrong length"}var t=w[0]-27;if(t<0||t>7){throw"Invalid signature type"}var x=this.ecparams.n;var v=f.fromByteArrayUnsigned(w.slice(1,33)).mod(x);var u=f.fromByteArrayUnsigned(w.slice(33,65)).mod(x);return{r:v,s:u,i:t}};this.readPKCS5PrvKeyHex=function(u){if(k(u)===false){throw new Error("not ASN.1 hex string")}var r,t,v;try{r=n(u,0,["[0]",0],"06");t=n(u,0,[1],"04");try{v=n(u,0,["[1]",0],"03")}catch(s){}}catch(s){throw new Error("malformed PKCS#1/5 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v);this.setPrivateKeyHex(t);this.isPublic=false};this.readPKCS8PrvKeyHex=function(v){if(k(v)===false){throw new j("not ASN.1 hex string")}var t,r,u,w;try{t=n(v,0,[1,0],"06");r=n(v,0,[1,1],"06");u=n(v,0,[2,0,1],"04");try{w=n(v,0,[2,0,"[1]",0],"03")}catch(s){}}catch(s){throw new j("malformed PKCS#8 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(w);this.setPrivateKeyHex(u);this.isPublic=false};this.readPKCS8PubKeyHex=function(u){if(k(u)===false){throw new j("not ASN.1 hex string")}var t,r,v;try{t=n(u,0,[0,0],"06");r=n(u,0,[0,1],"06");v=n(u,0,[1],"03")}catch(s){throw new j("malformed PKCS#8 ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v)};this.readCertPubKeyHex=function(t,v){if(k(t)===false){throw new j("not ASN.1 hex string")}var r,u;try{r=n(t,0,[0,5,0,1],"06");u=n(t,0,[0,5,1],"03")}catch(s){throw new j("malformed X.509 certificate ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(u)};if(e!==undefined){if(e.curve!==undefined){this.curveName=e.curve}}if(this.curveName===undefined){this.curveName=g}this.setNamedCurve(this.curveName);if(e!==undefined){if(e.prv!==undefined){this.setPrivateKeyHex(e.prv)}if(e.pub!==undefined){this.setPublicKeyHex(e.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(f){var j=ASN1HEX,i=j.getChildIdx,g=j.getV;j.checkStrictDER(f,0);if(f.substr(0,2)!="30"){throw new Error("signature is not a ASN.1 sequence")}var h=i(f,0);if(h.length!=2){throw new Error("signature shall have two elements")}var e=h[0];var d=h[1];if(f.substr(e,2)!="02"){throw new Error("1st item not ASN.1 integer")}if(f.substr(d,2)!="02"){throw new Error("2nd item not ASN.1 integer")}var c=g(f,e);var b=g(f,d);return{r:c,s:b}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(d){var e=KJUR.crypto.ECDSA.parseSigHexInHexRS(d);var b=e.r;var a=e.s;if(b.length>=130&&b.length<=134){if(b.length%2!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%2!=0){throw Error("unknown ECDSA sig s length error")}if(b.substr(0,2)=="00"){b=b.substr(2)}if(a.substr(0,2)=="00"){a=a.substr(2)}var c=Math.max(b.length,a.length);b=("000000"+b).slice(-c);a=("000000"+a).slice(-c);return b+a}if(b.substr(0,2)=="00"&&(b.length%32)==2){b=b.substr(2)}if(a.substr(0,2)=="00"&&(a.length%32)==2){a=a.substr(2)}if((b.length%32)==30){b="00"+b}if((a.length%32)==30){a="00"+a}if(b.length%32!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%32!=0){throw Error("unknown ECDSA sig s length error")}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if(a.length%4!=0){throw Error("unknown ECDSA concatinated r-s sig length error")}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(f,d){var c=KJUR.asn1;var b=new c.DERInteger({bigint:f});var a=new c.DERInteger({bigint:d});var e=new c.DERSequence({array:[b,a]});return e.getEncodedHex()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2b8104001f"){return"secp192k1"}if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040021"){return"secp224r1"}if(a==="2b81040022"){return"secp384r1"}if(a==="2b81040023"){return"secp521r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp224r1|NIST P-224|P-224|".indexOf(a)!==-1){return"secp224r1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}if("|secp521r1|NIST P-521|P-521|".indexOf(a)!==-1){return"secp521r1"}return null}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["keycharlen"]=Math.ceil(l/8)*2;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;v=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f0){var b=":"+n.join(":")+":";if(b.indexOf(":"+k+":")==-1){throw"algorithm '"+k+"' not accepted in the list"}}if(k!="none"&&B===null){throw"key shall be specified to verify."}if(typeof B=="string"&&B.indexOf("-----BEGIN ")!=-1){B=KEYUTIL.getKey(B)}if(z=="RS"||z=="PS"){if(!(B instanceof m)){throw"key shall be a RSAKey obj for RS* and PS* algs"}}if(z=="ES"){if(!(B instanceof p)){throw"key shall be a ECDSA obj for ES* algs"}}if(k=="none"){}var u=null;if(t.jwsalg2sigalg[l.alg]===undefined){throw"unsupported alg name: "+k}else{u=t.jwsalg2sigalg[k]}if(u=="none"){throw"not supported"}else{if(u.substr(0,4)=="Hmac"){var o=null;if(B===undefined){throw"hexadecimal key shall be specified for HMAC"}var j=new s({alg:u,pass:B});j.updateString(c);o=j.doFinal();return A==o}else{if(u.indexOf("withECDSA")!=-1){var h=null;try{h=p.concatSigToASN1Sig(A)}catch(v){return false}var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(h)}else{var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(A)}}}};KJUR.jws.JWS.parse=function(g){var c=g.split(".");var b={};var f,e,d;if(c.length!=2&&c.length!=3){throw"malformed sJWS: wrong number of '.' splitted elements"}f=c[0];e=c[1];if(c.length==3){d=c[2]}b.headerObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(f));b.payloadObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(e));b.headerPP=JSON.stringify(b.headerObj,null," ");if(b.payloadObj==null){b.payloadPP=b64utoutf8(e)}else{b.payloadPP=JSON.stringify(b.payloadObj,null," ")}if(d!==undefined){b.sigHex=b64utohex(d)}return b};KJUR.jws.JWS.verifyJWT=function(e,l,r){var d=KJUR,j=d.jws,o=j.JWS,n=o.readSafeJSONString,p=o.inArray,f=o.includedArray;var k=e.split(".");var c=k[0];var i=k[1];var q=c+"."+i;var m=b64utohex(k[2]);var h=n(b64utoutf8(c));var g=n(b64utoutf8(i));if(h.alg===undefined){return false}if(r.alg===undefined){throw"acceptField.alg shall be specified"}if(!p(h.alg,r.alg)){return false}if(g.iss!==undefined&&typeof r.iss==="object"){if(!p(g.iss,r.iss)){return false}}if(g.sub!==undefined&&typeof r.sub==="object"){if(!p(g.sub,r.sub)){return false}}if(g.aud!==undefined&&typeof r.aud==="object"){if(typeof g.aud=="string"){if(!p(g.aud,r.aud)){return false}}else{if(typeof g.aud=="object"){if(!f(g.aud,r.aud)){return false}}}}var b=j.IntDate.getNow();if(r.verifyAt!==undefined&&typeof r.verifyAt==="number"){b=r.verifyAt}if(r.gracePeriod===undefined||typeof r.gracePeriod!=="number"){r.gracePeriod=0}if(g.exp!==undefined&&typeof g.exp=="number"){if(g.exp+r.gracePeriod=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashHex(rstrtohex(d),c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{throw"Invalid RSA private key"}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;this.isPublic=false;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{throw"Invalid RSA private key in RSASetPrivateEx"}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);if(this.n.bitLength()==b){this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){if(b.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){if(e.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw new Error("ASN.1 length too long to represent by 8x: n = "+j.toString(16))}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.getEncodedHex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:o}}}else{return{"enum":parseInt(o,16)}}}else{if(A=="30"||A=="31"){j[c[A]]=r(v);return j}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(A)!=-1){var n=k(o);j[c[A]]={str:n};return j}else{if(A.match(/^8[0-9]$/)){var n=k(o);if(n==null|n==""|(n.match(/[\x00-\x1F\x7F-\x9F]/)!=null)|(n.match(/[\u0000-\u001F\u0080–\u009F]/)!=null)){return{tag:{tag:A,explicit:false,hex:o}}}else{return{tag:{tag:A,explicit:false,str:n}}}}else{if(A.match(/^a[0-9]$/)){try{if(!a(o)){throw"not encap"}return{tag:{tag:A,explicit:true,obj:f(o)}}}catch(x){return{tag:{tag:A,explicit:true,hex:o}}}}else{var y=new KJUR.asn1.ASN1Object();y.hV=o;var u=y.getLengthHexFromValue();return{asn1:{tlv:A+u+o}}}}}}}}}}}}}};ASN1HEX.isContextTag=function(c,b){c=c.toLowerCase();var f,e;try{f=parseInt(c,16)}catch(d){return -1}if(b===undefined){if((f&192)==128){return true}else{return false}}try{var a=b.match(/^\[[0-9]+\]$/);if(a==null){return false}e=parseInt(b.substr(1,b.length-1),10);if(e>31){return false}if(((f&192)==128)&&((f&31)==e)){return true}return false}catch(d){return false}};ASN1HEX.isASN1HEX=function(e){var d=ASN1HEX;if(e.length%2==1){return false}var c=d.getVblen(e,0);var b=e.substr(0,2);var f=d.getL(e,0);var a=e.length-b.length-f.length;if(a==c*2){return true}return false};ASN1HEX.checkStrictDER=function(g,o,d,c,r){var s=ASN1HEX;if(d===undefined){if(typeof g!="string"){throw new Error("not hex string")}g=g.toLowerCase();if(!KJUR.lang.String.isHex(g)){throw new Error("not hex string")}d=g.length;c=g.length/2;if(c<128){r=1}else{r=Math.ceil(c.toString(16))+1}}var k=s.getL(g,o);if(k.length>r*2){throw new Error("L of TLV too long: idx="+o)}var n=s.getVblen(g,o);if(n>c){throw new Error("value of L too long than hex: idx="+o)}var q=s.getTLV(g,o);var f=q.length-2-s.getL(g,o).length;if(f!==(n*2)){throw new Error("V string length and L's value not the same:"+f+"/"+(n*2))}if(o===0){if(g.length!=q.length){throw new Error("total length and TLV length unmatch:"+g.length+"!="+q.length)}}var b=g.substr(o,2);if(b==="02"){var a=s.getVidx(g,o);if(g.substr(a,2)=="00"&&g.charCodeAt(a+2)<56){throw new Error("not least zeros for DER INTEGER")}}if(parseInt(b,16)&32){var p=s.getVblen(g,o);var m=0;var l=s.getChildIdx(g,o);for(var e=0;ef.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f>24,(d&16711680)>>16,(d&65280)>>8,d&255]))));d+=1}return b}RSAKey.prototype.signPSS=function(e,a,d){var c=function(f){return KJUR.crypto.Util.hashHex(f,a)};var b=c(rstrtohex(e));if(d===undefined){d=-1}return this.signWithMessageHashPSS(b,a,d)};RSAKey.prototype.signWithMessageHashPSS=function(l,a,k){var b=hextorstr(l);var g=b.length;var m=this.n.bitLength()-1;var c=Math.ceil(m/8);var d;var o=function(i){return KJUR.crypto.Util.hashHex(i,a)};if(k===-1||k===undefined){k=g}else{if(k===-2){k=c-g-2}else{if(k<-2){throw new Error("invalid salt length")}}}if(c<(g+k+2)){throw new Error("data too long")}var f="";if(k>0){f=new Array(k);new SecureRandom().nextBytes(f);f=String.fromCharCode.apply(String,f)}var n=hextorstr(o(rstrtohex("\x00\x00\x00\x00\x00\x00\x00\x00"+b+f)));var j=[];for(d=0;d>(8*c-m))&255;q[0]&=~p;for(d=0;dk){return false}var j=this.doPublic(b);var i=j.toString(16);if(i.length+3!=k/4){return false}var e=i.replace(/^1f+00/,"");var g=_rsasign_getAlgNameAndHashFromHexDisgestInfo(e);if(g.length==0){return false}var d=g[0];var h=g[1];var a=function(m){return KJUR.crypto.Util.hashString(m,d)};var c=a(f);return(h==c)};RSAKey.prototype.verifyWithMessageHash=function(e,a){if(a.length!=Math.ceil(this.n.bitLength()/4)){return false}var b=parseBigInt(a,16);if(b.bitLength()>this.n.bitLength()){return 0}var h=this.doPublic(b);var g=h.toString(16).replace(/^1f+00/,"");var c=_rsasign_getAlgNameAndHashFromHexDisgestInfo(g);if(c.length==0){return false}var d=c[0];var f=c[1];return(f==e)};RSAKey.prototype.verifyPSS=function(c,b,a,f){var e=function(g){return KJUR.crypto.Util.hashHex(g,a)};var d=e(rstrtohex(c));if(f===undefined){f=-1}return this.verifyWithMessageHashPSS(d,b,a,f)};RSAKey.prototype.verifyWithMessageHashPSS=function(f,s,l,c){if(s.length!=Math.ceil(this.n.bitLength()/4)){return false}var k=new BigInteger(s,16);var r=function(i){return KJUR.crypto.Util.hashHex(i,l)};var j=hextorstr(f);var h=j.length;var g=this.n.bitLength()-1;var m=Math.ceil(g/8);var q;if(c===-1||c===undefined){c=h}else{if(c===-2){c=m-h-2}else{if(c<-2){throw new Error("invalid salt length")}}}if(m<(h+c+2)){throw new Error("data too long")}var a=this.doPublic(k).toByteArray();for(q=0;q>(8*m-g))&255;if((d.charCodeAt(0)&p)!==0){throw new Error("bits beyond keysize not zero")}var n=pss_mgf1_str(e,d.length,r);var o=[];for(q=0;q0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;mf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--u){v=v.twice2D();v.z=f.ONE;if(t.testBit(u)){if(s.testBit(u)){v=v.add2D(y)}else{v=v.add2D(x)}}else{if(s.testBit(u)){v=v.add2D(w)}}}return v}this.getBigRandom=function(r){return new f(r.bitLength(),a).mod(r.subtract(f.ONE)).add(f.ONE)};this.setNamedCurve=function(r){this.ecparams=c.getByName(r);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=r};this.setPrivateKeyHex=function(r){this.isPrivate=true;this.prvKeyHex=r};this.setPublicKeyHex=function(r){this.isPublic=true;this.pubKeyHex=r};this.getPublicKeyXYHex=function(){var t=this.pubKeyHex;if(t.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var s=this.ecparams.keycharlen;if(t.length!==2+s*2){throw"malformed public key hex length"}var r={};r.x=t.substr(2,s);r.y=t.substr(2+s);return r};this.getShortNISTPCurveName=function(){var r=this.curveName;if(r==="secp256r1"||r==="NIST P-256"||r==="P-256"||r==="prime256v1"){return"P-256"}if(r==="secp384r1"||r==="NIST P-384"||r==="P-384"){return"P-384"}if(r==="secp521r1"||r==="NIST P-521"||r==="P-521"){return"P-521"}return null};this.generateKeyPairHex=function(){var s=this.ecparams.n;var u=this.getBigRandom(s);var r=this.ecparams.keycharlen;var t=("0000000000"+u.toString(16)).slice(-r);this.setPrivateKeyHex(t);var v=this.generatePublicKeyHex();return{ecprvhex:t,ecpubhex:v}};this.generatePublicKeyHex=function(){var u=new f(this.prvKeyHex,16);var w=this.ecparams.G.multiply(u);var t=w.getX().toBigInteger();var s=w.getY().toBigInteger();var r=this.ecparams.keycharlen;var y=("0000000000"+t.toString(16)).slice(-r);var v=("0000000000"+s.toString(16)).slice(-r);var x="04"+y+v;this.setPublicKeyHex(x);return x};this.signWithMessageHash=function(r){return this.signHex(r,this.prvKeyHex)};this.signHex=function(x,u){var A=new f(u,16);var v=this.ecparams.n;var z=new f(x.substring(0,this.ecparams.keycharlen),16);do{var w=this.getBigRandom(v);var B=this.ecparams.G;var y=B.multiply(w);var t=y.getX().toBigInteger().mod(v)}while(t.compareTo(f.ZERO)<=0);var C=w.modInverse(v).multiply(z.add(A.multiply(t))).mod(v);return m.biRSSigToASN1Sig(t,C)};this.sign=function(w,B){var z=B;var u=this.ecparams.n;var y=f.fromByteArrayUnsigned(w);do{var v=this.getBigRandom(u);var A=this.ecparams.G;var x=A.multiply(v);var t=x.getX().toBigInteger().mod(u)}while(t.compareTo(BigInteger.ZERO)<=0);var C=v.modInverse(u).multiply(y.add(z.multiply(t))).mod(u);return this.serializeSig(t,C)};this.verifyWithMessageHash=function(s,r){return this.verifyHex(s,r,this.pubKeyHex)};this.verifyHex=function(v,y,u){try{var t,B;var w=m.parseSigHex(y);t=w.r;B=w.s;var x=h.decodeFromHex(this.ecparams.curve,u);var z=new f(v.substring(0,this.ecparams.keycharlen),16);return this.verifyRaw(z,t,B,x)}catch(A){return false}};this.verify=function(z,A,u){var w,t;if(Bitcoin.Util.isArray(A)){var y=this.parseSig(A);w=y.r;t=y.s}else{if("object"===typeof A&&A.r&&A.s){w=A.r;t=A.s}else{throw"Invalid value for signature"}}var v;if(u instanceof ECPointFp){v=u}else{if(Bitcoin.Util.isArray(u)){v=h.decodeFrom(this.ecparams.curve,u)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var x=f.fromByteArrayUnsigned(z);return this.verifyRaw(x,w,t,v)};this.verifyRaw=function(z,t,E,y){var x=this.ecparams.n;var D=this.ecparams.G;if(t.compareTo(f.ONE)<0||t.compareTo(x)>=0){return false}if(E.compareTo(f.ONE)<0||E.compareTo(x)>=0){return false}var A=E.modInverse(x);var w=z.multiply(A).mod(x);var u=t.multiply(A).mod(x);var B=D.multiply(w).add(y.multiply(u));var C=B.getX().toBigInteger().mod(x);return C.equals(t)};this.serializeSig=function(v,u){var w=v.toByteArraySigned();var t=u.toByteArraySigned();var x=[];x.push(2);x.push(w.length);x=x.concat(w);x.push(2);x.push(t.length);x=x.concat(t);x.unshift(x.length);x.unshift(48);return x};this.parseSig=function(y){var x;if(y[0]!=48){throw new Error("Signature not a valid DERSequence")}x=2;if(y[x]!=2){throw new Error("First element in signature must be a DERInteger")}var w=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];if(y[x]!=2){throw new Error("Second element in signature must be a DERInteger")}var t=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];var v=f.fromByteArrayUnsigned(w);var u=f.fromByteArrayUnsigned(t);return{r:v,s:u}};this.parseSigCompact=function(w){if(w.length!==65){throw"Signature has the wrong length"}var t=w[0]-27;if(t<0||t>7){throw"Invalid signature type"}var x=this.ecparams.n;var v=f.fromByteArrayUnsigned(w.slice(1,33)).mod(x);var u=f.fromByteArrayUnsigned(w.slice(33,65)).mod(x);return{r:v,s:u,i:t}};this.readPKCS5PrvKeyHex=function(u){if(k(u)===false){throw new Error("not ASN.1 hex string")}var r,t,v;try{r=n(u,0,["[0]",0],"06");t=n(u,0,[1],"04");try{v=n(u,0,["[1]",0],"03")}catch(s){}}catch(s){throw new Error("malformed PKCS#1/5 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v);this.setPrivateKeyHex(t);this.isPublic=false};this.readPKCS8PrvKeyHex=function(v){if(k(v)===false){throw new j("not ASN.1 hex string")}var t,r,u,w;try{t=n(v,0,[1,0],"06");r=n(v,0,[1,1],"06");u=n(v,0,[2,0,1],"04");try{w=n(v,0,[2,0,"[1]",0],"03")}catch(s){}}catch(s){throw new j("malformed PKCS#8 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(w);this.setPrivateKeyHex(u);this.isPublic=false};this.readPKCS8PubKeyHex=function(u){if(k(u)===false){throw new j("not ASN.1 hex string")}var t,r,v;try{t=n(u,0,[0,0],"06");r=n(u,0,[0,1],"06");v=n(u,0,[1],"03")}catch(s){throw new j("malformed PKCS#8 ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v)};this.readCertPubKeyHex=function(t,v){if(k(t)===false){throw new j("not ASN.1 hex string")}var r,u;try{r=n(t,0,[0,5,0,1],"06");u=n(t,0,[0,5,1],"03")}catch(s){throw new j("malformed X.509 certificate ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(u)};if(e!==undefined){if(e.curve!==undefined){this.curveName=e.curve}}if(this.curveName===undefined){this.curveName=g}this.setNamedCurve(this.curveName);if(e!==undefined){if(e.prv!==undefined){this.setPrivateKeyHex(e.prv)}if(e.pub!==undefined){this.setPublicKeyHex(e.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(f){var j=ASN1HEX,i=j.getChildIdx,g=j.getV;j.checkStrictDER(f,0);if(f.substr(0,2)!="30"){throw new Error("signature is not a ASN.1 sequence")}var h=i(f,0);if(h.length!=2){throw new Error("signature shall have two elements")}var e=h[0];var d=h[1];if(f.substr(e,2)!="02"){throw new Error("1st item not ASN.1 integer")}if(f.substr(d,2)!="02"){throw new Error("2nd item not ASN.1 integer")}var c=g(f,e);var b=g(f,d);return{r:c,s:b}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(d){var e=KJUR.crypto.ECDSA.parseSigHexInHexRS(d);var b=e.r;var a=e.s;if(b.length>=130&&b.length<=134){if(b.length%2!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%2!=0){throw Error("unknown ECDSA sig s length error")}if(b.substr(0,2)=="00"){b=b.substr(2)}if(a.substr(0,2)=="00"){a=a.substr(2)}var c=Math.max(b.length,a.length);b=("000000"+b).slice(-c);a=("000000"+a).slice(-c);return b+a}if(b.substr(0,2)=="00"&&(b.length%32)==2){b=b.substr(2)}if(a.substr(0,2)=="00"&&(a.length%32)==2){a=a.substr(2)}if((b.length%32)==30){b="00"+b}if((a.length%32)==30){a="00"+a}if(b.length%32!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%32!=0){throw Error("unknown ECDSA sig s length error")}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if(a.length%4!=0){throw Error("unknown ECDSA concatinated r-s sig length error")}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(f,d){var c=KJUR.asn1;var b=new c.DERInteger({bigint:f});var a=new c.DERInteger({bigint:d});var e=new c.DERSequence({array:[b,a]});return e.getEncodedHex()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2b8104001f"){return"secp192k1"}if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040021"){return"secp224r1"}if(a==="2b81040022"){return"secp384r1"}if(a==="2b81040023"){return"secp521r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp224r1|NIST P-224|P-224|".indexOf(a)!==-1){return"secp224r1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}if("|secp521r1|NIST P-521|P-521|".indexOf(a)!==-1){return"secp521r1"}return null}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["keycharlen"]=Math.ceil(l/8)*2;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;vMIT License */ @@ -624,7 +624,7 @@ function zulutomsec(s) { } return Date.UTC(year, month, day, hour, min, sec, msec); } - throw "unsupported zulu format: " + s; + throw new Error("unsupported zulu format: " + s); } /** @@ -647,8 +647,7 @@ function zulutomsec(s) { * zulutosec("20071231235959Z") → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT */ function zulutosec(s) { - var msec = zulutomsec(s); - return ~~(msec / 1000); + return Math.round(zulutomsec(s) / 1000.0); } // ==== zulu / Date ================================= diff --git a/test/qunit-do-base64x.html b/test/qunit-do-base64x.html index a9527d5f..b4e3c82e 100755 --- a/test/qunit-do-base64x.html +++ b/test/qunit-do-base64x.html @@ -180,6 +180,8 @@ equal(zulutosec("931231235959Z"), 757382399, "931231235959.345Z"); equal(zulutosec("20071231235959Z"), 1199145599, "20071231235959.345Z"); equal(zulutosec("561231235959Z"), -410227201, "561231235959Z"); +equal(zulutosec("401231235959Z"), 2240611199, "401231235959Z"); +equal(zulutosec("401231235959.8Z"), 2240611200, "401231235959.8Z"); }); test("zulutodate", function() {