From 2f7222e6123c8a5939b4b3397611bf673acfa3ec Mon Sep 17 00:00:00 2001 From: Kenji Urushima Date: Thu, 10 Mar 2022 20:00:53 +0900 Subject: [PATCH] 10.5.10 release --- ChangeLog.txt | 9 +- Makefile | 4 + api/files.html | 2 +- api/symbols/global__.html | 6 +- api/symbols/src/base64x-1.1.js.html | 1676 ++++++++++++++------------- bower.json | 2 +- jsrsasign-all-min.js | 4 +- jsrsasign-jwths-min.js | 4 +- jsrsasign-rsa-min.js | 4 +- min/base64x-1.1.min.js | 2 +- npm/lib/jsrsasign-all-min.js | 4 +- npm/lib/jsrsasign-jwths-min.js | 4 +- npm/lib/jsrsasign-rsa-min.js | 4 +- npm/lib/jsrsasign.js | 4 +- npm/package.json | 2 +- src/base64x-1.1.js | 60 +- test/qunit-do-base64x.html | 28 +- 17 files changed, 920 insertions(+), 899 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 79e64b16..bca0276f 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,8 +1,15 @@ ChangeLog for jsrsasign +hextoipv6 fix +* Changes from 10.5.9 to 10.5.10 (2022-Mar-10) + - src/base64x.js + - fix hextoipv6 for shrinking leading zeros (#536) + - test/qunit-do-base64x.html + - test case added for above updates. + small fix -* Changes from 10.5.8 to 10.5.9 version +* Changes from 10.5.8 to 10.5.9 (2022-Mar-10) - src/base64x.js - fix zulutosec (#538) - src/asn1csr.js diff --git a/Makefile b/Makefile index 893473fe..f890ab3d 100644 --- a/Makefile +++ b/Makefile @@ -94,13 +94,17 @@ gitadd: gitadd-all-doc gitadd-release @echo done rsync-test: + rsync -n -av api/ ../../_gitpg/jsrsasign/api 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 api/ ../../_gitpg/jsrsasign/api 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 +bbb: + diff --git a/api/files.html b/api/files.html index c31e6dd2..5eb32bde 100644 --- a/api/files.html +++ b/api/files.html @@ -677,7 +677,7 @@

base64x-1.1.js

Version:
-
jsrsasign 10.5.9 base64x 1.1.22 (2022-Mar-10)
+
jsrsasign 10.5.10 base64x 1.1.23 (2022-Mar-10)
diff --git a/api/symbols/global__.html b/api/symbols/global__.html index 08da4c7a..f6894741 100644 --- a/api/symbols/global__.html +++ b/api/symbols/global__.html @@ -2449,9 +2449,9 @@

-
hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
-hextoip("871020010db8000000000000000000") &rarr raise exception
-hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception
+
hextoipv6("871020010db8000000000000000000000004") &rarr "2001:db8::4"
+hextoipv6("871020010db8000000000000000000") &rarr raise exception
+hextoipv6("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception
diff --git a/api/symbols/src/base64x-1.1.js.html b/api/symbols/src/base64x-1.1.js.html index 72b62edd..540bd159 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.22 (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* base64x-1.1.23 (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.9 base64x 1.1.22 (2022-Mar-10)
+ 19  * @version jsrsasign 10.5.10 base64x 1.1.23 (2022-Mar-10)
  20  * @since jsrsasign 2.1
  21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  22  */
@@ -807,852 +807,854 @@
 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
+803  * hextoipv6("871020010db8000000000000000000000004") &rarr "2001:db8::4"
+804  * hextoipv6("871020010db8000000000000000000") &rarr raise exception
+805  * hextoipv6("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception
 806  */
 807 function hextoipv6(s) {
-808   if (! s.match(/^[0-9A-Fa-f]{32}$/))
-809     throw "malformed IPv6 address octet";
+808     if (! s.match(/^[0-9A-Fa-f]{32}$/))
+809 	throw new Error("malformed IPv6 address: " + s);
 810 
-811   // 1. downcase
-812   s = s.toLowerCase();
+811     // 1. downcase
+812     s = s.toLowerCase();
 813 
-814   // 2. split 4
-815   var a = s.match(/.{1,4}/g);
+814     // 2. split 4 > ["0123", "00a4", "0000", ..., "ffff"]
+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 =================================
+817     // 3. trim leading 0 for items and join > "123:a4:0:...:ffff"
+818     a = a.map(function(s){s.replace(/^0+/, '')});
+819     a = a.map(function(s){s == '' ? '0' : s});
+820     s = ':' + a.join(':') + ':';
+821 
+822     // 4. find shrinkable candidates :0:0:..:0:
+823     var aZero = s.match(/:(0:){2,}/g);
+824 
+825     // 5. no shrinkable
+826     if (aZero == null) return s.slice(1, -1);
+827 
+828     // 6. fix max length zero(:0:...:0:)
+829     var sMaxZero = aZero.sort().slice(-1)[0];
+830 
+831     // 7. replace shrinked
+832     s = s.replace(sMaxZero.substr(0, sMaxZero.length - 1), ':');
+833 
+834     // 8. trim leading ':' if not '::'
+835     if (s.substr(0, 2) != '::') s = s.substr(1);
+836 
+837     // 9. trim tail ':' if not '::'
+838     if (s.substr(-2, 2) != '::') s = s.substr(0, s.length - 1);
+839 
+840     return s;
+841 }
 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 ==============================
+843 // ==== hex / ip =================================
+844 
+845 /**
+846  * convert a hexadecimal string to IP addresss<br/>
+847  * @name hextoip
+848  * @function
+849  * @param {String} s hexadecimal string of IP address
+850  * @return {String} IP address string
+851  * @since jsrsasign 8.0.10 base64x 1.1.13
+852  * @description
+853  * This function converts a hexadecimal string of IPv4 or 
+854  * IPv6 address to IPv4 or IPv6 address string.
+855  * If byte length is not 4 nor 16, this returns a
+856  * hexadecimal string without conversion.
+857  * @see {@link hextoipv6}
+858  * @example
+859  * hextoip("c0a80101") &rarr "192.168.1.1"
+860  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
+861  * hextoip("c0a801010203") &rarr "c0a801010203" // 6 bytes
+862  * hextoip("zzz")) &rarr raise exception because of not hexadecimal
+863  */
+864 function hextoip(s) {
+865   var malformedMsg = "malformed hex value";
+866   if (! s.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))
+867     throw malformedMsg;
+868   if (s.length == 8) { // ipv4
+869     var ip;
+870     try {
+871       ip = parseInt(s.substr(0, 2), 16) + "." +
+872            parseInt(s.substr(2, 2), 16) + "." +
+873            parseInt(s.substr(4, 2), 16) + "." +
+874            parseInt(s.substr(6, 2), 16);
+875       return ip;
+876     } catch (ex) {
+877       throw malformedMsg;
+878     }
+879   } else if (s.length == 32) {
+880     return hextoipv6(s);
+881   } else {
+882     return s;
+883   }
+884 }
+885 
+886 /**
+887  * convert IPv4/v6 addresss to a hexadecimal string<br/>
+888  * @name iptohex
+889  * @function
+890  * @param {String} s IPv4/v6 address string
+891  * @return {String} hexadecimal string of IP address
+892  * @since jsrsasign 8.0.12 base64x 1.1.14
+893  * @description
+894  * This function converts IPv4 or IPv6 address string to
+895  * a hexadecimal string of IPv4 or IPv6 address.
+896  * @example
+897  * iptohex("192.168.1.1") &rarr "c0a80101"
+898  * iptohex("2001:db8::4") &rarr "871020010db8000000000000000000000004"
+899  * iptohex("zzz")) &rarr raise exception
+900  */
+901 function iptohex(s) {
+902   var malformedMsg = "malformed IP address";
+903   s = s.toLowerCase(s);
+904 
+905   if (s.match(/^[0-9.]+$/)) {
+906     var a = s.split(".");
+907     if (a.length !== 4) throw malformedMsg;
+908     var hex = "";
+909     try {
+910       for (var i = 0; i < 4; i++) {
+911         var d = parseInt(a[i]);
+912         hex += ("0" + d.toString(16)).slice(-2);
+913       }
+914       return hex;
+915     } catch(ex) {
+916       throw malformedMsg;
+917     }
+918   } else if (s.match(/^[0-9a-f:]+$/) && s.indexOf(":") !== -1) {
+919     return ipv6tohex(s);
+920   } else {
+921     throw malformedMsg;
+922   }
+923 }
 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 ===================
+925 // ==== ucs2hex / utf8 ==============================
+926 
+927 /**
+928  * convert UCS-2 hexadecimal stirng to UTF-8 string<br/>
+929  * @name ucs2hextoutf8
+930  * @function
+931  * @param {String} s hexadecimal string of UCS-2 string (ex. "0066")
+932  * @return {String} UTF-8 string
+933  * @since jsrsasign 10.1.13 base64x 1.1.20
+934  * @description
+935  * This function converts hexadecimal value of UCS-2 string to 
+936  * UTF-8 string.
+937  * @example
+938  * ucs2hextoutf8("006600fc0072") &rarr "für"
+939  */
+940 /*
+941 See: http://nomenclator.la.coocan.jp/unicode/ucs_utf.htm
+942 UCS-2 to UTF-8
+943 UCS-2 code point | UCS-2 bytes       | UTF-8 bytes
+944 U+0000 .. U+007F | 00000000-0xxxxxxx | 0xxxxxxx (1 byte)
+945 U+0080 .. U+07FF | 00000xxx-xxyyyyyy | 110xxxxx 10yyyyyy (2 byte)
+946 U+0800 .. U+FFFF | xxxxyyyy-yyzzzzzz | 1110xxxx 10yyyyyy 10zzzzzz (3 byte)
+947  */
+948 function ucs2hextoutf8(s) {
+949     function _conv(s) {
+950 	var i1 = parseInt(s.substr(0, 2), 16);
+951 	var i2 = parseInt(s.substr(2), 16);
+952 	if (i1 == 0 & i2 < 0x80) { // 1 byte
+953 	    return String.fromCharCode(i2);
+954 	}
+955 	if (i1 < 8) { // 2 bytes
+956 	    var u1 = 0xc0 | ((i1 & 0x07) << 3) | ((i2 & 0xc0) >> 6);
+957 	    var u2 = 0x80 | (i2 & 0x3f);
+958 	    return hextoutf8(u1.toString(16) + u2.toString(16));
+959 	}
+960 	// 3 bytes
+961 	var u1 = 0xe0 | ((i1 & 0xf0) >> 4);
+962 	var u2 = 0x80 | ((i1 & 0x0f) << 2) | ((i2 & 0xc0) >> 6);
+963 	var u3 = 0x80 | (i2 & 0x3f);
+964 	return hextoutf8(u1.toString(16) + u2.toString(16) + u3.toString(16));
+965     }
+966     var a = s.match(/.{4}/g);
+967     var a2 = a.map(_conv);
+968     return a2.join("");
+969 }
+970 
+971 // ==== URIComponent ================================
+972 /**
+973  * convert UTFa hexadecimal string to a URLComponent string such like "%67%68".<br/>
+974  * Note that these "<code>0-9A-Za-z!'()*-._~</code>" characters will not
+975  * converted to "%xx" format by builtin 'encodeURIComponent()' function.
+976  * However this 'encodeURIComponentAll()' function will convert 
+977  * all of characters into "%xx" format.
+978  * @name encodeURIComponentAll
+979  * @function
+980  * @param {String} s hexadecimal string
+981  * @return {String} URIComponent string such like "%67%68"
+982  * @since 1.1
+983  */
+984 function encodeURIComponentAll(u8) {
+985   var s = encodeURIComponent(u8);
+986   var s2 = "";
+987   for (var i = 0; i < s.length; i++) {
+988     if (s[i] == "%") {
+989       s2 = s2 + s.substr(i, 3);
+990       i = i + 2;
+991     } else {
+992       s2 = s2 + "%" + stohex(s[i]);
+993     }
+994   }
+995   return s2;
+996 }
+997 
+998 // ==== new lines ================================
+999 /**
+1000  * convert all DOS new line("\r\n") to UNIX new line("\n") in 
+1001  * a String "s".
+1002  * @name newline_toUnix
+1003  * @function
+1004  * @param {String} s string 
+1005  * @return {String} converted string
+1006  */
+1007 function newline_toUnix(s) {
+1008     s = s.replace(/\r\n/mg, "\n");
+1009     return s;
+1010 }
+1011 
+1012 /**
+1013  * convert all UNIX new line("\r\n") to DOS new line("\n") in 
+1014  * a String "s".
+1015  * @name newline_toDos
+1016  * @function
+1017  * @param {String} s string 
+1018  * @return {String} converted string
+1019  */
+1020 function newline_toDos(s) {
+1021     s = s.replace(/\r\n/mg, "\n");
+1022     s = s.replace(/\n/mg, "\r\n");
+1023     return s;
+1024 }
 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]+$/)) {
+1026 // ==== string type checker ===================
+1027 
+1028 /**
+1029  * check whether a string is an integer string or not<br/>
+1030  * @name isInteger
+1031  * @memberOf KJUR.lang.String
+1032  * @function
+1033  * @static
+1034  * @param {String} s input string
+1035  * @return {Boolean} true if a string "s" is an integer string otherwise false
+1036  * @since base64x 1.1.7 jsrsasign 5.0.13
+1037  * @example
+1038  * KJUR.lang.String.isInteger("12345") → true
+1039  * KJUR.lang.String.isInteger("123ab") → false
+1040  */
+1041 KJUR.lang.String.isInteger = function(s) {
+1042     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 ================================
+1044     } else if (s.match(/^-[0-9]+$/)) {
+1045 	return true;
+1046     } else {
+1047 	return false;
+1048     }
+1049 };
+1050 
+1051 /**
+1052  * check whether a string is an hexadecimal string or not (DEPRECATED)<br/>
+1053  * @name isHex
+1054  * @memberOf KJUR.lang.String
+1055  * @function
+1056  * @static
+1057  * @param {String} s input string
+1058  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
+1059  * @since base64x 1.1.7 jsrsasign 5.0.13
+1060  * @deprecated from 10.0.6. please use {@link ishex}
+1061  * @see ishex
+1062  * @example
+1063  * KJUR.lang.String.isHex("1234") → true
+1064  * KJUR.lang.String.isHex("12ab") → true
+1065  * KJUR.lang.String.isHex("12AB") → true
+1066  * KJUR.lang.String.isHex("12ZY") → false
+1067  * KJUR.lang.String.isHex("121") → false -- odd length
+1068  */
+1069 KJUR.lang.String.isHex = function(s) {
+1070     return ishex(s);
+1071 };
+1072 
+1073 /**
+1074  * check whether a string is an hexadecimal string or not<br/>
+1075  * @name ishex
+1076  * @function
+1077  * @static
+1078  * @param {String} s input string
+1079  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
+1080  * @since base64x 1.1.7 jsrsasign 5.0.13
+1081  * @example
+1082  * ishex("1234") → true
+1083  * ishex("12ab") → true
+1084  * ishex("12AB") → true
+1085  * ishex("12ZY") → false
+1086  * ishex("121") → false -- odd length
+1087  */
+1088 function ishex(s) {
+1089     if (s.length % 2 == 0 &&
+1090 	(s.match(/^[0-9a-f]+$/) || s.match(/^[0-9A-F]+$/))) {
+1091 	return true;
+1092     } else {
+1093 	return false;
+1094     }
+1095 };
+1096 
+1097 /**
+1098  * check whether a string is a base64 encoded string or not<br/>
+1099  * Input string can conclude new lines or space characters.
+1100  * @name isBase64
+1101  * @memberOf KJUR.lang.String
+1102  * @function
+1103  * @static
+1104  * @param {String} s input string
+1105  * @return {Boolean} true if a string "s" is a base64 encoded string otherwise false
+1106  * @since base64x 1.1.7 jsrsasign 5.0.13
+1107  * @example
+1108  * KJUR.lang.String.isBase64("YWE=") → true
+1109  * KJUR.lang.String.isBase64("YW_=") → false
+1110  * KJUR.lang.String.isBase64("YWE") → false -- length shall be multiples of 4
+1111  */
+1112 KJUR.lang.String.isBase64 = function(s) {
+1113     s = s.replace(/\s+/g, "");
+1114     if (s.match(/^[0-9A-Za-z+\/]+={0,3}$/) && s.length % 4 == 0) {
+1115 	return true;
+1116     } else {
+1117 	return false;
+1118     }
+1119 };
+1120 
+1121 /**
+1122  * check whether a string is a base64url encoded string or not<br/>
+1123  * Input string can conclude new lines or space characters.
+1124  * @name isBase64URL
+1125  * @memberOf KJUR.lang.String
+1126  * @function
+1127  * @static
+1128  * @param {String} s input string
+1129  * @return {Boolean} true if a string "s" is a base64url encoded string otherwise false
+1130  * @since base64x 1.1.7 jsrsasign 5.0.13
+1131  * @example
+1132  * KJUR.lang.String.isBase64URL("YWE") → true
+1133  * KJUR.lang.String.isBase64URL("YW-") → true
+1134  * KJUR.lang.String.isBase64URL("YW+") → false
+1135  */
+1136 KJUR.lang.String.isBase64URL = function(s) {
+1137     if (s.match(/[+/=]/)) return false;
+1138     s = b64utob64(s);
+1139     return KJUR.lang.String.isBase64(s);
+1140 };
+1141 
+1142 /**
+1143  * check whether a string is a string of integer array or not<br/>
+1144  * Input string can conclude new lines or space characters.
+1145  * @name isIntegerArray
+1146  * @memberOf KJUR.lang.String
+1147  * @function
+1148  * @static
+1149  * @param {String} s input string
+1150  * @return {Boolean} true if a string "s" is a string of integer array otherwise false
+1151  * @since base64x 1.1.7 jsrsasign 5.0.13
+1152  * @example
+1153  * KJUR.lang.String.isIntegerArray("[1,2,3]") → true
+1154  * KJUR.lang.String.isIntegerArray("  [1, 2, 3  ] ") → true
+1155  * KJUR.lang.String.isIntegerArray("[a,2]") → false
+1156  */
+1157 KJUR.lang.String.isIntegerArray = function(s) {
+1158     s = s.replace(/\s+/g, "");
+1159     if (s.match(/^\[[0-9,]+\]$/)) {
+1160 	return true;
+1161     } else {
+1162 	return false;
+1163     }
+1164 };
+1165 
+1166 /**
+1167  * check whether a string consists of PrintableString characters<br/>
+1168  * @name isPrintable
+1169  * @memberOf KJUR.lang.String
+1170  * @function
+1171  * @static
+1172  * @param {String} s input string
+1173  * @return {Boolean} true if a string "s" consists of PrintableString characters
+1174  * @since jsrsasign 9.0.0 base64x 1.1.16
+1175  * A PrintableString consists of following characters
+1176  * <pre>
+1177  * 0-9A-Za-z '()+,-./:=?
+1178  * </pre>
+1179  * This method returns false when other characters than above.
+1180  * Otherwise it returns true.
+1181  * @example
+1182  * KJUR.lang.String.isPrintable("abc") → true
+1183  * KJUR.lang.String.isPrintable("abc@") → false
+1184  * KJUR.lang.String.isPrintable("あいう") → false
+1185  */
+1186 KJUR.lang.String.isPrintable = function(s) {
+1187     if (s.match(/^[0-9A-Za-z '()+,-./:=?]*$/) !== null) return true;
+1188     return false;
+1189 };
+1190 
+1191 /**
+1192  * check whether a string consists of IAString characters<br/>
+1193  * @name isIA5
+1194  * @memberOf KJUR.lang.String
+1195  * @function
+1196  * @static
+1197  * @param {String} s input string
+1198  * @return {Boolean} true if a string "s" consists of IA5String characters
+1199  * @since jsrsasign 9.0.0 base64x 1.1.16
+1200  * A IA5String consists of following characters
+1201  * <pre>
+1202  * %x00-21/%x23-7F (i.e. ASCII characters excludes double quote(%x22)
+1203  * </pre>
+1204  * This method returns false when other characters than above.
+1205  * Otherwise it returns true.
+1206  * @example
+1207  * KJUR.lang.String.isIA5("abc") → true
+1208  * KJUR.lang.String.isIA5('"abc"') → false
+1209  * KJUR.lang.String.isIA5("あいう") → false
+1210  */
+1211 KJUR.lang.String.isIA5 = function(s) {
+1212     if (s.match(/^[\x20-\x21\x23-\x7f]*$/) !== null) return true;
+1213     return false;
+1214 };
+1215 
+1216 /**
+1217  * check whether a string is RFC 822 mail address<br/>
+1218  * @name isMail
+1219  * @memberOf KJUR.lang.String
+1220  * @function
+1221  * @static
+1222  * @param {String} s input string
+1223  * @return {Boolean} true if a string "s" RFC 822 mail address
+1224  * @since jsrsasign 9.0.0 base64x 1.1.16
+1225  * This static method will check string s is RFC 822 compliant mail address.
+1226  * @example
+1227  * KJUR.lang.String.isMail("abc") → false
+1228  * KJUR.lang.String.isMail("abc@example") → false
+1229  * KJUR.lang.String.isMail("abc@example.com") → true
+1230  */
+1231 KJUR.lang.String.isMail = function(s) {
+1232     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;
+1233     return false;
+1234 };
 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 =================================
+1236 // ==== others ================================
+1237 
+1238 /**
+1239  * canonicalize hexadecimal string of positive integer<br/>
+1240  * @name hextoposhex
+1241  * @function
+1242  * @param {String} s hexadecimal string 
+1243  * @return {String} canonicalized hexadecimal string of positive integer
+1244  * @since base64x 1.1.10 jsrsasign 7.1.4
+1245  * @description
+1246  * This method canonicalize a hexadecimal string of positive integer
+1247  * for two's complement representation.
+1248  * Canonicalized hexadecimal string of positive integer will be:
+1249  * <ul>
+1250  * <li>Its length is always even.</li>
+1251  * <li>If odd length it will be padded with leading zero.<li>
+1252  * <li>If it is even length and its first character is "8" or greater,
+1253  * it will be padded with "00" to make it positive integer.</li>
+1254  * </ul>
+1255  * @example
+1256  * hextoposhex("abcd") → "00abcd"
+1257  * hextoposhex("1234") → "1234"
+1258  * hextoposhex("12345") → "012345"
+1259  */
+1260 function hextoposhex(s) {
+1261     if (s.length % 2 == 1) return "0" + s;
+1262     if (s.substr(0, 1) > "7") return "00" + s;
+1263     return s;
+1264 }
+1265 
+1266 /**
+1267  * convert string of integer array to hexadecimal string.<br/>
+1268  * @name intarystrtohex
+1269  * @function
+1270  * @param {String} s string of integer array
+1271  * @return {String} hexadecimal string
+1272  * @since base64x 1.1.6 jsrsasign 5.0.2
+1273  * @throws "malformed integer array string: *" for wrong input
+1274  * @description
+1275  * This function converts a string of JavaScript integer array to
+1276  * a hexadecimal string. Each integer value shall be in a range 
+1277  * from 0 to 255 otherwise it raise exception. Input string can
+1278  * have extra space or newline string so that they will be ignored.
+1279  * 
+1280  * @example
+1281  * intarystrtohex(" [123, 34, 101, 34, 58] ")
+1282  * → 7b2265223a (i.e. '{"e":' as string)
+1283  */
+1284 function intarystrtohex(s) {
+1285   s = s.replace(/^\s*\[\s*/, '');
+1286   s = s.replace(/\s*\]\s*$/, '');
+1287   s = s.replace(/\s*/g, '');
+1288   try {
+1289     var hex = s.split(/,/).map(function(element, index, array) {
+1290       var i = parseInt(element);
+1291       if (i < 0 || 255 < i) throw "integer not in range 0-255";
+1292       var hI = ("00" + i.toString(16)).slice(-2);
+1293       return hI;
+1294     }).join('');
+1295     return hex;
+1296   } catch(ex) {
+1297     throw "malformed integer array string: " + ex;
+1298   }
+1299 }
+1300 
+1301 /**
+1302  * find index of string where two string differs
+1303  * @name strdiffidx
+1304  * @function
+1305  * @param {String} s1 string to compare
+1306  * @param {String} s2 string to compare
+1307  * @return {Number} string index of where character differs. Return -1 if same.
+1308  * @since jsrsasign 4.9.0 base64x 1.1.5
+1309  * @example
+1310  * strdiffidx("abcdefg", "abcd4fg") -> 4
+1311  * strdiffidx("abcdefg", "abcdefg") -> -1
+1312  * strdiffidx("abcdefg", "abcdef") -> 6
+1313  * strdiffidx("abcdefgh", "abcdef") -> 6
+1314  */
+1315 var strdiffidx = function(s1, s2) {
+1316     var n = s1.length;
+1317     if (s1.length > s2.length) n = s2.length;
+1318     for (var i = 0; i < n; i++) {
+1319 	if (s1.charCodeAt(i) != s2.charCodeAt(i)) return i;
+1320     }
+1321     if (s1.length != s2.length) return n;
+1322     return -1; // same
+1323 };
 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 {
+1325 // ==== hex / oid =================================
+1326 
+1327 /**
+1328  * get hexadecimal value of object identifier from dot noted oid value
+1329  * @name oidtohex
+1330  * @function
+1331  * @param {String} oidString dot noted string of object identifier
+1332  * @return {String} hexadecimal value of object identifier
+1333  * @since jsrsasign 10.1.0 base64x 1.1.18
+1334  * @see hextooid
+1335  * @see ASN1HEX.hextooidstr
+1336  * @see KJUR.asn1.ASN1Util.oidIntToHex
+1337  * @description
+1338  * This static method converts from object identifier value string.
+1339  * to hexadecimal string representation of it.
+1340  * {@link hextooid} is a reverse function of this.
+1341  * @example
+1342  * oidtohex("2.5.4.6") → "550406"
+1343  */
+1344 function oidtohex(oidString) {
+1345     var itox = function(i) {
+1346         var h = i.toString(16);
+1347         if (h.length == 1) h = '0' + h;
+1348         return h;
+1349     };
+1350 
+1351     var roidtox = function(roid) {
+1352         var h = '';
+1353         var bi = parseInt(roid, 10);
+1354         var b = bi.toString(2);
+1355 
+1356         var padLen = 7 - b.length % 7;
+1357         if (padLen == 7) padLen = 0;
+1358         var bPad = '';
+1359         for (var i = 0; i < padLen; i++) bPad += '0';
+1360         b = bPad + b;
+1361         for (var i = 0; i < b.length - 1; i += 7) {
+1362             var b8 = b.substr(i, 7);
+1363             if (i != b.length - 7) b8 = '1' + b8;
+1364             h += itox(parseInt(b8, 2));
+1365         }
+1366         return h;
+1367     };
+1368     
+1369     try {
+1370 	if (! oidString.match(/^[0-9.]+$/)) return null;
+1371     
+1372 	var h = '';
+1373 	var a = oidString.split('.');
+1374 	var i0 = parseInt(a[0], 10) * 40 + parseInt(a[1], 10);
+1375 	h += itox(i0);
+1376 	a.splice(0, 2);
+1377 	for (var i = 0; i < a.length; i++) {
+1378             h += roidtox(a[i]);
+1379 	}
+1380 	return h;
+1381     } catch(ex) {
+1382 	return null;
+1383     }
+1384 };
+1385 
+1386 /**
+1387  * get oid string from hexadecimal value of object identifier<br/>
+1388  * @name hextooid
+1389  * @function
+1390  * @param {String} h hexadecimal value of object identifier
+1391  * @return {String} dot noted string of object identifier (ex. "1.2.3.4")
+1392  * @since jsrsasign 10.1.0 base64x 1.1.18
+1393  * @see oidtohex
+1394  * @see ASN1HEX.hextooidstr
+1395  * @see KJUR.asn1.ASN1Util.oidIntToHex
+1396  * @description
+1397  * This static method converts from hexadecimal object identifier value 
+1398  * to dot noted OID value (ex. "1.2.3.4").
+1399  * {@link oidtohex} is a reverse function of this.
+1400  * @example
+1401  * hextooid("550406") → "2.5.4.6"
+1402  */
+1403 function hextooid(h) {
+1404     if (! ishex(h)) return null;
+1405     try {
+1406 	var a = [];
+1407 
+1408 	// a[0], a[1]
+1409 	var hex0 = h.substr(0, 2);
+1410 	var i0 = parseInt(hex0, 16);
+1411 	a[0] = new String(Math.floor(i0 / 40));
+1412 	a[1] = new String(i0 % 40);
+1413 
+1414 	// a[2]..a[n]
+1415 	var hex1 = h.substr(2);
+1416 	var b = [];
+1417 	for (var i = 0; i < hex1.length / 2; i++) {
+1418 	    b.push(parseInt(hex1.substr(i * 2, 2), 16));
+1419 	}
+1420 	var c = [];
+1421 	var cbin = "";
+1422 	for (var i = 0; i < b.length; i++) {
+1423             if (b[i] & 0x80) {
 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 =================================
+1425             } else {
+1426 		cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7);
+1427 		c.push(new String(parseInt(cbin, 2)));
+1428 		cbin = "";
+1429             }
+1430 	}
+1431 
+1432 	var s = a.join(".");
+1433 	if (c.length > 0) s = s + "." + c.join(".");
+1434 	return s;
+1435     } catch(ex) {
+1436 	return null;
+1437     }
+1438 };
+1439 
+1440 /**
+1441  * string padding<br/>
+1442  * @name strpad
+1443  * @function
+1444  * @param {String} s input string
+1445  * @param {Number} len output string length
+1446  * @param {String} padchar padding character (default is "0")
+1447  * @return {String} padded string
+1448  * @since jsrsasign 10.1.0 base64x 1.1.18
+1449  * @example
+1450  * strpad("1234", 10, "0") → "0000001234"
+1451  * strpad("1234", 10, " ") → "      1234"
+1452  * strpad("1234", 10)      → "0000001234"
+1453  */
+1454 var strpad = function(s, len, padchar) {
+1455     if (padchar == undefined) padchar = "0";
+1456     if (s.length >= len) return s;
+1457     return new Array(len - s.length + 1).join(padchar) + s;
+1458 };
 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 =======================
+1460 // ==== bitstr hex / int =================================
+1461 
+1462 /**
+1463  * convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value<br/>
+1464  * @name bitstrtoint
+1465  * @function
+1466  * @param {String} h hexadecimal string of ASN.1 BitString value with unused bit
+1467  * @return {Number} positive integer value of the BitString
+1468  * @since jsrsasign 10.1.3 base64x 1.1.19
+1469  * @see inttobitstr
+1470  * @see KJUR.asn1.DERBitString
+1471  * @see ASN1HEX.getInt
+1472  * 
+1473  * @description
+1474  * This function converts from hexadecimal string of ASN.1 BitString
+1475  * value with unused bit to its integer value. <br/>
+1476  * When an improper hexadecimal string of BitString value
+1477  * is applied, this returns -1.
+1478  * 
+1479  * @example
+1480  * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25
+1481  * bitstrtoint("03c8") → 25
+1482  * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02
+1483  * //   11111111111110b → 16382
+1484  * bitstrtoint("02fff8") → 16382
+1485  * bitstrtoint("05a0") → 5 (=101b)
+1486  * bitstrtoint("ff00") → -1 // for improper BitString value
+1487  * bitstrtoint("05a0").toString(2) → "101"
+1488  * bitstrtoint("07a080").toString(2) → "101000001"
+1489  */
+1490 function bitstrtoint(h) {
+1491     if (h.length % 2 != 0) return -1; 
+1492     h = h.toLowerCase();
+1493     if (h.match(/^[0-9a-f]+$/) == null) return -1;
+1494     try {
+1495 	var hUnusedbit = h.substr(0, 2);
+1496 	if (hUnusedbit == "00")
+1497 	    return parseInt(h.substr(2), 16);
+1498 	var iUnusedbit = parseInt(hUnusedbit, 16);
+1499 	if (iUnusedbit > 7) return -1;
+1500 	var hValue = h.substr(2);
+1501 	var bValue = parseInt(hValue, 16).toString(2);
+1502 	if (bValue == "0") bValue = "00000000";
+1503 	bValue = bValue.slice(0, 0 - iUnusedbit);
+1504 	var iValue = parseInt(bValue, 2);
+1505 	if (iValue == NaN) return -1;
+1506 	return iValue;
+1507     } catch(ex) {
+1508 	return -1;
+1509     }
+1510 };
+1511 
+1512 /**
+1513  * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit<br/>
+1514  * @name inttobitstr
+1515  * @function
+1516  * @param {Number} n integer value of ASN.1 BitString
+1517  * @return {String} hexadecimal string of ASN.1 BitString value with unused bit
+1518  * @since jsrsasign 10.1.3 base64x 1.1.19
+1519  * @see bitstrtoint
+1520  * @see KJUR.asn1.DERBitString
+1521  * @see ASN1HEX.getInt
+1522  * 
+1523  * @description
+1524  * This function converts from an integer value to 
+1525  * hexadecimal string of ASN.1 BitString value
+1526  * with unused bit. <br/>
+1527  * When "n" is not non-negative number, this returns null
+1528  * 
+1529  * @example
+1530  * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8"
+1531  * inttobitstr(25) → "03c8"
+1532  * inttobitstr(-3) → null
+1533  * inttobitstr("abc") → null
+1534  * inttobitstr(parseInt("11001", 2)) → "03c8"
+1535  * inttobitstr(parseInt("101", 2)) → "05a0"
+1536  * inttobitstr(parseInt("101000001", 2)) → "07a080"
+1537  */
+1538 function inttobitstr(n) {
+1539     if (typeof n != "number") return null;
+1540     if (n < 0) return null;
+1541     var bValue = Number(n).toString(2);
+1542     var iUnusedbit = 8 - bValue.length % 8;
+1543     if (iUnusedbit == 8) iUnusedbit = 0;
+1544     bValue = bValue + strpad("", iUnusedbit, "0");
+1545     var hValue = parseInt(bValue, 2).toString(16);
+1546     if (hValue.length % 2 == 1) hValue = "0" + hValue;
+1547     var hUnusedbit = "0" + iUnusedbit;
+1548     return hUnusedbit + hValue;
+1549 };
 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 
+1551
// ==== bitstr hex / binary string ======================= +1552 +1553 /** +1554 * convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string<br/> +1555 * @name bitstrtobinstr +1556 * @function +1557 * @param {string} h hexadecimal string of ASN.1 BitString value with unused bit +1558 * @return {string} binary string +1559 * @since jsrsasign 10.5.4 base64x 1.1.21 +1560 * @see binstrtobitstr +1561 * @see inttobitstr +1562 * +1563 * @description +1564 * This function converts from hexadecimal string of ASN.1 BitString +1565 * value with unused bit to its integer value. <br/> +1566 * When an improper hexadecimal string of BitString value +1567 * is applied, this returns null. +1568 * +1569 * @example +1570 * bitstrtobinstr("05a0") → "101" +1571 * bitstrtobinstr("07a080") → "101000001" +1572 * bitstrtoint(502) → null // non ASN.1 BitString value +1573 * bitstrtoint("ff00") → -1 // for improper BitString value +1574 */ +1575 function bitstrtobinstr(h) { +1576 var n = bitstrtoint(h); +1577 if (n == -1) return null; +1578 return n.toString(2); +1579 } +1580 +1581 /** +1582 * convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit<br/> +1583 * @name binstrtobitstr +1584 * @function +1585 * @param {string} s binary string (ex. "101") +1586 * @return {string} hexadecimal string of ASN.1 BitString value with unused bit +1587 * @since jsrsasign 10.5.4 base64x 1.1.21 +1588 * @see bitstrtobinstr +1589 * @see inttobitstr +1590 * @see KJUR.asn1.DERBitString +1591 * +1592 * @description +1593 * This function converts from an binary string (ex. "101") to +1594 * hexadecimal string of ASN.1 BitString value +1595 * with unused bit (ex. "05a0"). <br/> +1596 * When "s" is not binary string, this returns null. +1597 * +1598 * @example +1599 * binstrtobitstr("101") → "05a0" +1600 * binstrtobitstr("11001") → "03c8" +1601 * binstrtobitstr("101000001") → "07a080" +1602 * binstrtobitstr(101) → null // not number +1603 * binstrtobitstr("xyz") → null // not binary string +1604 */ +1605 function binstrtobitstr(s) { +1606 if (typeof s != "string") return null; +1607 if (s.match(/^[01]+$/) == null) return null; +1608 try { +1609 var n = parseInt(s, 2); +1610 return inttobitstr(n); +1611 } catch(ex) { +1612 return null; +1613 } +1614 } +1615 +1616 // ======================================================= +1617 /** +1618 * set class inheritance<br/> +1619 * @name extendClass +1620 * @function +1621 * @param {Function} subClass sub class to set inheritance +1622 * @param {Function} superClass super class to inherit +1623 * @since jsrsasign 10.3.0 base64x 1.1.21 +1624 * +1625 * @description +1626 * This function extends a class and set an inheritance +1627 * for member variables and methods. +1628 * +1629 * @example +1630 * var Animal = function() { +1631 * this.hello = function(){console.log("Hello")}; +1632 * this.name="Ani"; +1633 * }; +1634 * var Dog = function() { +1635 * Dog.superclass.constructor.call(this); +1636 * this.vow = function(){console.log("Vow wow")}; +1637 * this.tail=true; +1638 * }; +1639 * extendClass(Dog, Animal); +1640 */ +1641 function extendClass(subClass, superClass) { +1642 var F = function() {}; +1643 F.prototype = superClass.prototype; +1644 subClass.prototype = new F(); +1645 subClass.prototype.constructor = subClass; +1646 subClass.superclass = superClass.prototype; +1647 +1648 if (superClass.prototype.constructor == Object.prototype.constructor) { +1649 superClass.prototype.constructor = superClass; +1650 } +1651 }; +1652 +1653
diff --git a/bower.json b/bower.json index 5bad284a..c224a470 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kjur-jsrsasign", - "version": "10.5.9", + "version": "10.5.10", "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 7a1dd596..af16364e 100644 --- a/jsrsasign-all-min.js +++ b/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.5.9 (2022-03-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license + * jsrsasign(all) 10.5.10 (2022-03-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -225,7 +225,7 @@ 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.cades=="undefined"||!KJUR.asn1.cades){KJUR.asn1.cades={}}KJUR.asn1.cades.SignaturePolicyIdentifier=function(e){var c=KJUR,b=c.asn1,a=b.cades,d=a.SignaturePolicyId;a.SignaturePolicyIdentifier.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.15";this.params=null;this.getValueArray=function(){return[new d(this.params)]};this.setByParam=function(f){this.params=f};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cades.SignaturePolicyIdentifier,KJUR.asn1.cms.Attribute);KJUR.asn1.cades.SignaturePolicyId=function(e){var a=KJUR,g=a.asn1,f=g.DERSequence,i=g.DERObjectIdentifier,d=g.x509,j=d.AlgorithmIdentifier,c=g.cades,h=c.SignaturePolicyId,b=c.OtherHashAlgAndValue;h.superclass.constructor.call(this);this.params=null;this.getEncodedHex=function(){var m=this.params;var k=[];k.push(new i(m.oid));k.push(new b(m));var l=new f({array:k});return l.getEncodedHex()};this.setByParam=function(k){this.params=k};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cades.SignaturePolicyId,KJUR.asn1.ASN1Object);KJUR.asn1.cades.OtherHashAlgAndValue=function(e){var h=Error,a=KJUR,g=a.asn1,f=g.DERSequence,i=g.DEROctetString,d=g.x509,j=d.AlgorithmIdentifier,c=g.cades,b=c.OtherHashAlgAndValue;b.superclass.constructor.call(this);this.params=null;this.getEncodedHex=function(){var o=this.params;if(o.alg==undefined){throw new h("property 'alg' not specified")}if(o.hash==undefined&&o.cert==undefined){throw new h("property 'hash' nor 'cert' not specified")}var m=null;if(o.hash!=undefined){m=o.hash}else{if(o.cert!=undefined){if(typeof o.cert!="string"){throw new h("cert not string")}var n=o.cert;if(o.cert.indexOf("-----BEGIN")!=-1){n=pemtohex(o.cert)}m=KJUR.crypto.Util.hashHex(n,o.alg)}}var k=[];k.push(new j({name:o.alg}));k.push(new i({hex:m}));var l=new f({array:k});return l.getEncodedHex()};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cades.OtherHashAlgAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.cades.OtherHashValue=function(g){KJUR.asn1.cades.OtherHashValue.superclass.constructor.call(this);var d=Error,c=KJUR,f=c.lang.String.isHex,b=c.asn1,e=b.DEROctetString,a=c.crypto.Util.hashHex;this.params=null;this.getEncodedHex=function(){var j=this.params;if(j.hash==undefined&&j.cert==undefined){throw new d("hash or cert not specified")}var h=null;if(j.hash!=undefined){h=j.hash}else{if(j.cert!=undefined){if(typeof j.cert!="string"){throw new d("cert not string")}var i=j.cert;if(j.cert.indexOf("-----BEGIN")!=-1){i=pemtohex(j.cert)}h=KJUR.crypto.Util.hashHex(i,"sha1")}}return(new e({hex:h})).getEncodedHex()};if(g!=undefined){this.setByParam(g)}};extendClass(KJUR.asn1.cades.OtherHashValue,KJUR.asn1.ASN1Object);KJUR.asn1.cades.SignatureTimeStamp=function(h){var d=Error,c=KJUR,f=c.lang.String.isHex,b=c.asn1,e=b.ASN1Object,g=b.x509,a=b.cades;a.SignatureTimeStamp.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.14";this.params=null;this.getValueArray=function(){var l=this.params;if(l.tst!=undefined){if(f(l.tst)){var j=new e();j.hTLV=l.tst;return[j]}else{if(l.tst instanceof e){return[l.tst]}else{throw new d("params.tst has wrong value")}}}else{if(l.res!=undefined){var k=l.res;if(k instanceof e){k=k.getEncodedHex()}if(typeof k!="string"||(!f(k))){throw new d("params.res has wrong value")}var i=ASN1HEX.getTLVbyList(k,0,[1]);var j=new e();j.hTLV=l.tst;return[j]}}};if(h!=null){this.setByParam(h)}};extendClass(KJUR.asn1.cades.SignatureTimeStamp,KJUR.asn1.cms.Attribute);KJUR.asn1.cades.CompleteCertificateRefs=function(h){var f=Error,e=KJUR,d=e.asn1,b=d.DERSequence,c=d.cades,a=c.OtherCertID,g=e.lang.String.isHex;c.CompleteCertificateRefs.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.21";this.params=null;this.getValueArray=function(){var o=this.params;var k=[];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;c>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;c>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;c>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;c>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 7a1dd596..af16364e 100644 --- a/npm/lib/jsrsasign-all-min.js +++ b/npm/lib/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.5.9 (2022-03-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license + * jsrsasign(all) 10.5.10 (2022-03-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -225,7 +225,7 @@ 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.cades=="undefined"||!KJUR.asn1.cades){KJUR.asn1.cades={}}KJUR.asn1.cades.SignaturePolicyIdentifier=function(e){var c=KJUR,b=c.asn1,a=b.cades,d=a.SignaturePolicyId;a.SignaturePolicyIdentifier.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.15";this.params=null;this.getValueArray=function(){return[new d(this.params)]};this.setByParam=function(f){this.params=f};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cades.SignaturePolicyIdentifier,KJUR.asn1.cms.Attribute);KJUR.asn1.cades.SignaturePolicyId=function(e){var a=KJUR,g=a.asn1,f=g.DERSequence,i=g.DERObjectIdentifier,d=g.x509,j=d.AlgorithmIdentifier,c=g.cades,h=c.SignaturePolicyId,b=c.OtherHashAlgAndValue;h.superclass.constructor.call(this);this.params=null;this.getEncodedHex=function(){var m=this.params;var k=[];k.push(new i(m.oid));k.push(new b(m));var l=new f({array:k});return l.getEncodedHex()};this.setByParam=function(k){this.params=k};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cades.SignaturePolicyId,KJUR.asn1.ASN1Object);KJUR.asn1.cades.OtherHashAlgAndValue=function(e){var h=Error,a=KJUR,g=a.asn1,f=g.DERSequence,i=g.DEROctetString,d=g.x509,j=d.AlgorithmIdentifier,c=g.cades,b=c.OtherHashAlgAndValue;b.superclass.constructor.call(this);this.params=null;this.getEncodedHex=function(){var o=this.params;if(o.alg==undefined){throw new h("property 'alg' not specified")}if(o.hash==undefined&&o.cert==undefined){throw new h("property 'hash' nor 'cert' not specified")}var m=null;if(o.hash!=undefined){m=o.hash}else{if(o.cert!=undefined){if(typeof o.cert!="string"){throw new h("cert not string")}var n=o.cert;if(o.cert.indexOf("-----BEGIN")!=-1){n=pemtohex(o.cert)}m=KJUR.crypto.Util.hashHex(n,o.alg)}}var k=[];k.push(new j({name:o.alg}));k.push(new i({hex:m}));var l=new f({array:k});return l.getEncodedHex()};if(e!=undefined){this.setByParam(e)}};extendClass(KJUR.asn1.cades.OtherHashAlgAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.cades.OtherHashValue=function(g){KJUR.asn1.cades.OtherHashValue.superclass.constructor.call(this);var d=Error,c=KJUR,f=c.lang.String.isHex,b=c.asn1,e=b.DEROctetString,a=c.crypto.Util.hashHex;this.params=null;this.getEncodedHex=function(){var j=this.params;if(j.hash==undefined&&j.cert==undefined){throw new d("hash or cert not specified")}var h=null;if(j.hash!=undefined){h=j.hash}else{if(j.cert!=undefined){if(typeof j.cert!="string"){throw new d("cert not string")}var i=j.cert;if(j.cert.indexOf("-----BEGIN")!=-1){i=pemtohex(j.cert)}h=KJUR.crypto.Util.hashHex(i,"sha1")}}return(new e({hex:h})).getEncodedHex()};if(g!=undefined){this.setByParam(g)}};extendClass(KJUR.asn1.cades.OtherHashValue,KJUR.asn1.ASN1Object);KJUR.asn1.cades.SignatureTimeStamp=function(h){var d=Error,c=KJUR,f=c.lang.String.isHex,b=c.asn1,e=b.ASN1Object,g=b.x509,a=b.cades;a.SignatureTimeStamp.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.14";this.params=null;this.getValueArray=function(){var l=this.params;if(l.tst!=undefined){if(f(l.tst)){var j=new e();j.hTLV=l.tst;return[j]}else{if(l.tst instanceof e){return[l.tst]}else{throw new d("params.tst has wrong value")}}}else{if(l.res!=undefined){var k=l.res;if(k instanceof e){k=k.getEncodedHex()}if(typeof k!="string"||(!f(k))){throw new d("params.res has wrong value")}var i=ASN1HEX.getTLVbyList(k,0,[1]);var j=new e();j.hTLV=l.tst;return[j]}}};if(h!=null){this.setByParam(h)}};extendClass(KJUR.asn1.cades.SignatureTimeStamp,KJUR.asn1.cms.Attribute);KJUR.asn1.cades.CompleteCertificateRefs=function(h){var f=Error,e=KJUR,d=e.asn1,b=d.DERSequence,c=d.cades,a=c.OtherCertID,g=e.lang.String.isHex;c.CompleteCertificateRefs.superclass.constructor.call(this);this.typeOid="1.2.840.113549.1.9.16.2.21";this.params=null;this.getValueArray=function(){var o=this.params;var k=[];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;c>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;c>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;c>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}}; +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;c>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 */ @@ -800,42 +800,44 @@ function ipv6tohex(s) { * RFC 5952 * canonicalized IPv6 address string. * @example - * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4" - * hextoip("871020010db8000000000000000000") &rarr raise exception - * hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception + * hextoipv6("871020010db8000000000000000000000004") &rarr "2001:db8::4" + * hextoipv6("871020010db8000000000000000000") &rarr raise exception + * hextoipv6("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception */ function hextoipv6(s) { - if (! s.match(/^[0-9A-Fa-f]{32}$/)) - throw "malformed IPv6 address octet"; + if (! s.match(/^[0-9A-Fa-f]{32}$/)) + throw new Error("malformed IPv6 address: " + s); - // 1. downcase - s = s.toLowerCase(); + // 1. downcase + s = s.toLowerCase(); - // 2. split 4 - var a = s.match(/.{1,4}/g); + // 2. split 4 > ["0123", "00a4", "0000", ..., "ffff"] + var a = s.match(/.{1,4}/g); - // 3. trim leading 0 - for (var i = 0; i < 8; i++) { - a[i] = a[i].replace(/^0+/, ""); - if (a[i] == '') a[i] = '0'; - } - s = ":" + a.join(":") + ":"; + // 3. trim leading 0 for items and join > "123:a4:0:...:ffff" + a = a.map(function(s){s.replace(/^0+/, '')}); + a = a.map(function(s){s == '' ? '0' : s}); + s = ':' + a.join(':') + ':'; - // 4. find shrinkables :0:0:... - var aZero = s.match(/:(0:){2,}/g); + // 4. find shrinkable candidates :0:0:..:0: + var aZero = s.match(/:(0:){2,}/g); - // 5. no shrinkable - if (aZero === null) return s.slice(1, -1); + // 5. no shrinkable + if (aZero == null) return s.slice(1, -1); - // 6. find max length :0:0:... - var item = ''; - for (var i = 0; i < aZero.length; i++) { - if (aZero[i].length > item.length) item = aZero[i]; - } + // 6. fix max length zero(:0:...:0:) + var sMaxZero = aZero.sort().slice(-1)[0]; + + // 7. replace shrinked + s = s.replace(sMaxZero.substr(0, sMaxZero.length - 1), ':'); + + // 8. trim leading ':' if not '::' + if (s.substr(0, 2) != '::') s = s.substr(1); - // 7. shrink - s = s.replace(item, '::'); - return s.slice(1, -1); + // 9. trim tail ':' if not '::' + if (s.substr(-2, 2) != '::') s = s.substr(0, s.length - 1); + + return s; } // ==== hex / ip ================================= diff --git a/test/qunit-do-base64x.html b/test/qunit-do-base64x.html index b4e3c82e..8cc7cada 100755 --- a/test/qunit-do-base64x.html +++ b/test/qunit-do-base64x.html @@ -234,40 +234,46 @@ test("ipv6tohex", function() { equal(ipv6tohex('2001:db8:0:1:0:1:9d6:8'), '20010db8000000010000000109d60008', - '2001:db8:0:1:0:1:9d6:8'); + '2001 0db8 0000 0001 0000 0001 09d6 0008 < 2001:db8:0:1:0:1:9d6:8'); equal(ipv6tohex('2001:db8::2:1'), '20010db8000000000000000000020001', - '2001:db8::2:1'); + '2001 0db8 0000 0000 0000 0000 0002 0001 < 2001:db8::2:1'); equal(ipv6tohex('2001:db8:0:1:1:0:1:1'), '20010db8000000010001000000010001', - '2001:db8:0:1:1:0:1:1'); + '2001 0db8 0000 0001 0001 0000 0001 0001 < 2001:db8:0:1:1:0:1:1'); equal(ipv6tohex('2001:0:0:1::1'), '20010000000000010000000000000001', - '2001:0:0:1::1'); + '2001 0000 0000 0001 0000 0000 0000 0001 < 2001:0:0:1::1'); equal(ipv6tohex('2001:DB8::ABCD:EF12'), '20010db80000000000000000abcdef12', - '2001:DB8::ABCD:EF12'); + '2001 0db8 0000 0000 0000 0000 abcd ef12 < 2001:DB8::ABCD:EF12'); }); test("hextoipv6", function() { equal(hextoipv6('20010db8000000010000000109d60008'), '2001:db8:0:1:0:1:9d6:8', - '2001:db8:0:1:0:1:9d6:8'); + '2001 0db8 0000 0001 0000 0001 09d6 0008 > 2001:db8:0:1:0:1:9d6:8'); equal(hextoipv6('20010db8000000000000000000020001'), '2001:db8::2:1', - '2001:db8::2:1'); + '2001 0db8 0000 0000 0000 0000 0002 0001 > 2001:db8::2:1'); equal(hextoipv6('20010db8000000010001000000010001'), '2001:db8:0:1:1:0:1:1', - '2001:db8:0:1:1:0:1:1'); + '2001 0db8 0000 0001 0001 0000 0001 0001 > 2001:db8:0:1:1:0:1:1'); equal(hextoipv6('20010000000000010000000000000001'), '2001:0:0:1::1', - '2001:0:0:1::1'); + '2001 0000 0000 0001 0000 0000 0000 0001 > 2001:0:0:1::1'); equal(hextoipv6('20010db80000000000000000abcdef12'), '2001:db8::abcd:ef12', - '2001:db8::abcd:ef12'); + '2001 0db8 0000 0000 0000 0000 abcd ef12 > 2001:db8::abcd:ef12'); equal(hextoipv6('26064700470000000000000000001111'), // cloudflare 1.1.1.1 '2606:4700:4700::1111', - 'cloudflare 2606:4700:4700::1111'); + '2606 4700 4700 0000 0000 0000 0000 1111 > 2606:4700:4700::1111 cloudflare'); + equal(hextoipv6('00000000000000000000ffff0ac6cbb1'), // issue 536 + '::ffff:ac6:cbb1', + '0000 0000 0000 0000 0000 ffff 0ac6 cbb1 > ::ffff:ac6:cbb1') + equal(hextoipv6('ffff0ac6cbb100000000000000000000'), + 'ffff:ac6:cbb1::', + 'ffff 0ac6 cbb1 0000 0000 0000 0000 0000 > ffff:ac6:cbb1::') }); test("hextoip", function() {