diff --git a/ChangeLog.txt b/ChangeLog.txt index 7baa3f9c..5c4d5b65 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,33 @@ ChangeLog for jsrsasign +ASN.1 parser update and fix +* Changes from 10.5.3 to 10.5.4 (2022-Feb-15) + - src/asn1.js + - DERTaggedObject + - refactoring + - add {tag: xx, str:"aaa"} parameter support + - add {tag: xx, hex:"616161"} parameter support + - setASN1Object method now *deprecated*. Please use setByParam + - src/asn1hex.js + - ASN1HEX.parse + - add encapsulated OctetString, BitString support + - add encapsulated structured TaggedObject support + - changed to return binary string for 3byte or less BitString value + - ObjectIdentifier fix when undefined OID name + - src/base64x.js + - added bitstrtobinstr/binstrtobitstr + - utf8tohex fix for lower case hexadecimal string + - hextoutf8 fix for improper hexadecimal string for UTF-8 + - bitstrtoint/inttobitstr fix for error case return + - test/qunit-do-asn1.html + - TaggedObject test case update + - test/qunit-do-asn1hex-parse.html + - BitString, TaggedObject test case update + - test/qunit-do-base64x.html + - hextoutf8/utf8tohex testcase update + - bitstrtobinstr/binstrtobitstr testcase added + add OtherName support in GeneralName * Changes from 10.5.2 to 10.5.3 (2022-Feb-10) - add otherName support in GeneralName by PR diff --git a/api/files.html b/api/files.html index d3f3cf6b..da45c0e0 100644 --- a/api/files.html +++ b/api/files.html @@ -525,7 +525,7 @@

asn1-1.0.js

Version:
-
jsrsasign 10.4.1 asn1 1.0.22 (2021-Sep-30)
+
jsrsasign 10.5.4 asn1 1.0.23 (2022-Feb-14)
@@ -601,7 +601,7 @@

asn1hex-1.1.js

Version:
-
jsrsasign 10.5.3 asn1hex 1.2.10 (2022-Feb-10)
+
jsrsasign 10.5.4 asn1hex 1.2.11 (2022-Feb-14)
@@ -677,7 +677,7 @@

base64x-1.1.js

Version:
-
jsrsasign 10.1.13 base64x 1.1.20 (2021-Mar-07)
+
jsrsasign 10.5.4 base64x 1.1.21 (2022-Feb-14)
diff --git a/api/symbols/KJUR.asn1.DERBitString.html b/api/symbols/KJUR.asn1.DERBitString.html index f6ee1bb2..0d0aa785 100644 --- a/api/symbols/KJUR.asn1.DERBitString.html +++ b/api/symbols/KJUR.asn1.DERBitString.html @@ -794,7 +794,7 @@

o = new KJUR.asn1.DERBitString();
-o.setByBooleanArray("01011");
+o.setByBinaryString("01011"); diff --git a/api/symbols/KJUR.asn1.DERTaggedObject.html b/api/symbols/KJUR.asn1.DERTaggedObject.html index 4dcea0c1..82f3da45 100644 --- a/api/symbols/KJUR.asn1.DERTaggedObject.html +++ b/api/symbols/KJUR.asn1.DERTaggedObject.html @@ -722,6 +722,13 @@

+
+
Deprecated:
+
+ since jsrsasign 10.5.4 please use setByParam instead +
+
+ diff --git a/api/symbols/global__.html b/api/symbols/global__.html index 0695c2dc..08da4c7a 100644 --- a/api/symbols/global__.html +++ b/api/symbols/global__.html @@ -646,6 +646,27 @@

+ +   + +
binstrtobitstr(s) +
+
convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit
+This function converts from an binary string (ex.
+ + + + +   + +
bitstrtobinstr(h) +
+
convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string
+This function converts from hexadecimal string of ASN.1 BitString +value with unused bit to its integer value.
+ + +   @@ -1684,6 +1705,153 @@

+
+ + +
+ + {string} + binstrtobitstr(s) + +
+
+ convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit
+This function converts from an binary string (ex. "101") to +hexadecimal string of ASN.1 BitString value +with unused bit (ex. "05a0").
+When "s" is not binary string, this returns null. + +
+ Defined in: base64x-1.1.js. + + +
+ + + +
binstrtobitstr("101") → "05a0"
+binstrtobitstr("11001") → "03c8"
+binstrtobitstr("101000001") → "07a080"
+binstrtobitstr(101) → null // not number
+binstrtobitstr("xyz") → null // not binary string
+ + + + +
+
Parameters:
+ +
+ {string} s + +
+
binary string (ex. "101")
+ +
+ + + +
+
Since:
+
jsrsasign 10.5.4 base64x 1.1.21
+
+ + + + +
+
Returns:
+ +
{string} hexadecimal string of ASN.1 BitString value with unused bit
+ +
+ + + +
+
See:
+ +
bitstrtobinstr
+ +
inttobitstr
+ +
KJUR.asn1.DERBitString
+ +
+ + +
+ + +
+ + {string} + bitstrtobinstr(h) + +
+
+ convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string
+This function converts from hexadecimal string of ASN.1 BitString +value with unused bit to its integer value.
+When an improper hexadecimal string of BitString value +is applied, this returns null. + +
+ Defined in: base64x-1.1.js. + + +
+ + + +
bitstrtobinstr("05a0") → "101"
+bitstrtobinstr("07a080") → "101000001"
+bitstrtoint(502) → null // non ASN.1 BitString value
+bitstrtoint("ff00") → -1 // for improper BitString value
+ + + + +
+
Parameters:
+ +
+ {string} h + +
+
hexadecimal string of ASN.1 BitString value with unused bit
+ +
+ + + +
+
Since:
+
jsrsasign 10.5.4 base64x 1.1.21
+
+ + + + +
+
Returns:
+ +
{string} binary string
+ +
+ + + +
+
See:
+ +
binstrtobitstr
+ +
inttobitstr
+ +
+ +
@@ -1696,7 +1864,9 @@

convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value
This function converts from hexadecimal string of ASN.1 BitString -value with unused bit to its integer value. +value with unused bit to its integer value.
+When an improper hexadecimal string of BitString value +is applied, this returns -1.
Defined in: base64x-1.1.js. @@ -1710,7 +1880,11 @@

bitstrtoint("03c8") → 25 // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02 // 11111111111110b → 16382 -bitstrtoint("02fff8") → 16382 +bitstrtoint("02fff8") → 16382 +bitstrtoint("05a0") → 5 (=101b) +bitstrtoint("ff00") → -1 // for improper BitString value +bitstrtoint("05a0").toString(2) → "101" +bitstrtoint("07a080").toString(2) → "101000001" @@ -2763,7 +2937,8 @@

convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit
This function converts from an integer value to hexadecimal string of ASN.1 BitString value -with unused bit. +with unused bit.
+When "n" is not non-negative number, this returns null
Defined in: base64x-1.1.js. @@ -2774,7 +2949,12 @@

// 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8"
-inttobitstr(25) → "03c8"
+inttobitstr(25) → "03c8" +inttobitstr(-3) → null +inttobitstr("abc") → null +inttobitstr(parseInt("11001", 2)) → "03c8" +inttobitstr(parseInt("101", 2)) → "05a0" +inttobitstr(parseInt("101000001", 2)) → "07a080" diff --git a/api/symbols/src/asn1-1.0.js.html b/api/symbols/src/asn1-1.0.js.html index 0a9d2d2d..0256dd45 100644 --- a/api/symbols/src/asn1-1.0.js.html +++ b/api/symbols/src/asn1-1.0.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
  1 /* asn1-1.0.22.js (c) 2013-2021 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* asn1-1.0.23.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
   2  */
   3 /*
   4  * asn1.js - ASN.1 DER encoder classes
   5  *
-  6  * Copyright (c) 2013-2020 Kenji Urushima (kenji.urushima@gmail.com)
+  6  * Copyright (c) 2013-2022 Kenji Urushima (kenji.urushima@gmail.com)
   7  *
   8  * This software is licensed under the terms of the MIT License.
   9  * https://kjur.github.io/jsrsasign/license
@@ -23,7 +23,7 @@
  16  * @fileOverview
  17  * @name asn1-1.0.js
  18  * @author Kenji Urushima kenji.urushima@gmail.com
- 19  * @version jsrsasign 10.4.1 asn1 1.0.22 (2021-Sep-30)
+ 19  * @version jsrsasign 10.5.4 asn1 1.0.23 (2022-Feb-14)
  20  * @since jsrsasign 2.1
  21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  22  */
@@ -1048,7 +1048,7 @@
 1041      * NOTE: Trailing zeros '0' will be ignored.
 1042      * @example
 1043      * o = new KJUR.asn1.DERBitString();
-1044      * o.setByBooleanArray("01011");
+1044      * o.setByBinaryString("01011");
 1045      */
 1046     this.setByBinaryString = function(binaryString) {
 1047         binaryString = binaryString.replace(/0+$/, '');
@@ -1763,69 +1763,81 @@
 1756 KJUR.asn1.DERTaggedObject = function(params) {
 1757     KJUR.asn1.DERTaggedObject.superclass.constructor.call(this);
 1758 
-1759     var _KJUR_asn1 = KJUR.asn1;
-1760 
-1761     this.hT = "a0";
-1762     this.hV = '';
-1763     this.isExplicit = true;
-1764     this.asn1Object = null;
-1765 
-1766     /**
-1767      * set value by an ASN1Object
-1768      * @name setString
-1769      * @memberOf KJUR.asn1.DERTaggedObject#
-1770      * @function
-1771      * @param {Boolean} isExplicitFlag flag for explicit/implicit tag
-1772      * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag
-1773      * @param {ASN1Object} asn1Object ASN.1 to encapsulate
-1774      */
-1775     this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) {
-1776         this.hT = tagNoHex;
-1777         this.isExplicit = isExplicitFlag;
-1778         this.asn1Object = asn1Object;
-1779         if (this.isExplicit) {
-1780             this.hV = this.asn1Object.getEncodedHex();
-1781             this.hTLV = null;
-1782             this.isModified = true;
-1783         } else {
-1784             this.hV = null;
-1785             this.hTLV = asn1Object.getEncodedHex();
-1786             this.hTLV = this.hTLV.replace(/^../, tagNoHex);
-1787             this.isModified = false;
-1788         }
-1789     };
-1790 
-1791     this.getFreshValueHex = function() {
-1792         return this.hV;
-1793     };
-1794 
-1795     this.setByParam = function(params) {
-1796         if (params.tag != undefined) {
-1797             this.hT = params.tag;
-1798         }
-1799         if (params.explicit != undefined) {
-1800             this.isExplicit = params.explicit;
-1801         }
-1802 	if (params.tage != undefined) {
-1803 	    this.hT = params.tage;
-1804             this.isExplicit = true;
-1805 	}
-1806 	if (params.tagi != undefined) {
-1807 	    this.hT = params.tagi;
-1808             this.isExplicit = false;
-1809 	}
-1810         if (params.obj != undefined) {
-1811 	    if (params.obj instanceof _KJUR_asn1.ASN1Object) {
-1812 		this.asn1Object = params.obj;
-1813 		this.setASN1Object(this.isExplicit, this.hT, this.asn1Object);
-1814 	    } else if (typeof params.obj == "object") {
-1815 		this.asn1Object = _KJUR_asn1.ASN1Util.newObject(params.obj);
-1816 		this.setASN1Object(this.isExplicit, this.hT, this.asn1Object);
-1817 	    }
-1818         }
-1819     };
+1759     var _KJUR_asn1 = KJUR.asn1,
+1760 	_ASN1HEX = ASN1HEX,
+1761 	_getV = _ASN1HEX.getV,
+1762 	_isASN1HEX = _ASN1HEX.isASN1HEX,
+1763 	_newObject = _KJUR_asn1.ASN1Util.newObject;
+1764 
+1765     this.hT = "a0";
+1766     this.hV = '';
+1767     this.isExplicit = true;
+1768     this.asn1Object = null;
+1769     this.params = {tag: "a0", explicit: true}; //"tag": "a0, "explicit": true};
+1770 
+1771     /**
+1772      * set value by an ASN1Object
+1773      * @name setString
+1774      * @memberOf KJUR.asn1.DERTaggedObject#
+1775      * @function
+1776      * @param {Boolean} isExplicitFlag flag for explicit/implicit tag
+1777      * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag
+1778      * @param {ASN1Object} asn1Object ASN.1 to encapsulate
+1779      * @deprecated since jsrsasign 10.5.4 please use setByParam instead
+1780      */
+1781     this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) {
+1782 	this.params = {tag: tagNoHex,
+1783 		       explicit: isExplicitFlag,
+1784 		       obj: asn1Object};
+1785     };
+1786 
+1787     this.getFreshValueHex = function() {
+1788 	var params = this.params;
+1789 
+1790 	if (params.explicit == undefined) params.explicit = true;
+1791 
+1792 	if (params.tage != undefined) {
+1793 	    params.tag = params.tage;
+1794 	    params.explicit = true;
+1795 	}
+1796 	if (params.tagi != undefined) {
+1797 	    params.tag = params.tagi;
+1798 	    params.explicit = false;
+1799 	}
+1800 
+1801 	if (params.str != undefined) {
+1802 	    this.hV = utf8tohex(params.str);
+1803 	} else if (params.hex != undefined) {
+1804 	    this.hV = params.hex;
+1805 	} else if (params.obj != undefined) {
+1806 	    var hV1;
+1807 	    if (params.obj instanceof _KJUR_asn1.ASN1Object) {
+1808 		hV1 = params.obj.getEncodedHex();
+1809 	    } else if (typeof params.obj == "object") {
+1810 		hV1 = _newObject(params.obj).getEncodedHex();
+1811 	    }
+1812 	    if (params.explicit) {
+1813 		this.hV = hV1;
+1814 	    } else {
+1815 		this.hV = _getV(hV1, 0);
+1816 	    }
+1817 	} else {
+1818 	    throw new Error("str, hex nor obj not specified");
+1819 	}
 1820 
-1821     if (params != undefined) this.setByParam(params);
-1822 };
-1823 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object);
-1824 
\ No newline at end of file +1821
if (params.tag == undefined) params.tag = "a0"; +1822 this.hT = params.tag; +1823 this.hTLV = null; +1824 this.isModified = true; +1825 +1826 return this.hV; +1827 }; +1828 +1829 this.setByParam = function(params) { +1830 this.params = params; +1831 }; +1832 +1833 if (params !== undefined) this.setByParam(params); +1834 }; +1835 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); +1836
\ No newline at end of file diff --git a/api/symbols/src/asn1hex-1.1.js.html b/api/symbols/src/asn1hex-1.1.js.html index 47bea469..5723b22b 100644 --- a/api/symbols/src/asn1hex-1.1.js.html +++ b/api/symbols/src/asn1hex-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 /* asn1hex-1.2.10.js (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* asn1hex-1.2.11.js (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
   2  */
   3 /*
   4  * asn1hex.js - Hexadecimal represented ASN.1 string library
@@ -23,7 +23,7 @@
  16  * @fileOverview
  17  * @name asn1hex-1.1.js
  18  * @author Kenji Urushima kenji.urushima@gmail.com
- 19  * @version jsrsasign 10.5.3 asn1hex 1.2.10 (2022-Feb-10)
+ 19  * @version jsrsasign 10.5.4 asn1hex 1.2.11 (2022-Feb-14)
  20  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  21  */
  22 
@@ -1026,290 +1026,332 @@
 1019  * @example
 1020  */
 1021 ASN1HEX.parse = function(h) {
-1022     var _ASN1HEX = ASN1HEX;
-1023     var _parse = _ASN1HEX.parse;
-1024     var _getV = _ASN1HEX.getV;
-1025     var _getTLV = _ASN1HEX.getTLV;
-1026     var _dump = _ASN1HEX.dump;
-1027     var _getChildIdx = _ASN1HEX.getChildIdx;
-1028     var tagName = {
-1029 	"0c": "utf8str", "13": "prnstr", "14": "telstr",
-1030 	"16": "ia5str", "17": "utctime", "18": "gentime",
-1031 	"1a": "visstr", "1e": "bmpstr", "30": "seq",
-1032 	"31": "set"
-1033     };
-1034 
-1035     var _parseChild = function(h) {
-1036 	var result = [];
-1037 	var aIdx = _getChildIdx(h, 0);
-1038 	for (var i = 0; i < aIdx.length; i++) {
-1039 	    var idx = aIdx[i];
-1040 	    var hTLV = _getTLV(h, idx);
-1041 	    var pItem = _parse(hTLV);
-1042 	    result.push(pItem);
-1043 	}
-1044 	return result;
-1045     };
-1046 
-1047     var tag = h.substr(0, 2);
-1048     var result = {};
-1049     var hV = _getV(h, 0);
-1050     if (tag == "01") {
-1051 	if (h == "0101ff") return {bool: true};
-1052 	return {bool: false};
-1053     } else if (tag == "02") {
-1054 	return {"int": {hex: hV}};
-1055     } else if (tag == "03") {
-1056 	return {bitstr: {hex: hV}};
-1057     } else if (tag == "04") {
-1058 	return {octstr: {hex: hV}};
-1059     } else if (tag == "05") {
-1060 	return {"null": ''};
-1061     } else if (tag == "06") {
-1062 	var oidDot = KJUR.asn1.ASN1Util.oidHexToInt(hV);
-1063 	var oidName = KJUR.asn1.x509.OID.oid2name(oidDot);
-1064 	return {oid: oidName};
-1065     } else if (tag == "0a") {
-1066 	if (hV.length > 4) {
-1067 	    return {"enum": {hex: hV}};
-1068 	} else {
-1069 	    return {"enum": parseInt(hV, 16)};
-1070 	}
-1071     } else if (tag == "30" || tag == "31") {
-1072 	result[tagName[tag]] = _parseChild(h);
-1073 	return result;
-1074     } else if (":0c:13:14:16:17:18:1a:1e:".indexOf(tag) != -1) {
-1075 	var s = hextoutf8(hV);
-1076 	result[tagName[tag]] = {str: s};
-1077 	return result;
-1078     } else if (tag.match(/^8[0-9]$/)) {
-1079 	return {"tag": {"tag": tag, explicit: false, hex: hV}};
-1080     } else if (tag.match(/^a[0-9]$/)) {
-1081 	return {"tag": {"tag": tag, explicit: true, hex: hV}};
-1082     } else {
-1083 	var d = new KJUR.asn1.ASN1Object();
-1084 	d.hV = hV;
-1085 	var hL = d.getLengthHexFromValue();
-1086 	return {"asn1": {"tlv": tag + hL + hV}};
-1087     }
-1088 };
-1089 
-1090 /**
-1091  * check if a hexadecimal tag is a specified ASN.1 context specific tag
-1092  * @name isContextTag
-1093  * @memberOf ASN1HEX
-1094  * @function
-1095  * @param {hTag} hex string of a hexadecimal ASN.1 tag consists by two characters (e.x. "a0")
-1096  * @param {sTag} context specific tag in string represention (OPTION) (e.x. "[0]")
-1097  * @return {Boolean} true if hTag is a ASN.1 context specific tag specified by sTag value.
-1098  * @since jsrsasign 8.0.21 asn1hex 1.2.2
-1099  * @description
-1100  * This method checks if a hexadecimal tag is a specified ASN.1 context specific tag.
-1101  * Structured and non-structured type of tag have the same string representation
-1102  * of context specific tag. For example tag "a0" and "80" have the same string
-1103  * representation "[0]".
-1104  * The sTag has a range from from "[0]" to "[31]".
-1105  * @example
-1106  * ASN1HEX.isContextTag('a0', '[0]') → true // structured
-1107  * ASN1HEX.isContextTag('a1', '[1]') → true // structured
-1108  * ASN1HEX.isContextTag('a2', '[2]') → true // structured
-1109  * ASN1HEX.isContextTag('80', '[0]') → true // non structured
-1110  * ASN1HEX.isContextTag('81', '[1]') → true // non structured
-1111  * ASN1HEX.isContextTag('82', '[2]') → true // non structured
-1112  * ASN1HEX.isContextTag('a0', '[3]') → false
-1113  * ASN1HEX.isContextTag('80', '[15]') → false
-1114  *
-1115  * ASN.1 tag bits
-1116  * 12345679
-1117  * ++        tag class(universal:00, context specific:10)
-1118  *   +       structured:1, primitive:0
-1119  *    +++++  tag number (0 - 31)
-1120  */
-1121 ASN1HEX.isContextTag = function(hTag, sTag) {
-1122     hTag = hTag.toLowerCase();
-1123     var ihtag, istag;
-1124 
-1125     try {
-1126 	ihtag = parseInt(hTag, 16);
-1127     } catch (ex) {
-1128 	return -1;
+1022     var _ASN1HEX = ASN1HEX,
+1023 	_parse = _ASN1HEX.parse,
+1024 	_isASN1HEX = _ASN1HEX.isASN1HEX,
+1025 	_getV = _ASN1HEX.getV,
+1026 	_getTLV = _ASN1HEX.getTLV,
+1027 	_getChildIdx = _ASN1HEX.getChildIdx,
+1028 	_KJUR_asn1 = KJUR.asn1,
+1029 	_oidHexToInt = _KJUR_asn1.ASN1Util.oidHexToInt,
+1030 	_oid2name = _KJUR_asn1.x509.OID.oid2name,
+1031 	_hextoutf8 = hextoutf8;
+1032 
+1033     var tagName = {
+1034 	"0c": "utf8str", "13": "prnstr", "14": "telstr",
+1035 	"16": "ia5str", "17": "utctime", "18": "gentime",
+1036 	"1a": "visstr", "1e": "bmpstr", "30": "seq",
+1037 	"31": "set"
+1038     };
+1039 
+1040     var _parseChild = function(h) {
+1041 	var result = [];
+1042 	var aIdx = _getChildIdx(h, 0);
+1043 	for (var i = 0; i < aIdx.length; i++) {
+1044 	    var idx = aIdx[i];
+1045 	    var hTLV = _getTLV(h, idx);
+1046 	    var pItem = _parse(hTLV);
+1047 	    result.push(pItem);
+1048 	}
+1049 	return result;
+1050     };
+1051 
+1052     var tag = h.substr(0, 2);
+1053     var result = {};
+1054     var hV = _getV(h, 0);
+1055     if (tag == "01") {
+1056 	if (h == "0101ff") return {bool: true};
+1057 	return {bool: false};
+1058     } else if (tag == "02") {
+1059 	return {"int": {hex: hV}};
+1060     } else if (tag == "03") {
+1061 	try {
+1062 	    if (hV.substr(0, 2) != "00") throw "not encap";
+1063 	    var hV1 = hV.substr(2);
+1064 	    if (! _isASN1HEX(hV1)) throw "not encap";
+1065 	    return {bitstr: {obj: _parse(hV1)}};
+1066 	} catch(ex) {
+1067 	    var bV = null;
+1068 	    if (hV.length <= 6) bV = bitstrtobinstr(hV);
+1069 	    if (bV == null) {
+1070 		return {bitstr: {hex: hV}};
+1071 	    } else {
+1072 		return {bitstr: {bin: bV}};
+1073 	    }
+1074 	}
+1075     } else if (tag == "04") {
+1076 	try {
+1077 	    if (! _isASN1HEX(hV)) throw "not encap";
+1078 	    return {octstr: {obj: _parse(hV)}};
+1079 	} catch(ex) {
+1080 	    return {octstr: {hex: hV}};
+1081 	}
+1082     } else if (tag == "05") {
+1083 	return {"null": ''};
+1084     } else if (tag == "06") {
+1085 	var oidDot = _oidHexToInt(hV);
+1086 	var oidName = _oid2name(oidDot);
+1087 	if (oidName == "") {
+1088 	    return {oid: oidDot};
+1089 	} else {
+1090 	    return {oid: oidName};
+1091 	}
+1092     } else if (tag == "0a") {
+1093 	if (hV.length > 4) {
+1094 	    return {"enum": {hex: hV}};
+1095 	} else {
+1096 	    return {"enum": parseInt(hV, 16)};
+1097 	}
+1098     } else if (tag == "30" || tag == "31") {
+1099 	result[tagName[tag]] = _parseChild(h);
+1100 	return result;
+1101     } else if (":0c:13:14:16:17:18:1a:1e:".indexOf(tag) != -1) {
+1102 	var s = _hextoutf8(hV);
+1103 	result[tagName[tag]] = {str: s};
+1104 	return result;
+1105     } else if (tag.match(/^8[0-9]$/)) {
+1106 	var s = _hextoutf8(hV);
+1107 	if (s == null |
+1108 	    s == "" | 
+1109 	    (s.match(/[\x00-\x1F\x7F-\x9F]/) != null) |
+1110 	    (s.match(/[\u0000-\u001F\u0080–\u009F]/) != null)) {
+1111 	    return {"tag": {"tag": tag, explicit: false, hex: hV}};
+1112 	} else {
+1113 	    return {"tag": {"tag": tag, explicit: false, str: s}};
+1114 	}
+1115     } else if (tag.match(/^a[0-9]$/)) {
+1116 	try {
+1117 	    if (! _isASN1HEX(hV)) throw "not encap";
+1118 	    return {"tag": {"tag": tag, 
+1119 			    explicit: true,
+1120 			    obj: _parse(hV)}};
+1121 	} catch(ex) {
+1122 	    return {"tag": {"tag": tag, explicit: true, hex: hV}};
+1123 	}
+1124     } else {
+1125 	var d = new KJUR.asn1.ASN1Object();
+1126 	d.hV = hV;
+1127 	var hL = d.getLengthHexFromValue();
+1128 	return {"asn1": {"tlv": tag + hL + hV}};
 1129     }
-1130 	
-1131     if (sTag === undefined) {
-1132 	if ((ihtag & 192) == 128) {
-1133 	    return true;
-1134 	} else {
-1135 	    return false;
-1136 	}
-1137     }
-1138 
-1139     try {
-1140 	var result = sTag.match(/^\[[0-9]+\]$/);
-1141 	if (result == null) return false;
-1142 	istag = parseInt(sTag.substr(1,sTag.length - 1), 10);
-1143 	if (istag > 31) return false;
-1144 	if (((ihtag & 192) == 128) &&   // ihtag & b11000000 == b10000000
-1145 	    ((ihtag & 31) == istag)) {  // ihtag & b00011111 == istag (0-31)
-1146 	    return true;
-1147 	}
-1148 	return false;
-1149     } catch (ex) {
-1150 	return false;
-1151     }
-1152 };
-1153 
-1154 /**
-1155  * simple ASN.1 DER hexadecimal string checker<br/>
-1156  * @name isASN1HEX
-1157  * @memberOf ASN1HEX
-1158  * @function
-1159  * @param {String} hex string to check whether it is hexadecmal string for ASN.1 DER or not
-1160  * @return {Boolean} true if it is hexadecimal string of ASN.1 data otherwise false
-1161  * @since jsrsasign 4.8.3 asn1hex 1.1.6
-1162  * @description
-1163  * This method checks wheather the argument 'hex' is a hexadecimal string of
-1164  * ASN.1 data or not.
-1165  * @example
-1166  * ASN1HEX.isASN1HEX('0203012345') → true // PROPER ASN.1 INTEGER
-1167  * ASN1HEX.isASN1HEX('0203012345ff') → false // TOO LONG VALUE
-1168  * ASN1HEX.isASN1HEX('02030123') → false // TOO SHORT VALUE
-1169  * ASN1HEX.isASN1HEX('fa3bcd') → false // WRONG FOR ASN.1
-1170  */
-1171 ASN1HEX.isASN1HEX = function(hex) {
-1172     var _ASN1HEX = ASN1HEX;
-1173     if (hex.length % 2 == 1) return false;
-1174 
-1175     var intL = _ASN1HEX.getVblen(hex, 0);
-1176     var hT = hex.substr(0, 2);
-1177     var hL = _ASN1HEX.getL(hex, 0);
-1178     var hVLength = hex.length - hT.length - hL.length;
-1179     if (hVLength == intL * 2) return true;
+1130 };
+1131 
+1132 /**
+1133  * check if a hexadecimal tag is a specified ASN.1 context specific tag
+1134  * @name isContextTag
+1135  * @memberOf ASN1HEX
+1136  * @function
+1137  * @param {hTag} hex string of a hexadecimal ASN.1 tag consists by two characters (e.x. "a0")
+1138  * @param {sTag} context specific tag in string represention (OPTION) (e.x. "[0]")
+1139  * @return {Boolean} true if hTag is a ASN.1 context specific tag specified by sTag value.
+1140  * @since jsrsasign 8.0.21 asn1hex 1.2.2
+1141  * @description
+1142  * This method checks if a hexadecimal tag is a specified ASN.1 context specific tag.
+1143  * Structured and non-structured type of tag have the same string representation
+1144  * of context specific tag. For example tag "a0" and "80" have the same string
+1145  * representation "[0]".
+1146  * The sTag has a range from from "[0]" to "[31]".
+1147  * @example
+1148  * ASN1HEX.isContextTag('a0', '[0]') → true // structured
+1149  * ASN1HEX.isContextTag('a1', '[1]') → true // structured
+1150  * ASN1HEX.isContextTag('a2', '[2]') → true // structured
+1151  * ASN1HEX.isContextTag('80', '[0]') → true // non structured
+1152  * ASN1HEX.isContextTag('81', '[1]') → true // non structured
+1153  * ASN1HEX.isContextTag('82', '[2]') → true // non structured
+1154  * ASN1HEX.isContextTag('a0', '[3]') → false
+1155  * ASN1HEX.isContextTag('80', '[15]') → false
+1156  *
+1157  * ASN.1 tag bits
+1158  * 12345679
+1159  * ++        tag class(universal:00, context specific:10)
+1160  *   +       structured:1, primitive:0
+1161  *    +++++  tag number (0 - 31)
+1162  */
+1163 ASN1HEX.isContextTag = function(hTag, sTag) {
+1164     hTag = hTag.toLowerCase();
+1165     var ihtag, istag;
+1166 
+1167     try {
+1168 	ihtag = parseInt(hTag, 16);
+1169     } catch (ex) {
+1170 	return -1;
+1171     }
+1172 	
+1173     if (sTag === undefined) {
+1174 	if ((ihtag & 192) == 128) {
+1175 	    return true;
+1176 	} else {
+1177 	    return false;
+1178 	}
+1179     }
 1180 
-1181     return false;
-1182 };
-1183 
-1184 /**
-1185  * strict ASN.1 DER hexadecimal string checker
-1186  * @name checkStrictDER
-1187  * @memberOf ASN1HEX
-1188  * @function
-1189  * @param {String} hex string to check whether it is hexadecmal string for ASN.1 DER or not
-1190  * @return unspecified
-1191  * @since jsrsasign 8.0.19 asn1hex 1.2.1
-1192  * @throws Error when malformed ASN.1 DER hexadecimal string
-1193  * @description
-1194  * This method checks wheather the argument 'hex' is a hexadecimal string of
-1195  * ASN.1 data or not. If the argument is not DER string, this 
-1196  * raise an exception.
-1197  * @example
-1198  * ASN1HEX.checkStrictDER('0203012345') → NO EXCEPTION FOR PROPER ASN.1 INTEGER
-1199  * ASN1HEX.checkStrictDER('0203012345ff') → RAISE EXCEPTION FOR TOO LONG VALUE
-1200  * ASN1HEX.checkStrictDER('02030123') → false RAISE EXCEPITON FOR TOO SHORT VALUE
-1201  * ASN1HEX.checkStrictDER('fa3bcd') → false RAISE EXCEPTION FOR WRONG ASN.1
-1202  */
-1203 ASN1HEX.checkStrictDER = function(h, idx, maxHexLen, maxByteLen, maxLbyteLen) {
-1204     var _ASN1HEX = ASN1HEX;
-1205 
-1206     if (maxHexLen === undefined) {
-1207 	// 1. hex string check
-1208 	if (typeof h != "string") throw new Error("not hex string");
-1209 	h = h.toLowerCase();
-1210 	if (! KJUR.lang.String.isHex(h)) throw new Error("not hex string");
-1211 
-1212 	// 2. set max if needed
-1213 	// max length of hexadecimal string
-1214 	maxHexLen = h.length;
-1215 	// max length of octets
-1216 	maxByteLen = h.length / 2;
-1217 	// max length of L octets of TLV
-1218 	if (maxByteLen < 0x80) {
-1219 	    maxLbyteLen = 1;
-1220 	} else {
-1221 	    maxLbyteLen = Math.ceil(maxByteLen.toString(16)) + 1;
-1222 	}
-1223     }
-1224     //console.log(maxHexLen + ":" + maxByteLen + ":" + maxLbyteLen);
+1181     try {
+1182 	var result = sTag.match(/^\[[0-9]+\]$/);
+1183 	if (result == null) return false;
+1184 	istag = parseInt(sTag.substr(1,sTag.length - 1), 10);
+1185 	if (istag > 31) return false;
+1186 	if (((ihtag & 192) == 128) &&   // ihtag & b11000000 == b10000000
+1187 	    ((ihtag & 31) == istag)) {  // ihtag & b00011111 == istag (0-31)
+1188 	    return true;
+1189 	}
+1190 	return false;
+1191     } catch (ex) {
+1192 	return false;
+1193     }
+1194 };
+1195 
+1196 /**
+1197  * simple ASN.1 DER hexadecimal string checker<br/>
+1198  * @name isASN1HEX
+1199  * @memberOf ASN1HEX
+1200  * @function
+1201  * @param {String} hex string to check whether it is hexadecmal string for ASN.1 DER or not
+1202  * @return {Boolean} true if it is hexadecimal string of ASN.1 data otherwise false
+1203  * @since jsrsasign 4.8.3 asn1hex 1.1.6
+1204  * @description
+1205  * This method checks wheather the argument 'hex' is a hexadecimal string of
+1206  * ASN.1 data or not.
+1207  * @example
+1208  * ASN1HEX.isASN1HEX('0203012345') → true // PROPER ASN.1 INTEGER
+1209  * ASN1HEX.isASN1HEX('0203012345ff') → false // TOO LONG VALUE
+1210  * ASN1HEX.isASN1HEX('02030123') → false // TOO SHORT VALUE
+1211  * ASN1HEX.isASN1HEX('fa3bcd') → false // WRONG FOR ASN.1
+1212  */
+1213 ASN1HEX.isASN1HEX = function(hex) {
+1214     var _ASN1HEX = ASN1HEX;
+1215     if (hex.length % 2 == 1) return false;
+1216 
+1217     var intL = _ASN1HEX.getVblen(hex, 0);
+1218     var hT = hex.substr(0, 2);
+1219     var hL = _ASN1HEX.getL(hex, 0);
+1220     var hVLength = hex.length - hT.length - hL.length;
+1221     if (hVLength == intL * 2) return true;
+1222 
+1223     return false;
+1224 };
 1225 
-1226     // 3. check if L(length) string not exceeds maxLbyteLen
-1227     var hL = _ASN1HEX.getL(h, idx);
-1228     if (hL.length > maxLbyteLen * 2)
-1229 	throw new Error("L of TLV too long: idx=" + idx);
-1230 
-1231     // 4. check if V(value) octet length (i.e. L(length) value) 
-1232     //    not exceeds maxByteLen
-1233     var vblen = _ASN1HEX.getVblen(h, idx);
-1234     if (vblen > maxByteLen) 
-1235 	throw new Error("value of L too long than hex: idx=" + idx);
-1236 
-1237     // 5. check V string length and L's value are the same
-1238     var hTLV = _ASN1HEX.getTLV(h, idx);
-1239     var hVLength = 
-1240 	hTLV.length - 2 - _ASN1HEX.getL(h, idx).length;
-1241     if (hVLength !== (vblen * 2))
-1242 	throw new Error("V string length and L's value not the same:" +
-1243 		        hVLength + "/" + (vblen * 2));
-1244 
-1245     // 6. check appending garbled string
-1246     if (idx === 0) {
-1247 	if (h.length != hTLV.length)
-1248 	    throw new Error("total length and TLV length unmatch:" +
-1249 			    h.length + "!=" + hTLV.length);
-1250     }
-1251 
-1252     // 7. check if there isn't prepending zeros in DER INTEGER value
-1253     var hT = h.substr(idx, 2);
-1254     if (hT === '02') {
-1255 	var vidx = _ASN1HEX.getVidx(h, idx);
-1256 	// check if DER INTEGER VALUE have least leading zeros 
-1257 	// for two's complement
-1258 	// GOOD - 3fabde... 008fad...
-1259 	// BAD  - 000012... 007fad...
-1260 	if (h.substr(vidx, 2) == "00" && h.charCodeAt(vidx + 2) < 56) // '8'=56
-1261 	    throw new Error("not least zeros for DER INTEGER");
-1262     }
-1263 
-1264     // 8. check if all of elements in a structured item are conformed to
-1265     //    strict DER encoding rules.
-1266     if (parseInt(hT, 16) & 32) { // structured tag?
-1267 	var intL = _ASN1HEX.getVblen(h, idx);
-1268 	var sum = 0;
-1269 	var aIdx = _ASN1HEX.getChildIdx(h, idx);
-1270 	for (var i = 0; i < aIdx.length; i++) {
-1271 	    var tlv = _ASN1HEX.getTLV(h, aIdx[i]);
-1272 	    sum += tlv.length;
-1273 	    _ASN1HEX.checkStrictDER(h, aIdx[i], 
-1274 				   maxHexLen, maxByteLen, maxLbyteLen);
-1275 	}
-1276 	if ((intL * 2) != sum)
-1277 	    throw new Error("sum of children's TLV length and L unmatch: " +
-1278 			    (intL * 2) + "!=" + sum);
-1279     }
-1280 };
-1281 
-1282 /**
-1283  * get hexacedimal string from PEM format data<br/>
-1284  * @name oidname
-1285  * @memberOf ASN1HEX
-1286  * @function
-1287  * @param {String} oidDotOrHex number dot notation(i.e. 1.2.3) or hexadecimal string for OID
-1288  * @return {String} name for OID
-1289  * @since jsrsasign 7.2.0 asn1hex 1.1.11
-1290  * @description
-1291  * This static method gets a OID name for
-1292  * a specified string of number dot notation (i.e. 1.2.3) or
-1293  * hexadecimal string.
-1294  * @example
-1295  * ASN1HEX.oidname("2.5.29.37") → extKeyUsage
-1296  * ASN1HEX.oidname("551d25") → extKeyUsage
-1297  * ASN1HEX.oidname("0.1.2.3") → 0.1.2.3 // unknown
-1298  */
-1299 ASN1HEX.oidname = function(oidDotOrHex) {
-1300     var _KJUR_asn1 = KJUR.asn1;
-1301     if (KJUR.lang.String.isHex(oidDotOrHex))
-1302 	oidDotOrHex = _KJUR_asn1.ASN1Util.oidHexToInt(oidDotOrHex);
-1303     var name = _KJUR_asn1.x509.OID.oid2name(oidDotOrHex);
-1304     if (name === "") name = oidDotOrHex;
-1305     return name;
-1306 };
-1307 
-1308 
\ No newline at end of file +1226
/** +1227 * strict ASN.1 DER hexadecimal string checker +1228 * @name checkStrictDER +1229 * @memberOf ASN1HEX +1230 * @function +1231 * @param {String} hex string to check whether it is hexadecmal string for ASN.1 DER or not +1232 * @return unspecified +1233 * @since jsrsasign 8.0.19 asn1hex 1.2.1 +1234 * @throws Error when malformed ASN.1 DER hexadecimal string +1235 * @description +1236 * This method checks wheather the argument 'hex' is a hexadecimal string of +1237 * ASN.1 data or not. If the argument is not DER string, this +1238 * raise an exception. +1239 * @example +1240 * ASN1HEX.checkStrictDER('0203012345') → NO EXCEPTION FOR PROPER ASN.1 INTEGER +1241 * ASN1HEX.checkStrictDER('0203012345ff') → RAISE EXCEPTION FOR TOO LONG VALUE +1242 * ASN1HEX.checkStrictDER('02030123') → false RAISE EXCEPITON FOR TOO SHORT VALUE +1243 * ASN1HEX.checkStrictDER('fa3bcd') → false RAISE EXCEPTION FOR WRONG ASN.1 +1244 */ +1245 ASN1HEX.checkStrictDER = function(h, idx, maxHexLen, maxByteLen, maxLbyteLen) { +1246 var _ASN1HEX = ASN1HEX; +1247 +1248 if (maxHexLen === undefined) { +1249 // 1. hex string check +1250 if (typeof h != "string") throw new Error("not hex string"); +1251 h = h.toLowerCase(); +1252 if (! KJUR.lang.String.isHex(h)) throw new Error("not hex string"); +1253 +1254 // 2. set max if needed +1255 // max length of hexadecimal string +1256 maxHexLen = h.length; +1257 // max length of octets +1258 maxByteLen = h.length / 2; +1259 // max length of L octets of TLV +1260 if (maxByteLen < 0x80) { +1261 maxLbyteLen = 1; +1262 } else { +1263 maxLbyteLen = Math.ceil(maxByteLen.toString(16)) + 1; +1264 } +1265 } +1266 //console.log(maxHexLen + ":" + maxByteLen + ":" + maxLbyteLen); +1267 +1268 // 3. check if L(length) string not exceeds maxLbyteLen +1269 var hL = _ASN1HEX.getL(h, idx); +1270 if (hL.length > maxLbyteLen * 2) +1271 throw new Error("L of TLV too long: idx=" + idx); +1272 +1273 // 4. check if V(value) octet length (i.e. L(length) value) +1274 // not exceeds maxByteLen +1275 var vblen = _ASN1HEX.getVblen(h, idx); +1276 if (vblen > maxByteLen) +1277 throw new Error("value of L too long than hex: idx=" + idx); +1278 +1279 // 5. check V string length and L's value are the same +1280 var hTLV = _ASN1HEX.getTLV(h, idx); +1281 var hVLength = +1282 hTLV.length - 2 - _ASN1HEX.getL(h, idx).length; +1283 if (hVLength !== (vblen * 2)) +1284 throw new Error("V string length and L's value not the same:" + +1285 hVLength + "/" + (vblen * 2)); +1286 +1287 // 6. check appending garbled string +1288 if (idx === 0) { +1289 if (h.length != hTLV.length) +1290 throw new Error("total length and TLV length unmatch:" + +1291 h.length + "!=" + hTLV.length); +1292 } +1293 +1294 // 7. check if there isn't prepending zeros in DER INTEGER value +1295 var hT = h.substr(idx, 2); +1296 if (hT === '02') { +1297 var vidx = _ASN1HEX.getVidx(h, idx); +1298 // check if DER INTEGER VALUE have least leading zeros +1299 // for two's complement +1300 // GOOD - 3fabde... 008fad... +1301 // BAD - 000012... 007fad... +1302 if (h.substr(vidx, 2) == "00" && h.charCodeAt(vidx + 2) < 56) // '8'=56 +1303 throw new Error("not least zeros for DER INTEGER"); +1304 } +1305 +1306 // 8. check if all of elements in a structured item are conformed to +1307 // strict DER encoding rules. +1308 if (parseInt(hT, 16) & 32) { // structured tag? +1309 var intL = _ASN1HEX.getVblen(h, idx); +1310 var sum = 0; +1311 var aIdx = _ASN1HEX.getChildIdx(h, idx); +1312 for (var i = 0; i < aIdx.length; i++) { +1313 var tlv = _ASN1HEX.getTLV(h, aIdx[i]); +1314 sum += tlv.length; +1315 _ASN1HEX.checkStrictDER(h, aIdx[i], +1316 maxHexLen, maxByteLen, maxLbyteLen); +1317 } +1318 if ((intL * 2) != sum) +1319 throw new Error("sum of children's TLV length and L unmatch: " + +1320 (intL * 2) + "!=" + sum); +1321 } +1322 }; +1323 +1324 /** +1325 * get hexacedimal string from PEM format data<br/> +1326 * @name oidname +1327 * @memberOf ASN1HEX +1328 * @function +1329 * @param {String} oidDotOrHex number dot notation(i.e. 1.2.3) or hexadecimal string for OID +1330 * @return {String} name for OID +1331 * @since jsrsasign 7.2.0 asn1hex 1.1.11 +1332 * @description +1333 * This static method gets a OID name for +1334 * a specified string of number dot notation (i.e. 1.2.3) or +1335 * hexadecimal string. +1336 * @example +1337 * ASN1HEX.oidname("2.5.29.37") → extKeyUsage +1338 * ASN1HEX.oidname("551d25") → extKeyUsage +1339 * ASN1HEX.oidname("0.1.2.3") → 0.1.2.3 // unknown +1340 */ +1341 ASN1HEX.oidname = function(oidDotOrHex) { +1342 var _KJUR_asn1 = KJUR.asn1; +1343 if (KJUR.lang.String.isHex(oidDotOrHex)) +1344 oidDotOrHex = _KJUR_asn1.ASN1Util.oidHexToInt(oidDotOrHex); +1345 var name = _KJUR_asn1.x509.OID.oid2name(oidDotOrHex); +1346 if (name === "") name = oidDotOrHex; +1347 return name; +1348 }; +1349 +1350
\ No newline at end of file diff --git a/api/symbols/src/base64x-1.1.js.html b/api/symbols/src/base64x-1.1.js.html index 24cc8846..d7b1c71d 100644 --- a/api/symbols/src/base64x-1.1.js.html +++ b/api/symbols/src/base64x-1.1.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
  1 /* base64x-1.1.20 (c) 2012-2021 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* base64x-1.1.21 (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
   5  *
-  6  * Copyright (c) 2012-2021 Kenji Urushima (kenji.urushima@gmail.com)
+  6  * Copyright (c) 2012-2022 Kenji Urushima (kenji.urushima@gmail.com)
   7  *
   8  * This software is licensed under the terms of the MIT License.
   9  * https://kjur.github.io/jsrsasign/license
@@ -23,7 +23,7 @@
  16  * @fileOverview
  17  * @name base64x-1.1.js
  18  * @author Kenji Urushima kenji.urushima@gmail.com
- 19  * @version jsrsasign 10.1.13 base64x 1.1.20 (2021-Mar-07)
+ 19  * @version jsrsasign 10.5.4 base64x 1.1.21 (2022-Feb-14)
  20  * @since jsrsasign 2.1
  21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  22  */
@@ -329,7 +329,7 @@
 322  * @since 1.1.1
 323  */
 324 function utf8tohex(s) {
-325   return uricmptohex(encodeURIComponentAll(s));
+325   return uricmptohex(encodeURIComponentAll(s)).toLowerCase();
 326 }
 327 
 328 /**
@@ -343,1228 +343,1317 @@
 336  * @since 1.1.1
 337  */
 338 function hextoutf8(s) {
-339   return decodeURIComponent(hextouricmp(s));
-340 }
-341 
-342 /**
-343  * convert a hexadecimal encoded string to raw string including non printable characters.<br/>
-344  * @name hextorstr
-345  * @function
-346  * @param {String} s hexadecimal encoded string
-347  * @return {String} raw string
-348  * @since 1.1.2
-349  * @example
-350  * hextorstr("610061") → "a\x00a"
-351  */
-352 function hextorstr(sHex) {
-353     var s = "";
-354     for (var i = 0; i < sHex.length - 1; i += 2) {
-355         s += String.fromCharCode(parseInt(sHex.substr(i, 2), 16));
-356     }
-357     return s;
-358 }
-359 
-360 /**
-361  * convert a raw string including non printable characters to hexadecimal encoded string.<br/>
-362  * @name rstrtohex
-363  * @function
-364  * @param {String} s raw string
-365  * @return {String} hexadecimal encoded string
-366  * @since 1.1.2
-367  * @example
-368  * rstrtohex("a\x00a") → "610061"
-369  */
-370 function rstrtohex(s) {
-371     var result = "";
-372     for (var i = 0; i < s.length; i++) {
-373         result += ("0" + s.charCodeAt(i).toString(16)).slice(-2);
-374     }
-375     return result;
-376 }
-377 
-378 // ==== hex / b64nl =======================================
-379 
-380 /**
-381  * convert a hexadecimal string to Base64 encoded string<br/>
-382  * @name hextob64
-383  * @function
-384  * @param {String} s hexadecimal string
-385  * @return {String} resulted Base64 encoded string
-386  * @since base64x 1.1.3
-387  * @description
-388  * This function converts from a hexadecimal string to Base64 encoded
-389  * string without new lines.
-390  * @example
-391  * hextob64("616161") → "YWFh"
-392  */
-393 function hextob64(s) {
-394     return hex2b64(s);
-395 }
-396 
-397 /**
-398  * convert a hexadecimal string to Base64 encoded string with new lines<br/>
-399  * @name hextob64nl
-400  * @function
-401  * @param {String} s hexadecimal string
-402  * @return {String} resulted Base64 encoded string with new lines
-403  * @since base64x 1.1.3
-404  * @description
-405  * This function converts from a hexadecimal string to Base64 encoded
-406  * string with new lines for each 64 characters. This is useful for
-407  * PEM encoded file.
-408  * @example
-409  * hextob64nl("123456789012345678901234567890123456789012345678901234567890")
-410  * →
-411  * MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4 // new line
-412  * OTAxMjM0NTY3ODkwCg==
-413  */
-414 function hextob64nl(s) {
-415     var b64 = hextob64(s);
-416     var b64nl = b64.replace(/(.{64})/g, "$1\r\n");
-417     b64nl = b64nl.replace(/\r\n$/, '');
-418     return b64nl;
-419 }
-420 
-421 /**
-422  * convert a Base64 encoded string with new lines to a hexadecimal string<br/>
-423  * @name b64nltohex
-424  * @function
-425  * @param {String} s Base64 encoded string with new lines
-426  * @return {String} hexadecimal string
-427  * @since base64x 1.1.3
-428  * @description
-429  * This function converts from a Base64 encoded
-430  * string with new lines to a hexadecimal string.
-431  * This is useful to handle PEM encoded file.
-432  * This function removes any non-Base64 characters (i.e. not 0-9,A-Z,a-z,\,+,=)
-433  * including new line.
-434  * @example
-435  * hextob64nl(
-436  * "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4\r\n" +
-437  * "OTAxMjM0NTY3ODkwCg==\r\n")
-438  * →
-439  * "123456789012345678901234567890123456789012345678901234567890"
-440  */
-441 function b64nltohex(s) {
-442     var b64 = s.replace(/[^0-9A-Za-z\/+=]*/g, '');
-443     var hex = b64tohex(b64);
-444     return hex;
-445 } 
-446 
-447 // ==== hex / pem =========================================
-448 
-449 /**
-450  * get PEM string from hexadecimal data and header string
-451  * @name hextopem
-452  * @function
-453  * @param {String} dataHex hexadecimal string of PEM body
-454  * @param {String} pemHeader PEM header string (ex. 'RSA PRIVATE KEY')
-455  * @return {String} PEM formatted string of input data
-456  * @since jsrasign 7.2.1 base64x 1.1.12
-457  * @description
-458  * This function converts a hexadecimal string to a PEM string with
-459  * a specified header. Its line break will be CRLF("\r\n").
-460  * @example
-461  * hextopem('616161', 'RSA PRIVATE KEY') →
-462  * -----BEGIN PRIVATE KEY-----
-463  * YWFh
-464  * -----END PRIVATE KEY-----
-465  */
-466 function hextopem(dataHex, pemHeader) {
-467     var pemBody = hextob64nl(dataHex);
-468     return "-----BEGIN " + pemHeader + "-----\r\n" + 
-469         pemBody + 
-470         "\r\n-----END " + pemHeader + "-----\r\n";
-471 }
-472 
-473 /**
-474  * get hexacedimal string from PEM format data<br/>
-475  * @name pemtohex
-476  * @function
-477  * @param {String} s PEM formatted string
-478  * @param {String} sHead PEM header string without BEGIN/END(OPTION)
-479  * @return {String} hexadecimal string data of PEM contents
-480  * @since jsrsasign 7.2.1 base64x 1.1.12
-481  * @description
-482  * This static method gets a hexacedimal string of contents 
-483  * from PEM format data. You can explicitly specify PEM header 
-484  * by sHead argument. 
-485  * Any space characters such as white space or new line
-486  * will be omitted.<br/>
-487  * NOTE: Now {@link KEYUTIL.getHexFromPEM} and {@link X509.pemToHex}
-488  * have been deprecated since jsrsasign 7.2.1. 
-489  * Please use this method instead.
-490  * NOTE2: From jsrsasign 8.0.14 this can process multi
-491  * "BEGIN...END" section such as "EC PRIVATE KEY" with "EC PARAMETERS".
-492  * @example
-493  * pemtohex("-----BEGIN PUBLIC KEY...") → "3082..."
-494  * pemtohex("-----BEGIN CERTIFICATE...", "CERTIFICATE") → "3082..."
-495  * pemtohex(" \r\n-----BEGIN DSA PRIVATE KEY...") → "3082..."
-496  * pemtohex("-----BEGIN EC PARAMETERS...----BEGIN EC PRIVATE KEY...." → "3082..."
-497  */
-498 function pemtohex(s, sHead) {
-499     if (s.indexOf("-----BEGIN ") == -1)
-500         throw "can't find PEM header: " + sHead;
-501 
-502     if (sHead !== undefined) {
-503         s = s.replace(new RegExp('^[^]*-----BEGIN ' + sHead + '-----'), '');
-504         s = s.replace(new RegExp('-----END ' + sHead + '-----[^]*$'), '');
-505     } else {
-506         s = s.replace(/^[^]*-----BEGIN [^-]+-----/, '');
-507         s = s.replace(/-----END [^-]+-----[^]*$/, '');
-508     }
-509     return b64nltohex(s);
-510 }
-511 
-512 // ==== hex / ArrayBuffer =================================
-513 
-514 /**
-515  * convert a hexadecimal string to an ArrayBuffer<br/>
-516  * @name hextoArrayBuffer
-517  * @function
-518  * @param {String} hex hexadecimal string
-519  * @return {ArrayBuffer} ArrayBuffer
-520  * @since jsrsasign 6.1.4 base64x 1.1.8
-521  * @description
-522  * This function converts from a hexadecimal string to an ArrayBuffer.
-523  * @example
-524  * hextoArrayBuffer("fffa01") → ArrayBuffer of [255, 250, 1]
-525  */
-526 function hextoArrayBuffer(hex) {
-527     if (hex.length % 2 != 0) throw "input is not even length";
-528     if (hex.match(/^[0-9A-Fa-f]+$/) == null) throw "input is not hexadecimal";
-529 
-530     var buffer = new ArrayBuffer(hex.length / 2);
-531     var view = new DataView(buffer);
-532 
-533     for (var i = 0; i < hex.length / 2; i++) {
-534 	view.setUint8(i, parseInt(hex.substr(i * 2, 2), 16));
-535     }
+339   try {
+340     return decodeURIComponent(hextouricmp(s));
+341   } catch(ex) {
+342     return null;
+343   }
+344 }
+345 
+346 /**
+347  * convert a hexadecimal encoded string to raw string including non printable characters.<br/>
+348  * @name hextorstr
+349  * @function
+350  * @param {String} s hexadecimal encoded string
+351  * @return {String} raw string
+352  * @since 1.1.2
+353  * @example
+354  * hextorstr("610061") → "a\x00a"
+355  */
+356 function hextorstr(sHex) {
+357     var s = "";
+358     for (var i = 0; i < sHex.length - 1; i += 2) {
+359         s += String.fromCharCode(parseInt(sHex.substr(i, 2), 16));
+360     }
+361     return s;
+362 }
+363 
+364 /**
+365  * convert a raw string including non printable characters to hexadecimal encoded string.<br/>
+366  * @name rstrtohex
+367  * @function
+368  * @param {String} s raw string
+369  * @return {String} hexadecimal encoded string
+370  * @since 1.1.2
+371  * @example
+372  * rstrtohex("a\x00a") → "610061"
+373  */
+374 function rstrtohex(s) {
+375     var result = "";
+376     for (var i = 0; i < s.length; i++) {
+377         result += ("0" + s.charCodeAt(i).toString(16)).slice(-2);
+378     }
+379     return result;
+380 }
+381 
+382 // ==== hex / b64nl =======================================
+383 
+384 /**
+385  * convert a hexadecimal string to Base64 encoded string<br/>
+386  * @name hextob64
+387  * @function
+388  * @param {String} s hexadecimal string
+389  * @return {String} resulted Base64 encoded string
+390  * @since base64x 1.1.3
+391  * @description
+392  * This function converts from a hexadecimal string to Base64 encoded
+393  * string without new lines.
+394  * @example
+395  * hextob64("616161") → "YWFh"
+396  */
+397 function hextob64(s) {
+398     return hex2b64(s);
+399 }
+400 
+401 /**
+402  * convert a hexadecimal string to Base64 encoded string with new lines<br/>
+403  * @name hextob64nl
+404  * @function
+405  * @param {String} s hexadecimal string
+406  * @return {String} resulted Base64 encoded string with new lines
+407  * @since base64x 1.1.3
+408  * @description
+409  * This function converts from a hexadecimal string to Base64 encoded
+410  * string with new lines for each 64 characters. This is useful for
+411  * PEM encoded file.
+412  * @example
+413  * hextob64nl("123456789012345678901234567890123456789012345678901234567890")
+414  * →
+415  * MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4 // new line
+416  * OTAxMjM0NTY3ODkwCg==
+417  */
+418 function hextob64nl(s) {
+419     var b64 = hextob64(s);
+420     var b64nl = b64.replace(/(.{64})/g, "$1\r\n");
+421     b64nl = b64nl.replace(/\r\n$/, '');
+422     return b64nl;
+423 }
+424 
+425 /**
+426  * convert a Base64 encoded string with new lines to a hexadecimal string<br/>
+427  * @name b64nltohex
+428  * @function
+429  * @param {String} s Base64 encoded string with new lines
+430  * @return {String} hexadecimal string
+431  * @since base64x 1.1.3
+432  * @description
+433  * This function converts from a Base64 encoded
+434  * string with new lines to a hexadecimal string.
+435  * This is useful to handle PEM encoded file.
+436  * This function removes any non-Base64 characters (i.e. not 0-9,A-Z,a-z,\,+,=)
+437  * including new line.
+438  * @example
+439  * hextob64nl(
+440  * "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4\r\n" +
+441  * "OTAxMjM0NTY3ODkwCg==\r\n")
+442  * →
+443  * "123456789012345678901234567890123456789012345678901234567890"
+444  */
+445 function b64nltohex(s) {
+446     var b64 = s.replace(/[^0-9A-Za-z\/+=]*/g, '');
+447     var hex = b64tohex(b64);
+448     return hex;
+449 } 
+450 
+451 // ==== hex / pem =========================================
+452 
+453 /**
+454  * get PEM string from hexadecimal data and header string
+455  * @name hextopem
+456  * @function
+457  * @param {String} dataHex hexadecimal string of PEM body
+458  * @param {String} pemHeader PEM header string (ex. 'RSA PRIVATE KEY')
+459  * @return {String} PEM formatted string of input data
+460  * @since jsrasign 7.2.1 base64x 1.1.12
+461  * @description
+462  * This function converts a hexadecimal string to a PEM string with
+463  * a specified header. Its line break will be CRLF("\r\n").
+464  * @example
+465  * hextopem('616161', 'RSA PRIVATE KEY') →
+466  * -----BEGIN PRIVATE KEY-----
+467  * YWFh
+468  * -----END PRIVATE KEY-----
+469  */
+470 function hextopem(dataHex, pemHeader) {
+471     var pemBody = hextob64nl(dataHex);
+472     return "-----BEGIN " + pemHeader + "-----\r\n" + 
+473         pemBody + 
+474         "\r\n-----END " + pemHeader + "-----\r\n";
+475 }
+476 
+477 /**
+478  * get hexacedimal string from PEM format data<br/>
+479  * @name pemtohex
+480  * @function
+481  * @param {String} s PEM formatted string
+482  * @param {String} sHead PEM header string without BEGIN/END(OPTION)
+483  * @return {String} hexadecimal string data of PEM contents
+484  * @since jsrsasign 7.2.1 base64x 1.1.12
+485  * @description
+486  * This static method gets a hexacedimal string of contents 
+487  * from PEM format data. You can explicitly specify PEM header 
+488  * by sHead argument. 
+489  * Any space characters such as white space or new line
+490  * will be omitted.<br/>
+491  * NOTE: Now {@link KEYUTIL.getHexFromPEM} and {@link X509.pemToHex}
+492  * have been deprecated since jsrsasign 7.2.1. 
+493  * Please use this method instead.
+494  * NOTE2: From jsrsasign 8.0.14 this can process multi
+495  * "BEGIN...END" section such as "EC PRIVATE KEY" with "EC PARAMETERS".
+496  * @example
+497  * pemtohex("-----BEGIN PUBLIC KEY...") → "3082..."
+498  * pemtohex("-----BEGIN CERTIFICATE...", "CERTIFICATE") → "3082..."
+499  * pemtohex(" \r\n-----BEGIN DSA PRIVATE KEY...") → "3082..."
+500  * pemtohex("-----BEGIN EC PARAMETERS...----BEGIN EC PRIVATE KEY...." → "3082..."
+501  */
+502 function pemtohex(s, sHead) {
+503     if (s.indexOf("-----BEGIN ") == -1)
+504         throw "can't find PEM header: " + sHead;
+505 
+506     if (sHead !== undefined) {
+507         s = s.replace(new RegExp('^[^]*-----BEGIN ' + sHead + '-----'), '');
+508         s = s.replace(new RegExp('-----END ' + sHead + '-----[^]*$'), '');
+509     } else {
+510         s = s.replace(/^[^]*-----BEGIN [^-]+-----/, '');
+511         s = s.replace(/-----END [^-]+-----[^]*$/, '');
+512     }
+513     return b64nltohex(s);
+514 }
+515 
+516 // ==== hex / ArrayBuffer =================================
+517 
+518 /**
+519  * convert a hexadecimal string to an ArrayBuffer<br/>
+520  * @name hextoArrayBuffer
+521  * @function
+522  * @param {String} hex hexadecimal string
+523  * @return {ArrayBuffer} ArrayBuffer
+524  * @since jsrsasign 6.1.4 base64x 1.1.8
+525  * @description
+526  * This function converts from a hexadecimal string to an ArrayBuffer.
+527  * @example
+528  * hextoArrayBuffer("fffa01") → ArrayBuffer of [255, 250, 1]
+529  */
+530 function hextoArrayBuffer(hex) {
+531     if (hex.length % 2 != 0) throw "input is not even length";
+532     if (hex.match(/^[0-9A-Fa-f]+$/) == null) throw "input is not hexadecimal";
+533 
+534     var buffer = new ArrayBuffer(hex.length / 2);
+535     var view = new DataView(buffer);
 536 
-537     return buffer;
-538 }
-539 
-540 // ==== ArrayBuffer / hex =================================
-541 
-542 /**
-543  * convert an ArrayBuffer to a hexadecimal string<br/>
-544  * @name ArrayBuffertohex
-545  * @function
-546  * @param {ArrayBuffer} buffer ArrayBuffer
-547  * @return {String} hexadecimal string
-548  * @since jsrsasign 6.1.4 base64x 1.1.8
-549  * @description
-550  * This function converts from an ArrayBuffer to a hexadecimal string.
-551  * @example
-552  * var buffer = new ArrayBuffer(3);
-553  * var view = new DataView(buffer);
-554  * view.setUint8(0, 0xfa);
-555  * view.setUint8(1, 0xfb);
-556  * view.setUint8(2, 0x01);
-557  * ArrayBuffertohex(buffer) → "fafb01"
-558  */
-559 function ArrayBuffertohex(buffer) {
-560     var hex = "";
-561     var view = new DataView(buffer);
-562 
-563     for (var i = 0; i < buffer.byteLength; i++) {
-564 	hex += ("00" + view.getUint8(i).toString(16)).slice(-2);
-565     }
+537     for (var i = 0; i < hex.length / 2; i++) {
+538 	view.setUint8(i, parseInt(hex.substr(i * 2, 2), 16));
+539     }
+540 
+541     return buffer;
+542 }
+543 
+544 // ==== ArrayBuffer / hex =================================
+545 
+546 /**
+547  * convert an ArrayBuffer to a hexadecimal string<br/>
+548  * @name ArrayBuffertohex
+549  * @function
+550  * @param {ArrayBuffer} buffer ArrayBuffer
+551  * @return {String} hexadecimal string
+552  * @since jsrsasign 6.1.4 base64x 1.1.8
+553  * @description
+554  * This function converts from an ArrayBuffer to a hexadecimal string.
+555  * @example
+556  * var buffer = new ArrayBuffer(3);
+557  * var view = new DataView(buffer);
+558  * view.setUint8(0, 0xfa);
+559  * view.setUint8(1, 0xfb);
+560  * view.setUint8(2, 0x01);
+561  * ArrayBuffertohex(buffer) → "fafb01"
+562  */
+563 function ArrayBuffertohex(buffer) {
+564     var hex = "";
+565     var view = new DataView(buffer);
 566 
-567     return hex;
-568 }
-569 
-570 // ==== zulu / int =================================
-571 /**
-572  * GeneralizedTime or UTCTime string to milliseconds from Unix origin<br>
-573  * @name zulutomsec
-574  * @function
-575  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
-576  * @return {Number} milliseconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
-577  * @since jsrsasign 7.1.3 base64x 1.1.9
-578  * @description
-579  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
-580  * UTCTime string (i.e. YYMMDDHHmmSSZ) to milliseconds from Unix origin time
-581  * (i.e. Jan 1 1970 0:00:00 UTC). 
-582  * Argument string may have fraction of seconds and
-583  * its length is one or more digits such as "20170410235959.1234567Z".
-584  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
-585  * If year "YY" is equal or greater than 50 then it is 19YY.
-586  * @example
-587  * zulutomsec(  "071231235959Z")       → 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
-588  * zulutomsec(  "071231235959.1Z")     → 1199145599100 #Mon, 31 Dec 2007 23:59:59 GMT
-589  * zulutomsec(  "071231235959.12345Z") → 1199145599123 #Mon, 31 Dec 2007 23:59:59 GMT
-590  * zulutomsec("20071231235959Z")       → 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
-591  * zulutomsec(  "931231235959Z")       → -410227201000 #Mon, 31 Dec 1956 23:59:59 GMT
-592  */
-593 function zulutomsec(s) {
-594     var year, month, day, hour, min, sec, msec, d;
-595     var sYear, sFrac, sMsec, matchResult;
-596 
-597     matchResult = s.match(/^(\d{2}|\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/);
-598 
-599     if (matchResult) {
-600         sYear = matchResult[1];
-601 	year = parseInt(sYear);
-602         if (sYear.length === 2) {
-603 	    if (50 <= year && year < 100) {
-604 		year = 1900 + year;
-605 	    } else if (0 <= year && year < 50) {
-606 		year = 2000 + year;
-607 	    }
-608 	}
-609 	month = parseInt(matchResult[2]) - 1;
-610 	day = parseInt(matchResult[3]);
-611 	hour = parseInt(matchResult[4]);
-612 	min = parseInt(matchResult[5]);
-613 	sec = parseInt(matchResult[6]);
-614 	msec = 0;
-615 
-616 	sFrac = matchResult[7];
-617 	if (sFrac !== "") {
-618 	    sMsec = (sFrac.substr(1) + "00").substr(0, 3); // .12 -> 012
-619 	    msec = parseInt(sMsec);
-620 	}
-621 	return Date.UTC(year, month, day, hour, min, sec, msec);
-622     }
-623     throw "unsupported zulu format: " + s;
-624 }
-625 
-626 /**
-627  * GeneralizedTime or UTCTime string to seconds from Unix origin<br>
-628  * @name zulutosec
-629  * @function
-630  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
-631  * @return {Number} seconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
-632  * @since jsrsasign 7.1.3 base64x 1.1.9
-633  * @description
-634  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
-635  * UTCTime string (i.e. YYMMDDHHmmSSZ) to seconds from Unix origin time
-636  * (i.e. Jan 1 1970 0:00:00 UTC). Argument string may have fraction of seconds 
-637  * however result value will be omitted.
-638  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
-639  * If year "YY" is equal or greater than 50 then it is 19YY.
-640  * @example
-641  * zulutosec(  "071231235959Z")       → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
-642  * zulutosec(  "071231235959.1Z")     → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
-643  * zulutosec("20071231235959Z")       → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
-644  */
-645 function zulutosec(s) {
-646     var msec = zulutomsec(s);
-647     return ~~(msec / 1000);
-648 }
-649 
-650 // ==== zulu / Date =================================
-651 
-652 /**
-653  * GeneralizedTime or UTCTime string to Date object<br>
-654  * @name zulutodate
-655  * @function
-656  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
-657  * @return {Date} Date object for specified time
-658  * @since jsrsasign 7.1.3 base64x 1.1.9
-659  * @description
-660  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
-661  * UTCTime string (i.e. YYMMDDHHmmSSZ) to Date object.
-662  * Argument string may have fraction of seconds and
-663  * its length is one or more digits such as "20170410235959.1234567Z".
-664  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
-665  * If year "YY" is equal or greater than 50 then it is 19YY.
-666  * @example
-667  * zulutodate(  "071231235959Z").toUTCString()   → "Mon, 31 Dec 2007 23:59:59 GMT"
-668  * zulutodate(  "071231235959.1Z").toUTCString() → "Mon, 31 Dec 2007 23:59:59 GMT"
-669  * zulutodate("20071231235959Z").toUTCString()   → "Mon, 31 Dec 2007 23:59:59 GMT"
-670  * zulutodate(  "071231235959.34").getMilliseconds() → 340
-671  */
-672 function zulutodate(s) {
-673     return new Date(zulutomsec(s));
-674 }
-675 
-676 // ==== Date / zulu =================================
-677 
-678 /**
-679  * Date object to zulu time string<br>
-680  * @name datetozulu
-681  * @function
-682  * @param {Date} d Date object for specified time
-683  * @param {Boolean} flagUTCTime if this is true year will be YY otherwise YYYY
-684  * @param {Boolean} flagMilli if this is true result concludes milliseconds
-685  * @return {String} GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
-686  * @since jsrsasign 7.2.0 base64x 1.1.11
-687  * @description
-688  * This function converts from Date object to GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
-689  * UTCTime string (i.e. YYMMDDHHmmSSZ).
-690  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
-691  * If year "YY" is equal or greater than 50 then it is 19YY.
-692  * If flagMilli is true its result concludes milliseconds such like
-693  * "20170520235959.42Z". 
-694  * @example
-695  * d = new Date(Date.UTC(2017,4,20,23,59,59,670));
-696  * datetozulu(d) → "20170520235959Z"
-697  * datetozulu(d, true) → "170520235959Z"
-698  * datetozulu(d, false, true) → "20170520235959.67Z"
-699  */
-700 function datetozulu(d, flagUTCTime, flagMilli) {
-701     var s;
-702     var year = d.getUTCFullYear();
-703     if (flagUTCTime) {
-704 	if (year < 1950 || 2049 < year) 
-705 	    throw "not proper year for UTCTime: " + year;
-706 	s = ("" + year).slice(-2);
-707     } else {
-708 	s = ("000" + year).slice(-4);
-709     }
-710     s += ("0" + (d.getUTCMonth() + 1)).slice(-2);
-711     s += ("0" + d.getUTCDate()).slice(-2);
-712     s += ("0" + d.getUTCHours()).slice(-2);
-713     s += ("0" + d.getUTCMinutes()).slice(-2);
-714     s += ("0" + d.getUTCSeconds()).slice(-2);
-715     if (flagMilli) {
-716 	var milli = d.getUTCMilliseconds();
-717 	if (milli !== 0) {
-718 	    milli = ("00" + milli).slice(-3);
-719 	    milli = milli.replace(/0+$/g, "");
-720 	    s += "." + milli;
-721 	}
-722     }
-723     s += "Z";
-724     return s;
-725 }
-726 
-727 // ==== URIComponent / hex ================================
-728 /**
-729  * convert a URLComponent string such like "%67%68" to a hexadecimal string.<br/>
-730  * @name uricmptohex
-731  * @function
-732  * @param {String} s URIComponent string such like "%67%68"
-733  * @return {String} hexadecimal string
-734  * @since 1.1
-735  */
-736 function uricmptohex(s) {
-737   return s.replace(/%/g, "");
-738 }
-739 
-740 /**
-741  * convert a hexadecimal string to a URLComponent string such like "%67%68".<br/>
-742  * @name hextouricmp
-743  * @function
-744  * @param {String} s hexadecimal string
-745  * @return {String} URIComponent string such like "%67%68"
-746  * @since 1.1
-747  */
-748 function hextouricmp(s) {
-749   return s.replace(/(..)/g, "%$1");
-750 }
-751 
-752 // ==== hex / ipv6 =================================
-753 
-754 /**
-755  * convert any IPv6 address to a 16 byte hexadecimal string
-756  * @function
-757  * @param s string of IPv6 address
-758  * @return {String} 16 byte hexadecimal string of IPv6 address
-759  * @description
-760  * This function converts any IPv6 address representation string
-761  * to a 16 byte hexadecimal string of address.
-762  * @example
-763  * 
-764  */
-765 function ipv6tohex(s) {
-766   var msgMalformedAddress = "malformed IPv6 address";
-767   if (! s.match(/^[0-9A-Fa-f:]+$/))
-768     throw msgMalformedAddress;
-769 
-770   // 1. downcase
-771   s = s.toLowerCase();
-772 
-773   // 2. expand ::
-774   var num_colon = s.split(':').length - 1;
-775   if (num_colon < 2) throw msgMalformedAddress;
-776   var colon_replacer = ':'.repeat(7 - num_colon + 2);
-777   s = s.replace('::', colon_replacer);
-778 
-779   // 3. fill zero
-780   var a = s.split(':');
-781   if (a.length != 8) throw msgMalformedAddress;
-782   for (var i = 0; i < 8; i++) {
-783     a[i] = ("0000" + a[i]).slice(-4);
-784   }
-785   return a.join('');
-786 }
-787 
-788 /**
-789  * convert a 16 byte hexadecimal string to RFC 5952 canonicalized IPv6 address<br/>
-790  * @name hextoipv6
-791  * @function
-792  * @param {String} s hexadecimal string of 16 byte IPv6 address
-793  * @return {String} IPv6 address string canonicalized by RFC 5952
-794  * @since jsrsasign 8.0.10 base64x 1.1.13
-795  * @description
-796  * This function converts a 16 byte hexadecimal string to 
-797  * <a href="https://tools.ietf.org/html/rfc5952">RFC 5952</a>
-798  * canonicalized IPv6 address string.
-799  * @example
-800  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
-801  * hextoip("871020010db8000000000000000000") &rarr raise exception
-802  * hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception
-803  */
-804 function hextoipv6(s) {
-805   if (! s.match(/^[0-9A-Fa-f]{32}$/))
-806     throw "malformed IPv6 address octet";
-807 
-808   // 1. downcase
-809   s = s.toLowerCase();
-810 
-811   // 2. split 4
-812   var a = s.match(/.{1,4}/g);
-813 
-814   // 3. trim leading 0
-815   for (var i = 0; i < 8; i++) {
-816     a[i] = a[i].replace(/^0+/, "");
-817     if (a[i] == '') a[i] = '0';
-818   }
-819   s = ":" + a.join(":") + ":";
-820 
-821   // 4. find shrinkables :0:0:...
-822   var aZero = s.match(/:(0:){2,}/g);
-823 
-824   // 5. no shrinkable
-825   if (aZero === null) return s.slice(1, -1);
-826 
-827   // 6. find max length :0:0:...
-828   var item = '';
-829   for (var i = 0; i < aZero.length; i++) {
-830     if (aZero[i].length > item.length) item = aZero[i];
-831   }
-832 
-833   // 7. shrink
-834   s = s.replace(item, '::');
-835   return s.slice(1, -1);
-836 }
-837 
-838 // ==== hex / ip =================================
-839 
-840 /**
-841  * convert a hexadecimal string to IP addresss<br/>
-842  * @name hextoip
-843  * @function
-844  * @param {String} s hexadecimal string of IP address
-845  * @return {String} IP address string
-846  * @since jsrsasign 8.0.10 base64x 1.1.13
-847  * @description
-848  * This function converts a hexadecimal string of IPv4 or 
-849  * IPv6 address to IPv4 or IPv6 address string.
-850  * If byte length is not 4 nor 16, this returns a
-851  * hexadecimal string without conversion.
-852  * @see {@link hextoipv6}
-853  * @example
-854  * hextoip("c0a80101") &rarr "192.168.1.1"
-855  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
-856  * hextoip("c0a801010203") &rarr "c0a801010203" // 6 bytes
-857  * hextoip("zzz")) &rarr raise exception because of not hexadecimal
-858  */
-859 function hextoip(s) {
-860   var malformedMsg = "malformed hex value";
-861   if (! s.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))
-862     throw malformedMsg;
-863   if (s.length == 8) { // ipv4
-864     var ip;
-865     try {
-866       ip = parseInt(s.substr(0, 2), 16) + "." +
-867            parseInt(s.substr(2, 2), 16) + "." +
-868            parseInt(s.substr(4, 2), 16) + "." +
-869            parseInt(s.substr(6, 2), 16);
-870       return ip;
-871     } catch (ex) {
-872       throw malformedMsg;
-873     }
-874   } else if (s.length == 32) {
-875     return hextoipv6(s);
-876   } else {
-877     return s;
-878   }
-879 }
-880 
-881 /**
-882  * convert IPv4/v6 addresss to a hexadecimal string<br/>
-883  * @name iptohex
-884  * @function
-885  * @param {String} s IPv4/v6 address string
-886  * @return {String} hexadecimal string of IP address
-887  * @since jsrsasign 8.0.12 base64x 1.1.14
-888  * @description
-889  * This function converts IPv4 or IPv6 address string to
-890  * a hexadecimal string of IPv4 or IPv6 address.
-891  * @example
-892  * iptohex("192.168.1.1") &rarr "c0a80101"
-893  * iptohex("2001:db8::4") &rarr "871020010db8000000000000000000000004"
-894  * iptohex("zzz")) &rarr raise exception
-895  */
-896 function iptohex(s) {
-897   var malformedMsg = "malformed IP address";
-898   s = s.toLowerCase(s);
-899 
-900   if (s.match(/^[0-9.]+$/)) {
-901     var a = s.split(".");
-902     if (a.length !== 4) throw malformedMsg;
-903     var hex = "";
-904     try {
-905       for (var i = 0; i < 4; i++) {
-906         var d = parseInt(a[i]);
-907         hex += ("0" + d.toString(16)).slice(-2);
-908       }
-909       return hex;
-910     } catch(ex) {
-911       throw malformedMsg;
-912     }
-913   } else if (s.match(/^[0-9a-f:]+$/) && s.indexOf(":") !== -1) {
-914     return ipv6tohex(s);
-915   } else {
-916     throw malformedMsg;
-917   }
-918 }
-919 
-920 // ==== ucs2hex / utf8 ==============================
-921 
-922 /**
-923  * convert UCS-2 hexadecimal stirng to UTF-8 string<br/>
-924  * @name ucs2hextoutf8
-925  * @function
-926  * @param {String} s hexadecimal string of UCS-2 string (ex. "0066")
-927  * @return {String} UTF-8 string
-928  * @since jsrsasign 10.1.13 base64x 1.1.20
-929  * @description
-930  * This function converts hexadecimal value of UCS-2 string to 
-931  * UTF-8 string.
-932  * @example
-933  * ucs2hextoutf8("006600fc0072") &rarr "für"
-934  */
-935 /*
-936 See: http://nomenclator.la.coocan.jp/unicode/ucs_utf.htm
-937 UCS-2 to UTF-8
-938 UCS-2 code point | UCS-2 bytes       | UTF-8 bytes
-939 U+0000 .. U+007F | 00000000-0xxxxxxx | 0xxxxxxx (1 byte)
-940 U+0080 .. U+07FF | 00000xxx-xxyyyyyy | 110xxxxx 10yyyyyy (2 byte)
-941 U+0800 .. U+FFFF | xxxxyyyy-yyzzzzzz | 1110xxxx 10yyyyyy 10zzzzzz (3 byte)
-942  */
-943 function ucs2hextoutf8(s) {
-944     function _conv(s) {
-945 	var i1 = parseInt(s.substr(0, 2), 16);
-946 	var i2 = parseInt(s.substr(2), 16);
-947 	if (i1 == 0 & i2 < 0x80) { // 1 byte
-948 	    return String.fromCharCode(i2);
-949 	}
-950 	if (i1 < 8) { // 2 bytes
-951 	    var u1 = 0xc0 | ((i1 & 0x07) << 3) | ((i2 & 0xc0) >> 6);
-952 	    var u2 = 0x80 | (i2 & 0x3f);
-953 	    return hextoutf8(u1.toString(16) + u2.toString(16));
-954 	}
-955 	// 3 bytes
-956 	var u1 = 0xe0 | ((i1 & 0xf0) >> 4);
-957 	var u2 = 0x80 | ((i1 & 0x0f) << 2) | ((i2 & 0xc0) >> 6);
-958 	var u3 = 0x80 | (i2 & 0x3f);
-959 	return hextoutf8(u1.toString(16) + u2.toString(16) + u3.toString(16));
-960     }
-961     var a = s.match(/.{4}/g);
-962     var a2 = a.map(_conv);
-963     return a2.join("");
-964 }
-965 
-966 // ==== URIComponent ================================
-967 /**
-968  * convert UTFa hexadecimal string to a URLComponent string such like "%67%68".<br/>
-969  * Note that these "<code>0-9A-Za-z!'()*-._~</code>" characters will not
-970  * converted to "%xx" format by builtin 'encodeURIComponent()' function.
-971  * However this 'encodeURIComponentAll()' function will convert 
-972  * all of characters into "%xx" format.
-973  * @name encodeURIComponentAll
-974  * @function
-975  * @param {String} s hexadecimal string
-976  * @return {String} URIComponent string such like "%67%68"
-977  * @since 1.1
-978  */
-979 function encodeURIComponentAll(u8) {
-980   var s = encodeURIComponent(u8);
-981   var s2 = "";
-982   for (var i = 0; i < s.length; i++) {
-983     if (s[i] == "%") {
-984       s2 = s2 + s.substr(i, 3);
-985       i = i + 2;
-986     } else {
-987       s2 = s2 + "%" + stohex(s[i]);
-988     }
-989   }
-990   return s2;
-991 }
-992 
-993 // ==== new lines ================================
-994 /**
-995  * convert all DOS new line("\r\n") to UNIX new line("\n") in 
-996  * a String "s".
-997  * @name newline_toUnix
-998  * @function
-999  * @param {String} s string 
-1000  * @return {String} converted string
-1001  */
-1002 function newline_toUnix(s) {
-1003     s = s.replace(/\r\n/mg, "\n");
-1004     return s;
-1005 }
-1006 
-1007 /**
-1008  * convert all UNIX new line("\r\n") to DOS new line("\n") in 
-1009  * a String "s".
-1010  * @name newline_toDos
-1011  * @function
-1012  * @param {String} s string 
-1013  * @return {String} converted string
-1014  */
-1015 function newline_toDos(s) {
-1016     s = s.replace(/\r\n/mg, "\n");
-1017     s = s.replace(/\n/mg, "\r\n");
-1018     return s;
-1019 }
-1020 
-1021 // ==== string type checker ===================
-1022 
-1023 /**
-1024  * check whether a string is an integer string or not<br/>
-1025  * @name isInteger
-1026  * @memberOf KJUR.lang.String
-1027  * @function
-1028  * @static
-1029  * @param {String} s input string
-1030  * @return {Boolean} true if a string "s" is an integer string otherwise false
-1031  * @since base64x 1.1.7 jsrsasign 5.0.13
-1032  * @example
-1033  * KJUR.lang.String.isInteger("12345") → true
-1034  * KJUR.lang.String.isInteger("123ab") → false
-1035  */
-1036 KJUR.lang.String.isInteger = function(s) {
-1037     if (s.match(/^[0-9]+$/)) {
-1038 	return true;
-1039     } else if (s.match(/^-[0-9]+$/)) {
-1040 	return true;
-1041     } else {
-1042 	return false;
-1043     }
-1044 };
-1045 
-1046 /**
-1047  * check whether a string is an hexadecimal string or not (DEPRECATED)<br/>
-1048  * @name isHex
-1049  * @memberOf KJUR.lang.String
-1050  * @function
-1051  * @static
-1052  * @param {String} s input string
-1053  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
-1054  * @since base64x 1.1.7 jsrsasign 5.0.13
-1055  * @deprecated from 10.0.6. please use {@link ishex}
-1056  * @see ishex
-1057  * @example
-1058  * KJUR.lang.String.isHex("1234") → true
-1059  * KJUR.lang.String.isHex("12ab") → true
-1060  * KJUR.lang.String.isHex("12AB") → true
-1061  * KJUR.lang.String.isHex("12ZY") → false
-1062  * KJUR.lang.String.isHex("121") → false -- odd length
-1063  */
-1064 KJUR.lang.String.isHex = function(s) {
-1065     return ishex(s);
-1066 };
-1067 
-1068 /**
-1069  * check whether a string is an hexadecimal string or not<br/>
-1070  * @name ishex
-1071  * @function
-1072  * @static
-1073  * @param {String} s input string
-1074  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
-1075  * @since base64x 1.1.7 jsrsasign 5.0.13
-1076  * @example
-1077  * ishex("1234") → true
-1078  * ishex("12ab") → true
-1079  * ishex("12AB") → true
-1080  * ishex("12ZY") → false
-1081  * ishex("121") → false -- odd length
-1082  */
-1083 function ishex(s) {
-1084     if (s.length % 2 == 0 &&
-1085 	(s.match(/^[0-9a-f]+$/) || s.match(/^[0-9A-F]+$/))) {
-1086 	return true;
-1087     } else {
-1088 	return false;
-1089     }
-1090 };
-1091 
-1092 /**
-1093  * check whether a string is a base64 encoded string or not<br/>
-1094  * Input string can conclude new lines or space characters.
-1095  * @name isBase64
-1096  * @memberOf KJUR.lang.String
-1097  * @function
-1098  * @static
-1099  * @param {String} s input string
-1100  * @return {Boolean} true if a string "s" is a base64 encoded string otherwise false
-1101  * @since base64x 1.1.7 jsrsasign 5.0.13
-1102  * @example
-1103  * KJUR.lang.String.isBase64("YWE=") → true
-1104  * KJUR.lang.String.isBase64("YW_=") → false
-1105  * KJUR.lang.String.isBase64("YWE") → false -- length shall be multiples of 4
-1106  */
-1107 KJUR.lang.String.isBase64 = function(s) {
-1108     s = s.replace(/\s+/g, "");
-1109     if (s.match(/^[0-9A-Za-z+\/]+={0,3}$/) && s.length % 4 == 0) {
-1110 	return true;
-1111     } else {
-1112 	return false;
-1113     }
-1114 };
-1115 
-1116 /**
-1117  * check whether a string is a base64url encoded string or not<br/>
-1118  * Input string can conclude new lines or space characters.
-1119  * @name isBase64URL
-1120  * @memberOf KJUR.lang.String
-1121  * @function
-1122  * @static
-1123  * @param {String} s input string
-1124  * @return {Boolean} true if a string "s" is a base64url encoded string otherwise false
-1125  * @since base64x 1.1.7 jsrsasign 5.0.13
-1126  * @example
-1127  * KJUR.lang.String.isBase64URL("YWE") → true
-1128  * KJUR.lang.String.isBase64URL("YW-") → true
-1129  * KJUR.lang.String.isBase64URL("YW+") → false
-1130  */
-1131 KJUR.lang.String.isBase64URL = function(s) {
-1132     if (s.match(/[+/=]/)) return false;
-1133     s = b64utob64(s);
-1134     return KJUR.lang.String.isBase64(s);
-1135 };
-1136 
-1137 /**
-1138  * check whether a string is a string of integer array or not<br/>
-1139  * Input string can conclude new lines or space characters.
-1140  * @name isIntegerArray
-1141  * @memberOf KJUR.lang.String
-1142  * @function
-1143  * @static
-1144  * @param {String} s input string
-1145  * @return {Boolean} true if a string "s" is a string of integer array otherwise false
-1146  * @since base64x 1.1.7 jsrsasign 5.0.13
-1147  * @example
-1148  * KJUR.lang.String.isIntegerArray("[1,2,3]") → true
-1149  * KJUR.lang.String.isIntegerArray("  [1, 2, 3  ] ") → true
-1150  * KJUR.lang.String.isIntegerArray("[a,2]") → false
-1151  */
-1152 KJUR.lang.String.isIntegerArray = function(s) {
-1153     s = s.replace(/\s+/g, "");
-1154     if (s.match(/^\[[0-9,]+\]$/)) {
-1155 	return true;
-1156     } else {
-1157 	return false;
-1158     }
-1159 };
-1160 
-1161 /**
-1162  * check whether a string consists of PrintableString characters<br/>
-1163  * @name isPrintable
-1164  * @memberOf KJUR.lang.String
-1165  * @function
-1166  * @static
-1167  * @param {String} s input string
-1168  * @return {Boolean} true if a string "s" consists of PrintableString characters
-1169  * @since jsrsasign 9.0.0 base64x 1.1.16
-1170  * A PrintableString consists of following characters
-1171  * <pre>
-1172  * 0-9A-Za-z '()+,-./:=?
-1173  * </pre>
-1174  * This method returns false when other characters than above.
-1175  * Otherwise it returns true.
-1176  * @example
-1177  * KJUR.lang.String.isPrintable("abc") → true
-1178  * KJUR.lang.String.isPrintable("abc@") → false
-1179  * KJUR.lang.String.isPrintable("あいう") → false
-1180  */
-1181 KJUR.lang.String.isPrintable = function(s) {
-1182     if (s.match(/^[0-9A-Za-z '()+,-./:=?]*$/) !== null) return true;
-1183     return false;
-1184 };
-1185 
-1186 /**
-1187  * check whether a string consists of IAString characters<br/>
-1188  * @name isIA5
-1189  * @memberOf KJUR.lang.String
-1190  * @function
-1191  * @static
-1192  * @param {String} s input string
-1193  * @return {Boolean} true if a string "s" consists of IA5String characters
-1194  * @since jsrsasign 9.0.0 base64x 1.1.16
-1195  * A IA5String consists of following characters
-1196  * <pre>
-1197  * %x00-21/%x23-7F (i.e. ASCII characters excludes double quote(%x22)
-1198  * </pre>
-1199  * This method returns false when other characters than above.
-1200  * Otherwise it returns true.
-1201  * @example
-1202  * KJUR.lang.String.isIA5("abc") → true
-1203  * KJUR.lang.String.isIA5('"abc"') → false
-1204  * KJUR.lang.String.isIA5("あいう") → false
-1205  */
-1206 KJUR.lang.String.isIA5 = function(s) {
-1207     if (s.match(/^[\x20-\x21\x23-\x7f]*$/) !== null) return true;
-1208     return false;
-1209 };
-1210 
-1211 /**
-1212  * check whether a string is RFC 822 mail address<br/>
-1213  * @name isMail
-1214  * @memberOf KJUR.lang.String
-1215  * @function
-1216  * @static
-1217  * @param {String} s input string
-1218  * @return {Boolean} true if a string "s" RFC 822 mail address
-1219  * @since jsrsasign 9.0.0 base64x 1.1.16
-1220  * This static method will check string s is RFC 822 compliant mail address.
-1221  * @example
-1222  * KJUR.lang.String.isMail("abc") → false
-1223  * KJUR.lang.String.isMail("abc@example") → false
-1224  * KJUR.lang.String.isMail("abc@example.com") → true
-1225  */
-1226 KJUR.lang.String.isMail = function(s) {
-1227     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;
-1228     return false;
-1229 };
-1230 
-1231 // ==== others ================================
-1232 
-1233 /**
-1234  * canonicalize hexadecimal string of positive integer<br/>
-1235  * @name hextoposhex
-1236  * @function
-1237  * @param {String} s hexadecimal string 
-1238  * @return {String} canonicalized hexadecimal string of positive integer
-1239  * @since base64x 1.1.10 jsrsasign 7.1.4
-1240  * @description
-1241  * This method canonicalize a hexadecimal string of positive integer
-1242  * for two's complement representation.
-1243  * Canonicalized hexadecimal string of positive integer will be:
-1244  * <ul>
-1245  * <li>Its length is always even.</li>
-1246  * <li>If odd length it will be padded with leading zero.<li>
-1247  * <li>If it is even length and its first character is "8" or greater,
-1248  * it will be padded with "00" to make it positive integer.</li>
-1249  * </ul>
-1250  * @example
-1251  * hextoposhex("abcd") → "00abcd"
-1252  * hextoposhex("1234") → "1234"
-1253  * hextoposhex("12345") → "012345"
-1254  */
-1255 function hextoposhex(s) {
-1256     if (s.length % 2 == 1) return "0" + s;
-1257     if (s.substr(0, 1) > "7") return "00" + s;
-1258     return s;
-1259 }
-1260 
-1261 /**
-1262  * convert string of integer array to hexadecimal string.<br/>
-1263  * @name intarystrtohex
-1264  * @function
-1265  * @param {String} s string of integer array
-1266  * @return {String} hexadecimal string
-1267  * @since base64x 1.1.6 jsrsasign 5.0.2
-1268  * @throws "malformed integer array string: *" for wrong input
-1269  * @description
-1270  * This function converts a string of JavaScript integer array to
-1271  * a hexadecimal string. Each integer value shall be in a range 
-1272  * from 0 to 255 otherwise it raise exception. Input string can
-1273  * have extra space or newline string so that they will be ignored.
-1274  * 
-1275  * @example
-1276  * intarystrtohex(" [123, 34, 101, 34, 58] ")
-1277  * → 7b2265223a (i.e. '{"e":' as string)
-1278  */
-1279 function intarystrtohex(s) {
-1280   s = s.replace(/^\s*\[\s*/, '');
-1281   s = s.replace(/\s*\]\s*$/, '');
-1282   s = s.replace(/\s*/g, '');
-1283   try {
-1284     var hex = s.split(/,/).map(function(element, index, array) {
-1285       var i = parseInt(element);
-1286       if (i < 0 || 255 < i) throw "integer not in range 0-255";
-1287       var hI = ("00" + i.toString(16)).slice(-2);
-1288       return hI;
-1289     }).join('');
-1290     return hex;
-1291   } catch(ex) {
-1292     throw "malformed integer array string: " + ex;
-1293   }
-1294 }
-1295 
-1296 /**
-1297  * find index of string where two string differs
-1298  * @name strdiffidx
-1299  * @function
-1300  * @param {String} s1 string to compare
-1301  * @param {String} s2 string to compare
-1302  * @return {Number} string index of where character differs. Return -1 if same.
-1303  * @since jsrsasign 4.9.0 base64x 1.1.5
-1304  * @example
-1305  * strdiffidx("abcdefg", "abcd4fg") -> 4
-1306  * strdiffidx("abcdefg", "abcdefg") -> -1
-1307  * strdiffidx("abcdefg", "abcdef") -> 6
-1308  * strdiffidx("abcdefgh", "abcdef") -> 6
-1309  */
-1310 var strdiffidx = function(s1, s2) {
-1311     var n = s1.length;
-1312     if (s1.length > s2.length) n = s2.length;
-1313     for (var i = 0; i < n; i++) {
-1314 	if (s1.charCodeAt(i) != s2.charCodeAt(i)) return i;
-1315     }
-1316     if (s1.length != s2.length) return n;
-1317     return -1; // same
-1318 };
-1319 
-1320 // ==== hex / oid =================================
-1321 
-1322 /**
-1323  * get hexadecimal value of object identifier from dot noted oid value
-1324  * @name oidtohex
-1325  * @function
-1326  * @param {String} oidString dot noted string of object identifier
-1327  * @return {String} hexadecimal value of object identifier
-1328  * @since jsrsasign 10.1.0 base64x 1.1.18
-1329  * @see hextooid
-1330  * @see ASN1HEX.hextooidstr
-1331  * @see KJUR.asn1.ASN1Util.oidIntToHex
-1332  * @description
-1333  * This static method converts from object identifier value string.
-1334  * to hexadecimal string representation of it.
-1335  * {@link hextooid} is a reverse function of this.
-1336  * @example
-1337  * oidtohex("2.5.4.6") → "550406"
-1338  */
-1339 function oidtohex(oidString) {
-1340     var itox = function(i) {
-1341         var h = i.toString(16);
-1342         if (h.length == 1) h = '0' + h;
-1343         return h;
-1344     };
-1345 
-1346     var roidtox = function(roid) {
-1347         var h = '';
-1348         var bi = parseInt(roid, 10);
-1349         var b = bi.toString(2);
-1350 
-1351         var padLen = 7 - b.length % 7;
-1352         if (padLen == 7) padLen = 0;
-1353         var bPad = '';
-1354         for (var i = 0; i < padLen; i++) bPad += '0';
-1355         b = bPad + b;
-1356         for (var i = 0; i < b.length - 1; i += 7) {
-1357             var b8 = b.substr(i, 7);
-1358             if (i != b.length - 7) b8 = '1' + b8;
-1359             h += itox(parseInt(b8, 2));
-1360         }
-1361         return h;
-1362     };
-1363     
-1364     try {
-1365 	if (! oidString.match(/^[0-9.]+$/)) return null;
-1366     
-1367 	var h = '';
-1368 	var a = oidString.split('.');
-1369 	var i0 = parseInt(a[0], 10) * 40 + parseInt(a[1], 10);
-1370 	h += itox(i0);
-1371 	a.splice(0, 2);
-1372 	for (var i = 0; i < a.length; i++) {
-1373             h += roidtox(a[i]);
-1374 	}
-1375 	return h;
-1376     } catch(ex) {
-1377 	return null;
-1378     }
-1379 };
-1380 
-1381 /**
-1382  * get oid string from hexadecimal value of object identifier<br/>
-1383  * @name hextooid
-1384  * @function
-1385  * @param {String} h hexadecimal value of object identifier
-1386  * @return {String} dot noted string of object identifier (ex. "1.2.3.4")
-1387  * @since jsrsasign 10.1.0 base64x 1.1.18
-1388  * @see oidtohex
-1389  * @see ASN1HEX.hextooidstr
-1390  * @see KJUR.asn1.ASN1Util.oidIntToHex
-1391  * @description
-1392  * This static method converts from hexadecimal object identifier value 
-1393  * to dot noted OID value (ex. "1.2.3.4").
-1394  * {@link oidtohex} is a reverse function of this.
-1395  * @example
-1396  * hextooid("550406") → "2.5.4.6"
-1397  */
-1398 function hextooid(h) {
-1399     if (! ishex(h)) return null;
-1400     try {
-1401 	var a = [];
-1402 
-1403 	// a[0], a[1]
-1404 	var hex0 = h.substr(0, 2);
-1405 	var i0 = parseInt(hex0, 16);
-1406 	a[0] = new String(Math.floor(i0 / 40));
-1407 	a[1] = new String(i0 % 40);
-1408 
-1409 	// a[2]..a[n]
-1410 	var hex1 = h.substr(2);
-1411 	var b = [];
-1412 	for (var i = 0; i < hex1.length / 2; i++) {
-1413 	    b.push(parseInt(hex1.substr(i * 2, 2), 16));
-1414 	}
-1415 	var c = [];
-1416 	var cbin = "";
-1417 	for (var i = 0; i < b.length; i++) {
-1418             if (b[i] & 0x80) {
-1419 		cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7);
-1420             } else {
-1421 		cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7);
-1422 		c.push(new String(parseInt(cbin, 2)));
-1423 		cbin = "";
-1424             }
-1425 	}
-1426 
-1427 	var s = a.join(".");
-1428 	if (c.length > 0) s = s + "." + c.join(".");
-1429 	return s;
-1430     } catch(ex) {
-1431 	return null;
-1432     }
-1433 };
-1434 
-1435 /**
-1436  * string padding<br/>
-1437  * @name strpad
-1438  * @function
-1439  * @param {String} s input string
-1440  * @param {Number} len output string length
-1441  * @param {String} padchar padding character (default is "0")
-1442  * @return {String} padded string
-1443  * @since jsrsasign 10.1.0 base64x 1.1.18
-1444  * @example
-1445  * strpad("1234", 10, "0") → "0000001234"
-1446  * strpad("1234", 10, " ") → "      1234"
-1447  * strpad("1234", 10)      → "0000001234"
-1448  */
-1449 var strpad = function(s, len, padchar) {
-1450     if (padchar == undefined) padchar = "0";
-1451     if (s.length >= len) return s;
-1452     return new Array(len - s.length + 1).join(padchar) + s;
-1453 };
-1454 
-1455 // ==== bitstr hex / int =================================
-1456 
-1457 /**
-1458  * convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value<br/>
-1459  * @name bitstrtoint
-1460  * @function
-1461  * @param {String} h hexadecimal string of ASN.1 BitString value with unused bit
-1462  * @return {Number} positive integer value of the BitString
-1463  * @since jsrsasign 10.1.3 base64x 1.1.19
-1464  * @see inttobitstr
-1465  * @see KJUR.asn1.DERBitString
-1466  * @see ASN1HEX.getInt
-1467  * 
-1468  * @description
-1469  * This function converts from hexadecimal string of ASN.1 BitString
-1470  * value with unused bit to its integer value.
+567     for (var i = 0; i < buffer.byteLength; i++) {
+568 	hex += ("00" + view.getUint8(i).toString(16)).slice(-2);
+569     }
+570 
+571     return hex;
+572 }
+573 
+574 // ==== zulu / int =================================
+575 /**
+576  * GeneralizedTime or UTCTime string to milliseconds from Unix origin<br>
+577  * @name zulutomsec
+578  * @function
+579  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
+580  * @return {Number} milliseconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
+581  * @since jsrsasign 7.1.3 base64x 1.1.9
+582  * @description
+583  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
+584  * UTCTime string (i.e. YYMMDDHHmmSSZ) to milliseconds from Unix origin time
+585  * (i.e. Jan 1 1970 0:00:00 UTC). 
+586  * Argument string may have fraction of seconds and
+587  * its length is one or more digits such as "20170410235959.1234567Z".
+588  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
+589  * If year "YY" is equal or greater than 50 then it is 19YY.
+590  * @example
+591  * zulutomsec(  "071231235959Z")       → 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
+592  * zulutomsec(  "071231235959.1Z")     → 1199145599100 #Mon, 31 Dec 2007 23:59:59 GMT
+593  * zulutomsec(  "071231235959.12345Z") → 1199145599123 #Mon, 31 Dec 2007 23:59:59 GMT
+594  * zulutomsec("20071231235959Z")       → 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
+595  * zulutomsec(  "931231235959Z")       → -410227201000 #Mon, 31 Dec 1956 23:59:59 GMT
+596  */
+597 function zulutomsec(s) {
+598     var year, month, day, hour, min, sec, msec, d;
+599     var sYear, sFrac, sMsec, matchResult;
+600 
+601     matchResult = s.match(/^(\d{2}|\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/);
+602 
+603     if (matchResult) {
+604         sYear = matchResult[1];
+605 	year = parseInt(sYear);
+606         if (sYear.length === 2) {
+607 	    if (50 <= year && year < 100) {
+608 		year = 1900 + year;
+609 	    } else if (0 <= year && year < 50) {
+610 		year = 2000 + year;
+611 	    }
+612 	}
+613 	month = parseInt(matchResult[2]) - 1;
+614 	day = parseInt(matchResult[3]);
+615 	hour = parseInt(matchResult[4]);
+616 	min = parseInt(matchResult[5]);
+617 	sec = parseInt(matchResult[6]);
+618 	msec = 0;
+619 
+620 	sFrac = matchResult[7];
+621 	if (sFrac !== "") {
+622 	    sMsec = (sFrac.substr(1) + "00").substr(0, 3); // .12 -> 012
+623 	    msec = parseInt(sMsec);
+624 	}
+625 	return Date.UTC(year, month, day, hour, min, sec, msec);
+626     }
+627     throw "unsupported zulu format: " + s;
+628 }
+629 
+630 /**
+631  * GeneralizedTime or UTCTime string to seconds from Unix origin<br>
+632  * @name zulutosec
+633  * @function
+634  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
+635  * @return {Number} seconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
+636  * @since jsrsasign 7.1.3 base64x 1.1.9
+637  * @description
+638  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
+639  * UTCTime string (i.e. YYMMDDHHmmSSZ) to seconds from Unix origin time
+640  * (i.e. Jan 1 1970 0:00:00 UTC). Argument string may have fraction of seconds 
+641  * however result value will be omitted.
+642  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
+643  * If year "YY" is equal or greater than 50 then it is 19YY.
+644  * @example
+645  * zulutosec(  "071231235959Z")       → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
+646  * zulutosec(  "071231235959.1Z")     → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
+647  * zulutosec("20071231235959Z")       → 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
+648  */
+649 function zulutosec(s) {
+650     var msec = zulutomsec(s);
+651     return ~~(msec / 1000);
+652 }
+653 
+654 // ==== zulu / Date =================================
+655 
+656 /**
+657  * GeneralizedTime or UTCTime string to Date object<br>
+658  * @name zulutodate
+659  * @function
+660  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
+661  * @return {Date} Date object for specified time
+662  * @since jsrsasign 7.1.3 base64x 1.1.9
+663  * @description
+664  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
+665  * UTCTime string (i.e. YYMMDDHHmmSSZ) to Date object.
+666  * Argument string may have fraction of seconds and
+667  * its length is one or more digits such as "20170410235959.1234567Z".
+668  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
+669  * If year "YY" is equal or greater than 50 then it is 19YY.
+670  * @example
+671  * zulutodate(  "071231235959Z").toUTCString()   → "Mon, 31 Dec 2007 23:59:59 GMT"
+672  * zulutodate(  "071231235959.1Z").toUTCString() → "Mon, 31 Dec 2007 23:59:59 GMT"
+673  * zulutodate("20071231235959Z").toUTCString()   → "Mon, 31 Dec 2007 23:59:59 GMT"
+674  * zulutodate(  "071231235959.34").getMilliseconds() → 340
+675  */
+676 function zulutodate(s) {
+677     return new Date(zulutomsec(s));
+678 }
+679 
+680 // ==== Date / zulu =================================
+681 
+682 /**
+683  * Date object to zulu time string<br>
+684  * @name datetozulu
+685  * @function
+686  * @param {Date} d Date object for specified time
+687  * @param {Boolean} flagUTCTime if this is true year will be YY otherwise YYYY
+688  * @param {Boolean} flagMilli if this is true result concludes milliseconds
+689  * @return {String} GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
+690  * @since jsrsasign 7.2.0 base64x 1.1.11
+691  * @description
+692  * This function converts from Date object to GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
+693  * UTCTime string (i.e. YYMMDDHHmmSSZ).
+694  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
+695  * If year "YY" is equal or greater than 50 then it is 19YY.
+696  * If flagMilli is true its result concludes milliseconds such like
+697  * "20170520235959.42Z". 
+698  * @example
+699  * d = new Date(Date.UTC(2017,4,20,23,59,59,670));
+700  * datetozulu(d) → "20170520235959Z"
+701  * datetozulu(d, true) → "170520235959Z"
+702  * datetozulu(d, false, true) → "20170520235959.67Z"
+703  */
+704 function datetozulu(d, flagUTCTime, flagMilli) {
+705     var s;
+706     var year = d.getUTCFullYear();
+707     if (flagUTCTime) {
+708 	if (year < 1950 || 2049 < year) 
+709 	    throw "not proper year for UTCTime: " + year;
+710 	s = ("" + year).slice(-2);
+711     } else {
+712 	s = ("000" + year).slice(-4);
+713     }
+714     s += ("0" + (d.getUTCMonth() + 1)).slice(-2);
+715     s += ("0" + d.getUTCDate()).slice(-2);
+716     s += ("0" + d.getUTCHours()).slice(-2);
+717     s += ("0" + d.getUTCMinutes()).slice(-2);
+718     s += ("0" + d.getUTCSeconds()).slice(-2);
+719     if (flagMilli) {
+720 	var milli = d.getUTCMilliseconds();
+721 	if (milli !== 0) {
+722 	    milli = ("00" + milli).slice(-3);
+723 	    milli = milli.replace(/0+$/g, "");
+724 	    s += "." + milli;
+725 	}
+726     }
+727     s += "Z";
+728     return s;
+729 }
+730 
+731 // ==== URIComponent / hex ================================
+732 /**
+733  * convert a URLComponent string such like "%67%68" to a hexadecimal string.<br/>
+734  * @name uricmptohex
+735  * @function
+736  * @param {String} s URIComponent string such like "%67%68"
+737  * @return {String} hexadecimal string
+738  * @since 1.1
+739  */
+740 function uricmptohex(s) {
+741   return s.replace(/%/g, "");
+742 }
+743 
+744 /**
+745  * convert a hexadecimal string to a URLComponent string such like "%67%68".<br/>
+746  * @name hextouricmp
+747  * @function
+748  * @param {String} s hexadecimal string
+749  * @return {String} URIComponent string such like "%67%68"
+750  * @since 1.1
+751  */
+752 function hextouricmp(s) {
+753   return s.replace(/(..)/g, "%$1");
+754 }
+755 
+756 // ==== hex / ipv6 =================================
+757 
+758 /**
+759  * convert any IPv6 address to a 16 byte hexadecimal string
+760  * @function
+761  * @param s string of IPv6 address
+762  * @return {String} 16 byte hexadecimal string of IPv6 address
+763  * @description
+764  * This function converts any IPv6 address representation string
+765  * to a 16 byte hexadecimal string of address.
+766  * @example
+767  * 
+768  */
+769 function ipv6tohex(s) {
+770   var msgMalformedAddress = "malformed IPv6 address";
+771   if (! s.match(/^[0-9A-Fa-f:]+$/))
+772     throw msgMalformedAddress;
+773 
+774   // 1. downcase
+775   s = s.toLowerCase();
+776 
+777   // 2. expand ::
+778   var num_colon = s.split(':').length - 1;
+779   if (num_colon < 2) throw msgMalformedAddress;
+780   var colon_replacer = ':'.repeat(7 - num_colon + 2);
+781   s = s.replace('::', colon_replacer);
+782 
+783   // 3. fill zero
+784   var a = s.split(':');
+785   if (a.length != 8) throw msgMalformedAddress;
+786   for (var i = 0; i < 8; i++) {
+787     a[i] = ("0000" + a[i]).slice(-4);
+788   }
+789   return a.join('');
+790 }
+791 
+792 /**
+793  * convert a 16 byte hexadecimal string to RFC 5952 canonicalized IPv6 address<br/>
+794  * @name hextoipv6
+795  * @function
+796  * @param {String} s hexadecimal string of 16 byte IPv6 address
+797  * @return {String} IPv6 address string canonicalized by RFC 5952
+798  * @since jsrsasign 8.0.10 base64x 1.1.13
+799  * @description
+800  * This function converts a 16 byte hexadecimal string to 
+801  * <a href="https://tools.ietf.org/html/rfc5952">RFC 5952</a>
+802  * canonicalized IPv6 address string.
+803  * @example
+804  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
+805  * hextoip("871020010db8000000000000000000") &rarr raise exception
+806  * hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception
+807  */
+808 function hextoipv6(s) {
+809   if (! s.match(/^[0-9A-Fa-f]{32}$/))
+810     throw "malformed IPv6 address octet";
+811 
+812   // 1. downcase
+813   s = s.toLowerCase();
+814 
+815   // 2. split 4
+816   var a = s.match(/.{1,4}/g);
+817 
+818   // 3. trim leading 0
+819   for (var i = 0; i < 8; i++) {
+820     a[i] = a[i].replace(/^0+/, "");
+821     if (a[i] == '') a[i] = '0';
+822   }
+823   s = ":" + a.join(":") + ":";
+824 
+825   // 4. find shrinkables :0:0:...
+826   var aZero = s.match(/:(0:){2,}/g);
+827 
+828   // 5. no shrinkable
+829   if (aZero === null) return s.slice(1, -1);
+830 
+831   // 6. find max length :0:0:...
+832   var item = '';
+833   for (var i = 0; i < aZero.length; i++) {
+834     if (aZero[i].length > item.length) item = aZero[i];
+835   }
+836 
+837   // 7. shrink
+838   s = s.replace(item, '::');
+839   return s.slice(1, -1);
+840 }
+841 
+842 // ==== hex / ip =================================
+843 
+844 /**
+845  * convert a hexadecimal string to IP addresss<br/>
+846  * @name hextoip
+847  * @function
+848  * @param {String} s hexadecimal string of IP address
+849  * @return {String} IP address string
+850  * @since jsrsasign 8.0.10 base64x 1.1.13
+851  * @description
+852  * This function converts a hexadecimal string of IPv4 or 
+853  * IPv6 address to IPv4 or IPv6 address string.
+854  * If byte length is not 4 nor 16, this returns a
+855  * hexadecimal string without conversion.
+856  * @see {@link hextoipv6}
+857  * @example
+858  * hextoip("c0a80101") &rarr "192.168.1.1"
+859  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
+860  * hextoip("c0a801010203") &rarr "c0a801010203" // 6 bytes
+861  * hextoip("zzz")) &rarr raise exception because of not hexadecimal
+862  */
+863 function hextoip(s) {
+864   var malformedMsg = "malformed hex value";
+865   if (! s.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))
+866     throw malformedMsg;
+867   if (s.length == 8) { // ipv4
+868     var ip;
+869     try {
+870       ip = parseInt(s.substr(0, 2), 16) + "." +
+871            parseInt(s.substr(2, 2), 16) + "." +
+872            parseInt(s.substr(4, 2), 16) + "." +
+873            parseInt(s.substr(6, 2), 16);
+874       return ip;
+875     } catch (ex) {
+876       throw malformedMsg;
+877     }
+878   } else if (s.length == 32) {
+879     return hextoipv6(s);
+880   } else {
+881     return s;
+882   }
+883 }
+884 
+885 /**
+886  * convert IPv4/v6 addresss to a hexadecimal string<br/>
+887  * @name iptohex
+888  * @function
+889  * @param {String} s IPv4/v6 address string
+890  * @return {String} hexadecimal string of IP address
+891  * @since jsrsasign 8.0.12 base64x 1.1.14
+892  * @description
+893  * This function converts IPv4 or IPv6 address string to
+894  * a hexadecimal string of IPv4 or IPv6 address.
+895  * @example
+896  * iptohex("192.168.1.1") &rarr "c0a80101"
+897  * iptohex("2001:db8::4") &rarr "871020010db8000000000000000000000004"
+898  * iptohex("zzz")) &rarr raise exception
+899  */
+900 function iptohex(s) {
+901   var malformedMsg = "malformed IP address";
+902   s = s.toLowerCase(s);
+903 
+904   if (s.match(/^[0-9.]+$/)) {
+905     var a = s.split(".");
+906     if (a.length !== 4) throw malformedMsg;
+907     var hex = "";
+908     try {
+909       for (var i = 0; i < 4; i++) {
+910         var d = parseInt(a[i]);
+911         hex += ("0" + d.toString(16)).slice(-2);
+912       }
+913       return hex;
+914     } catch(ex) {
+915       throw malformedMsg;
+916     }
+917   } else if (s.match(/^[0-9a-f:]+$/) && s.indexOf(":") !== -1) {
+918     return ipv6tohex(s);
+919   } else {
+920     throw malformedMsg;
+921   }
+922 }
+923 
+924 // ==== ucs2hex / utf8 ==============================
+925 
+926 /**
+927  * convert UCS-2 hexadecimal stirng to UTF-8 string<br/>
+928  * @name ucs2hextoutf8
+929  * @function
+930  * @param {String} s hexadecimal string of UCS-2 string (ex. "0066")
+931  * @return {String} UTF-8 string
+932  * @since jsrsasign 10.1.13 base64x 1.1.20
+933  * @description
+934  * This function converts hexadecimal value of UCS-2 string to 
+935  * UTF-8 string.
+936  * @example
+937  * ucs2hextoutf8("006600fc0072") &rarr "für"
+938  */
+939 /*
+940 See: http://nomenclator.la.coocan.jp/unicode/ucs_utf.htm
+941 UCS-2 to UTF-8
+942 UCS-2 code point | UCS-2 bytes       | UTF-8 bytes
+943 U+0000 .. U+007F | 00000000-0xxxxxxx | 0xxxxxxx (1 byte)
+944 U+0080 .. U+07FF | 00000xxx-xxyyyyyy | 110xxxxx 10yyyyyy (2 byte)
+945 U+0800 .. U+FFFF | xxxxyyyy-yyzzzzzz | 1110xxxx 10yyyyyy 10zzzzzz (3 byte)
+946  */
+947 function ucs2hextoutf8(s) {
+948     function _conv(s) {
+949 	var i1 = parseInt(s.substr(0, 2), 16);
+950 	var i2 = parseInt(s.substr(2), 16);
+951 	if (i1 == 0 & i2 < 0x80) { // 1 byte
+952 	    return String.fromCharCode(i2);
+953 	}
+954 	if (i1 < 8) { // 2 bytes
+955 	    var u1 = 0xc0 | ((i1 & 0x07) << 3) | ((i2 & 0xc0) >> 6);
+956 	    var u2 = 0x80 | (i2 & 0x3f);
+957 	    return hextoutf8(u1.toString(16) + u2.toString(16));
+958 	}
+959 	// 3 bytes
+960 	var u1 = 0xe0 | ((i1 & 0xf0) >> 4);
+961 	var u2 = 0x80 | ((i1 & 0x0f) << 2) | ((i2 & 0xc0) >> 6);
+962 	var u3 = 0x80 | (i2 & 0x3f);
+963 	return hextoutf8(u1.toString(16) + u2.toString(16) + u3.toString(16));
+964     }
+965     var a = s.match(/.{4}/g);
+966     var a2 = a.map(_conv);
+967     return a2.join("");
+968 }
+969 
+970 // ==== URIComponent ================================
+971 /**
+972  * convert UTFa hexadecimal string to a URLComponent string such like "%67%68".<br/>
+973  * Note that these "<code>0-9A-Za-z!'()*-._~</code>" characters will not
+974  * converted to "%xx" format by builtin 'encodeURIComponent()' function.
+975  * However this 'encodeURIComponentAll()' function will convert 
+976  * all of characters into "%xx" format.
+977  * @name encodeURIComponentAll
+978  * @function
+979  * @param {String} s hexadecimal string
+980  * @return {String} URIComponent string such like "%67%68"
+981  * @since 1.1
+982  */
+983 function encodeURIComponentAll(u8) {
+984   var s = encodeURIComponent(u8);
+985   var s2 = "";
+986   for (var i = 0; i < s.length; i++) {
+987     if (s[i] == "%") {
+988       s2 = s2 + s.substr(i, 3);
+989       i = i + 2;
+990     } else {
+991       s2 = s2 + "%" + stohex(s[i]);
+992     }
+993   }
+994   return s2;
+995 }
+996 
+997 // ==== new lines ================================
+998 /**
+999  * convert all DOS new line("\r\n") to UNIX new line("\n") in 
+1000  * a String "s".
+1001  * @name newline_toUnix
+1002  * @function
+1003  * @param {String} s string 
+1004  * @return {String} converted string
+1005  */
+1006 function newline_toUnix(s) {
+1007     s = s.replace(/\r\n/mg, "\n");
+1008     return s;
+1009 }
+1010 
+1011 /**
+1012  * convert all UNIX new line("\r\n") to DOS new line("\n") in 
+1013  * a String "s".
+1014  * @name newline_toDos
+1015  * @function
+1016  * @param {String} s string 
+1017  * @return {String} converted string
+1018  */
+1019 function newline_toDos(s) {
+1020     s = s.replace(/\r\n/mg, "\n");
+1021     s = s.replace(/\n/mg, "\r\n");
+1022     return s;
+1023 }
+1024 
+1025 // ==== string type checker ===================
+1026 
+1027 /**
+1028  * check whether a string is an integer string or not<br/>
+1029  * @name isInteger
+1030  * @memberOf KJUR.lang.String
+1031  * @function
+1032  * @static
+1033  * @param {String} s input string
+1034  * @return {Boolean} true if a string "s" is an integer string otherwise false
+1035  * @since base64x 1.1.7 jsrsasign 5.0.13
+1036  * @example
+1037  * KJUR.lang.String.isInteger("12345") → true
+1038  * KJUR.lang.String.isInteger("123ab") → false
+1039  */
+1040 KJUR.lang.String.isInteger = function(s) {
+1041     if (s.match(/^[0-9]+$/)) {
+1042 	return true;
+1043     } else if (s.match(/^-[0-9]+$/)) {
+1044 	return true;
+1045     } else {
+1046 	return false;
+1047     }
+1048 };
+1049 
+1050 /**
+1051  * check whether a string is an hexadecimal string or not (DEPRECATED)<br/>
+1052  * @name isHex
+1053  * @memberOf KJUR.lang.String
+1054  * @function
+1055  * @static
+1056  * @param {String} s input string
+1057  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
+1058  * @since base64x 1.1.7 jsrsasign 5.0.13
+1059  * @deprecated from 10.0.6. please use {@link ishex}
+1060  * @see ishex
+1061  * @example
+1062  * KJUR.lang.String.isHex("1234") → true
+1063  * KJUR.lang.String.isHex("12ab") → true
+1064  * KJUR.lang.String.isHex("12AB") → true
+1065  * KJUR.lang.String.isHex("12ZY") → false
+1066  * KJUR.lang.String.isHex("121") → false -- odd length
+1067  */
+1068 KJUR.lang.String.isHex = function(s) {
+1069     return ishex(s);
+1070 };
+1071 
+1072 /**
+1073  * check whether a string is an hexadecimal string or not<br/>
+1074  * @name ishex
+1075  * @function
+1076  * @static
+1077  * @param {String} s input string
+1078  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
+1079  * @since base64x 1.1.7 jsrsasign 5.0.13
+1080  * @example
+1081  * ishex("1234") → true
+1082  * ishex("12ab") → true
+1083  * ishex("12AB") → true
+1084  * ishex("12ZY") → false
+1085  * ishex("121") → false -- odd length
+1086  */
+1087 function ishex(s) {
+1088     if (s.length % 2 == 0 &&
+1089 	(s.match(/^[0-9a-f]+$/) || s.match(/^[0-9A-F]+$/))) {
+1090 	return true;
+1091     } else {
+1092 	return false;
+1093     }
+1094 };
+1095 
+1096 /**
+1097  * check whether a string is a base64 encoded string or not<br/>
+1098  * Input string can conclude new lines or space characters.
+1099  * @name isBase64
+1100  * @memberOf KJUR.lang.String
+1101  * @function
+1102  * @static
+1103  * @param {String} s input string
+1104  * @return {Boolean} true if a string "s" is a base64 encoded string otherwise false
+1105  * @since base64x 1.1.7 jsrsasign 5.0.13
+1106  * @example
+1107  * KJUR.lang.String.isBase64("YWE=") → true
+1108  * KJUR.lang.String.isBase64("YW_=") → false
+1109  * KJUR.lang.String.isBase64("YWE") → false -- length shall be multiples of 4
+1110  */
+1111 KJUR.lang.String.isBase64 = function(s) {
+1112     s = s.replace(/\s+/g, "");
+1113     if (s.match(/^[0-9A-Za-z+\/]+={0,3}$/) && s.length % 4 == 0) {
+1114 	return true;
+1115     } else {
+1116 	return false;
+1117     }
+1118 };
+1119 
+1120 /**
+1121  * check whether a string is a base64url encoded string or not<br/>
+1122  * Input string can conclude new lines or space characters.
+1123  * @name isBase64URL
+1124  * @memberOf KJUR.lang.String
+1125  * @function
+1126  * @static
+1127  * @param {String} s input string
+1128  * @return {Boolean} true if a string "s" is a base64url encoded string otherwise false
+1129  * @since base64x 1.1.7 jsrsasign 5.0.13
+1130  * @example
+1131  * KJUR.lang.String.isBase64URL("YWE") → true
+1132  * KJUR.lang.String.isBase64URL("YW-") → true
+1133  * KJUR.lang.String.isBase64URL("YW+") → false
+1134  */
+1135 KJUR.lang.String.isBase64URL = function(s) {
+1136     if (s.match(/[+/=]/)) return false;
+1137     s = b64utob64(s);
+1138     return KJUR.lang.String.isBase64(s);
+1139 };
+1140 
+1141 /**
+1142  * check whether a string is a string of integer array or not<br/>
+1143  * Input string can conclude new lines or space characters.
+1144  * @name isIntegerArray
+1145  * @memberOf KJUR.lang.String
+1146  * @function
+1147  * @static
+1148  * @param {String} s input string
+1149  * @return {Boolean} true if a string "s" is a string of integer array otherwise false
+1150  * @since base64x 1.1.7 jsrsasign 5.0.13
+1151  * @example
+1152  * KJUR.lang.String.isIntegerArray("[1,2,3]") → true
+1153  * KJUR.lang.String.isIntegerArray("  [1, 2, 3  ] ") → true
+1154  * KJUR.lang.String.isIntegerArray("[a,2]") → false
+1155  */
+1156 KJUR.lang.String.isIntegerArray = function(s) {
+1157     s = s.replace(/\s+/g, "");
+1158     if (s.match(/^\[[0-9,]+\]$/)) {
+1159 	return true;
+1160     } else {
+1161 	return false;
+1162     }
+1163 };
+1164 
+1165 /**
+1166  * check whether a string consists of PrintableString characters<br/>
+1167  * @name isPrintable
+1168  * @memberOf KJUR.lang.String
+1169  * @function
+1170  * @static
+1171  * @param {String} s input string
+1172  * @return {Boolean} true if a string "s" consists of PrintableString characters
+1173  * @since jsrsasign 9.0.0 base64x 1.1.16
+1174  * A PrintableString consists of following characters
+1175  * <pre>
+1176  * 0-9A-Za-z '()+,-./:=?
+1177  * </pre>
+1178  * This method returns false when other characters than above.
+1179  * Otherwise it returns true.
+1180  * @example
+1181  * KJUR.lang.String.isPrintable("abc") → true
+1182  * KJUR.lang.String.isPrintable("abc@") → false
+1183  * KJUR.lang.String.isPrintable("あいう") → false
+1184  */
+1185 KJUR.lang.String.isPrintable = function(s) {
+1186     if (s.match(/^[0-9A-Za-z '()+,-./:=?]*$/) !== null) return true;
+1187     return false;
+1188 };
+1189 
+1190 /**
+1191  * check whether a string consists of IAString characters<br/>
+1192  * @name isIA5
+1193  * @memberOf KJUR.lang.String
+1194  * @function
+1195  * @static
+1196  * @param {String} s input string
+1197  * @return {Boolean} true if a string "s" consists of IA5String characters
+1198  * @since jsrsasign 9.0.0 base64x 1.1.16
+1199  * A IA5String consists of following characters
+1200  * <pre>
+1201  * %x00-21/%x23-7F (i.e. ASCII characters excludes double quote(%x22)
+1202  * </pre>
+1203  * This method returns false when other characters than above.
+1204  * Otherwise it returns true.
+1205  * @example
+1206  * KJUR.lang.String.isIA5("abc") → true
+1207  * KJUR.lang.String.isIA5('"abc"') → false
+1208  * KJUR.lang.String.isIA5("あいう") → false
+1209  */
+1210 KJUR.lang.String.isIA5 = function(s) {
+1211     if (s.match(/^[\x20-\x21\x23-\x7f]*$/) !== null) return true;
+1212     return false;
+1213 };
+1214 
+1215 /**
+1216  * check whether a string is RFC 822 mail address<br/>
+1217  * @name isMail
+1218  * @memberOf KJUR.lang.String
+1219  * @function
+1220  * @static
+1221  * @param {String} s input string
+1222  * @return {Boolean} true if a string "s" RFC 822 mail address
+1223  * @since jsrsasign 9.0.0 base64x 1.1.16
+1224  * This static method will check string s is RFC 822 compliant mail address.
+1225  * @example
+1226  * KJUR.lang.String.isMail("abc") → false
+1227  * KJUR.lang.String.isMail("abc@example") → false
+1228  * KJUR.lang.String.isMail("abc@example.com") → true
+1229  */
+1230 KJUR.lang.String.isMail = function(s) {
+1231     if (s.match(/^[A-Za-z0-9]{1}[A-Za-z0-9_.-]*@{1}[A-Za-z0-9_.-]{1,}\.[A-Za-z0-9]{1,}$/) !== null) return true;
+1232     return false;
+1233 };
+1234 
+1235 // ==== others ================================
+1236 
+1237 /**
+1238  * canonicalize hexadecimal string of positive integer<br/>
+1239  * @name hextoposhex
+1240  * @function
+1241  * @param {String} s hexadecimal string 
+1242  * @return {String} canonicalized hexadecimal string of positive integer
+1243  * @since base64x 1.1.10 jsrsasign 7.1.4
+1244  * @description
+1245  * This method canonicalize a hexadecimal string of positive integer
+1246  * for two's complement representation.
+1247  * Canonicalized hexadecimal string of positive integer will be:
+1248  * <ul>
+1249  * <li>Its length is always even.</li>
+1250  * <li>If odd length it will be padded with leading zero.<li>
+1251  * <li>If it is even length and its first character is "8" or greater,
+1252  * it will be padded with "00" to make it positive integer.</li>
+1253  * </ul>
+1254  * @example
+1255  * hextoposhex("abcd") → "00abcd"
+1256  * hextoposhex("1234") → "1234"
+1257  * hextoposhex("12345") → "012345"
+1258  */
+1259 function hextoposhex(s) {
+1260     if (s.length % 2 == 1) return "0" + s;
+1261     if (s.substr(0, 1) > "7") return "00" + s;
+1262     return s;
+1263 }
+1264 
+1265 /**
+1266  * convert string of integer array to hexadecimal string.<br/>
+1267  * @name intarystrtohex
+1268  * @function
+1269  * @param {String} s string of integer array
+1270  * @return {String} hexadecimal string
+1271  * @since base64x 1.1.6 jsrsasign 5.0.2
+1272  * @throws "malformed integer array string: *" for wrong input
+1273  * @description
+1274  * This function converts a string of JavaScript integer array to
+1275  * a hexadecimal string. Each integer value shall be in a range 
+1276  * from 0 to 255 otherwise it raise exception. Input string can
+1277  * have extra space or newline string so that they will be ignored.
+1278  * 
+1279  * @example
+1280  * intarystrtohex(" [123, 34, 101, 34, 58] ")
+1281  * → 7b2265223a (i.e. '{"e":' as string)
+1282  */
+1283 function intarystrtohex(s) {
+1284   s = s.replace(/^\s*\[\s*/, '');
+1285   s = s.replace(/\s*\]\s*$/, '');
+1286   s = s.replace(/\s*/g, '');
+1287   try {
+1288     var hex = s.split(/,/).map(function(element, index, array) {
+1289       var i = parseInt(element);
+1290       if (i < 0 || 255 < i) throw "integer not in range 0-255";
+1291       var hI = ("00" + i.toString(16)).slice(-2);
+1292       return hI;
+1293     }).join('');
+1294     return hex;
+1295   } catch(ex) {
+1296     throw "malformed integer array string: " + ex;
+1297   }
+1298 }
+1299 
+1300 /**
+1301  * find index of string where two string differs
+1302  * @name strdiffidx
+1303  * @function
+1304  * @param {String} s1 string to compare
+1305  * @param {String} s2 string to compare
+1306  * @return {Number} string index of where character differs. Return -1 if same.
+1307  * @since jsrsasign 4.9.0 base64x 1.1.5
+1308  * @example
+1309  * strdiffidx("abcdefg", "abcd4fg") -> 4
+1310  * strdiffidx("abcdefg", "abcdefg") -> -1
+1311  * strdiffidx("abcdefg", "abcdef") -> 6
+1312  * strdiffidx("abcdefgh", "abcdef") -> 6
+1313  */
+1314 var strdiffidx = function(s1, s2) {
+1315     var n = s1.length;
+1316     if (s1.length > s2.length) n = s2.length;
+1317     for (var i = 0; i < n; i++) {
+1318 	if (s1.charCodeAt(i) != s2.charCodeAt(i)) return i;
+1319     }
+1320     if (s1.length != s2.length) return n;
+1321     return -1; // same
+1322 };
+1323 
+1324 // ==== hex / oid =================================
+1325 
+1326 /**
+1327  * get hexadecimal value of object identifier from dot noted oid value
+1328  * @name oidtohex
+1329  * @function
+1330  * @param {String} oidString dot noted string of object identifier
+1331  * @return {String} hexadecimal value of object identifier
+1332  * @since jsrsasign 10.1.0 base64x 1.1.18
+1333  * @see hextooid
+1334  * @see ASN1HEX.hextooidstr
+1335  * @see KJUR.asn1.ASN1Util.oidIntToHex
+1336  * @description
+1337  * This static method converts from object identifier value string.
+1338  * to hexadecimal string representation of it.
+1339  * {@link hextooid} is a reverse function of this.
+1340  * @example
+1341  * oidtohex("2.5.4.6") → "550406"
+1342  */
+1343 function oidtohex(oidString) {
+1344     var itox = function(i) {
+1345         var h = i.toString(16);
+1346         if (h.length == 1) h = '0' + h;
+1347         return h;
+1348     };
+1349 
+1350     var roidtox = function(roid) {
+1351         var h = '';
+1352         var bi = parseInt(roid, 10);
+1353         var b = bi.toString(2);
+1354 
+1355         var padLen = 7 - b.length % 7;
+1356         if (padLen == 7) padLen = 0;
+1357         var bPad = '';
+1358         for (var i = 0; i < padLen; i++) bPad += '0';
+1359         b = bPad + b;
+1360         for (var i = 0; i < b.length - 1; i += 7) {
+1361             var b8 = b.substr(i, 7);
+1362             if (i != b.length - 7) b8 = '1' + b8;
+1363             h += itox(parseInt(b8, 2));
+1364         }
+1365         return h;
+1366     };
+1367     
+1368     try {
+1369 	if (! oidString.match(/^[0-9.]+$/)) return null;
+1370     
+1371 	var h = '';
+1372 	var a = oidString.split('.');
+1373 	var i0 = parseInt(a[0], 10) * 40 + parseInt(a[1], 10);
+1374 	h += itox(i0);
+1375 	a.splice(0, 2);
+1376 	for (var i = 0; i < a.length; i++) {
+1377             h += roidtox(a[i]);
+1378 	}
+1379 	return h;
+1380     } catch(ex) {
+1381 	return null;
+1382     }
+1383 };
+1384 
+1385 /**
+1386  * get oid string from hexadecimal value of object identifier<br/>
+1387  * @name hextooid
+1388  * @function
+1389  * @param {String} h hexadecimal value of object identifier
+1390  * @return {String} dot noted string of object identifier (ex. "1.2.3.4")
+1391  * @since jsrsasign 10.1.0 base64x 1.1.18
+1392  * @see oidtohex
+1393  * @see ASN1HEX.hextooidstr
+1394  * @see KJUR.asn1.ASN1Util.oidIntToHex
+1395  * @description
+1396  * This static method converts from hexadecimal object identifier value 
+1397  * to dot noted OID value (ex. "1.2.3.4").
+1398  * {@link oidtohex} is a reverse function of this.
+1399  * @example
+1400  * hextooid("550406") → "2.5.4.6"
+1401  */
+1402 function hextooid(h) {
+1403     if (! ishex(h)) return null;
+1404     try {
+1405 	var a = [];
+1406 
+1407 	// a[0], a[1]
+1408 	var hex0 = h.substr(0, 2);
+1409 	var i0 = parseInt(hex0, 16);
+1410 	a[0] = new String(Math.floor(i0 / 40));
+1411 	a[1] = new String(i0 % 40);
+1412 
+1413 	// a[2]..a[n]
+1414 	var hex1 = h.substr(2);
+1415 	var b = [];
+1416 	for (var i = 0; i < hex1.length / 2; i++) {
+1417 	    b.push(parseInt(hex1.substr(i * 2, 2), 16));
+1418 	}
+1419 	var c = [];
+1420 	var cbin = "";
+1421 	for (var i = 0; i < b.length; i++) {
+1422             if (b[i] & 0x80) {
+1423 		cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7);
+1424             } else {
+1425 		cbin = cbin + strpad((b[i] & 0x7f).toString(2), 7);
+1426 		c.push(new String(parseInt(cbin, 2)));
+1427 		cbin = "";
+1428             }
+1429 	}
+1430 
+1431 	var s = a.join(".");
+1432 	if (c.length > 0) s = s + "." + c.join(".");
+1433 	return s;
+1434     } catch(ex) {
+1435 	return null;
+1436     }
+1437 };
+1438 
+1439 /**
+1440  * string padding<br/>
+1441  * @name strpad
+1442  * @function
+1443  * @param {String} s input string
+1444  * @param {Number} len output string length
+1445  * @param {String} padchar padding character (default is "0")
+1446  * @return {String} padded string
+1447  * @since jsrsasign 10.1.0 base64x 1.1.18
+1448  * @example
+1449  * strpad("1234", 10, "0") → "0000001234"
+1450  * strpad("1234", 10, " ") → "      1234"
+1451  * strpad("1234", 10)      → "0000001234"
+1452  */
+1453 var strpad = function(s, len, padchar) {
+1454     if (padchar == undefined) padchar = "0";
+1455     if (s.length >= len) return s;
+1456     return new Array(len - s.length + 1).join(padchar) + s;
+1457 };
+1458 
+1459 // ==== bitstr hex / int =================================
+1460 
+1461 /**
+1462  * convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value<br/>
+1463  * @name bitstrtoint
+1464  * @function
+1465  * @param {String} h hexadecimal string of ASN.1 BitString value with unused bit
+1466  * @return {Number} positive integer value of the BitString
+1467  * @since jsrsasign 10.1.3 base64x 1.1.19
+1468  * @see inttobitstr
+1469  * @see KJUR.asn1.DERBitString
+1470  * @see ASN1HEX.getInt
 1471  * 
-1472  * @example
-1473  * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25
-1474  * bitstrtoint("03c8") → 25
-1475  * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02
-1476  * //   11111111111110b → 16382
-1477  * bitstrtoint("02fff8") → 16382
-1478  */
-1479 function bitstrtoint(h) {
-1480     try {
-1481 	var hUnusedbit = h.substr(0, 2);
-1482 	if (hUnusedbit == "00")
-1483 	    return parseInt(h.substr(2), 16);
-1484 	var iUnusedbit = parseInt(hUnusedbit, 16);
-1485 	var hValue = h.substr(2);
-1486 	var bValue = parseInt(hValue, 16).toString(2);
-1487 	if (bValue == "0") bValue = "00000000";
-1488 	bValue = bValue.slice(0, 0 - iUnusedbit);
-1489 	return parseInt(bValue, 2);
-1490     } catch(ex) {
-1491 	return -1;
-1492     }
-1493 };
-1494 
-1495 
-1496 /**
-1497  * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit<br/>
-1498  * @name inttobitstr
-1499  * @function
-1500  * @param {Number} n integer value of ASN.1 BitString
-1501  * @return {String} hexadecimal string of ASN.1 BitString value with unused bit
-1502  * @since jsrsasign 10.1.3 base64x 1.1.19
-1503  * @see bitstrtoint
-1504  * @see KJUR.asn1.DERBitString
-1505  * @see ASN1HEX.getInt
-1506  * 
-1507  * @description
-1508  * This function converts from an integer value to 
-1509  * hexadecimal string of ASN.1 BitString value
-1510  * with unused bit.
-1511  * 
-1512  * @example
-1513  * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8"
-1514  * inttobitstr(25) → "03c8"
-1515  */
-1516 function inttobitstr(n) {
-1517     var bValue = Number(n).toString(2);
-1518     var iUnusedbit = 8 - bValue.length % 8;
-1519     if (iUnusedbit == 8) iUnusedbit = 0;
-1520     bValue = bValue + strpad("", iUnusedbit, "0");
-1521     var hValue = parseInt(bValue, 2).toString(16);
-1522     if (hValue.length % 2 == 1) hValue = "0" + hValue;
-1523     var hUnusedbit = "0" + iUnusedbit;
-1524     return hUnusedbit + hValue;
-1525 };
-1526 
-1527 /**
-1528  * set class inheritance<br/>
-1529  * @name extendClass
-1530  * @function
-1531  * @param {Function} subClass sub class to set inheritance
-1532  * @param {Function} superClass super class to inherit
-1533  * @since jsrsasign 10.3.0 base64x 1.1.21
-1534  *
-1535  * @description
-1536  * This function extends a class and set an inheritance
-1537  * for member variables and methods.
-1538  *
-1539  * @example
-1540  * var Animal = function() {
-1541  *   this.hello = function(){console.log("Hello")};
-1542  *   this.name="Ani";
-1543  * };
-1544  * var Dog = function() {
-1545  *   Dog.superclass.constructor.call(this);
-1546  *   this.vow = function(){console.log("Vow wow")};
-1547  *   this.tail=true;
-1548  * };
-1549  * extendClass(Dog, Animal);
-1550  */
-1551 function extendClass(subClass, superClass) {
-1552     var F = function() {};
-1553     F.prototype = superClass.prototype;
-1554     subClass.prototype = new F();
-1555     subClass.prototype.constructor = subClass;
-1556     subClass.superclass = superClass.prototype;
-1557      
-1558     if (superClass.prototype.constructor == Object.prototype.constructor) {
-1559         superClass.prototype.constructor = superClass;
-1560     }
-1561 };
-1562 
-1563 
\ No newline at end of file +1472 * @description +1473 * This function converts from hexadecimal string of ASN.1 BitString +1474 * value with unused bit to its integer value. <br/> +1475 * When an improper hexadecimal string of BitString value +1476 * is applied, this returns -1. +1477 * +1478 * @example +1479 * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25 +1480 * bitstrtoint("03c8") → 25 +1481 * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02 +1482 * // 11111111111110b → 16382 +1483 * bitstrtoint("02fff8") → 16382 +1484 * bitstrtoint("05a0") → 5 (=101b) +1485 * bitstrtoint("ff00") → -1 // for improper BitString value +1486 * bitstrtoint("05a0").toString(2) → "101" +1487 * bitstrtoint("07a080").toString(2) → "101000001" +1488 */
+1489 function bitstrtoint(h) { +1490 if (h.length % 2 != 0) return -1; +1491 h = h.toLowerCase(); +1492 if (h.match(/^[0-9a-f]+$/) == null) return -1; +1493 try { +1494 var hUnusedbit = h.substr(0, 2); +1495 if (hUnusedbit == "00") +1496 return parseInt(h.substr(2), 16); +1497 var iUnusedbit = parseInt(hUnusedbit, 16); +1498 if (iUnusedbit > 7) return -1; +1499 var hValue = h.substr(2); +1500 var bValue = parseInt(hValue, 16).toString(2); +1501 if (bValue == "0") bValue = "00000000"; +1502 bValue = bValue.slice(0, 0 - iUnusedbit); +1503 var iValue = parseInt(bValue, 2); +1504 if (iValue == NaN) return -1; +1505 return iValue; +1506 } catch(ex) { +1507 return -1; +1508 } +1509 }; +1510 +1511 /** +1512 * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit<br/> +1513 * @name inttobitstr +1514 * @function +1515 * @param {Number} n integer value of ASN.1 BitString +1516 * @return {String} hexadecimal string of ASN.1 BitString value with unused bit +1517 * @since jsrsasign 10.1.3 base64x 1.1.19 +1518 * @see bitstrtoint +1519 * @see KJUR.asn1.DERBitString +1520 * @see ASN1HEX.getInt +1521 * +1522 * @description +1523 * This function converts from an integer value to +1524 * hexadecimal string of ASN.1 BitString value +1525 * with unused bit. <br/> +1526 * When "n" is not non-negative number, this returns null +1527 * +1528 * @example +1529 * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8" +1530 * inttobitstr(25) → "03c8" +1531 * inttobitstr(-3) → null +1532 * inttobitstr("abc") → null +1533 * inttobitstr(parseInt("11001", 2)) → "03c8" +1534 * inttobitstr(parseInt("101", 2)) → "05a0" +1535 * inttobitstr(parseInt("101000001", 2)) → "07a080" +1536 */ +1537 function inttobitstr(n) { +1538 if (typeof n != "number") return null; +1539 if (n < 0) return null; +1540 var bValue = Number(n).toString(2); +1541 var iUnusedbit = 8 - bValue.length % 8; +1542 if (iUnusedbit == 8) iUnusedbit = 0; +1543 bValue = bValue + strpad("", iUnusedbit, "0"); +1544 var hValue = parseInt(bValue, 2).toString(16); +1545 if (hValue.length % 2 == 1) hValue = "0" + hValue; +1546 var hUnusedbit = "0" + iUnusedbit; +1547 return hUnusedbit + hValue; +1548 }; +1549 +1550 // ==== bitstr hex / binary string ======================= +1551 +1552 /** +1553 * convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string<br/> +1554 * @name bitstrtobinstr +1555 * @function +1556 * @param {string} h hexadecimal string of ASN.1 BitString value with unused bit +1557 * @return {string} binary string +1558 * @since jsrsasign 10.5.4 base64x 1.1.21 +1559 * @see binstrtobitstr +1560 * @see inttobitstr +1561 * +1562 * @description +1563 * This function converts from hexadecimal string of ASN.1 BitString +1564 * value with unused bit to its integer value. <br/> +1565 * When an improper hexadecimal string of BitString value +1566 * is applied, this returns null. +1567 * +1568 * @example +1569 * bitstrtobinstr("05a0") → "101" +1570 * bitstrtobinstr("07a080") → "101000001" +1571 * bitstrtoint(502) → null // non ASN.1 BitString value +1572 * bitstrtoint("ff00") → -1 // for improper BitString value +1573 */ +1574 function bitstrtobinstr(h) { +1575 var n = bitstrtoint(h); +1576 if (n == -1) return null; +1577 return n.toString(2); +1578 } +1579 +1580 /** +1581 * convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit<br/> +1582 * @name binstrtobitstr +1583 * @function +1584 * @param {string} s binary string (ex. "101") +1585 * @return {string} hexadecimal string of ASN.1 BitString value with unused bit +1586 * @since jsrsasign 10.5.4 base64x 1.1.21 +1587 * @see bitstrtobinstr +1588 * @see inttobitstr +1589 * @see KJUR.asn1.DERBitString +1590 * +1591 * @description +1592 * This function converts from an binary string (ex. "101") to +1593 * hexadecimal string of ASN.1 BitString value +1594 * with unused bit (ex. "05a0"). <br/> +1595 * When "s" is not binary string, this returns null. +1596 * +1597 * @example +1598 * binstrtobitstr("101") → "05a0" +1599 * binstrtobitstr("11001") → "03c8" +1600 * binstrtobitstr("101000001") → "07a080" +1601 * binstrtobitstr(101) → null // not number +1602 * binstrtobitstr("xyz") → null // not binary string +1603 */ +1604 function binstrtobitstr(s) { +1605 if (typeof s != "string") return null; +1606 if (s.match(/^[01]+$/) == null) return null; +1607 try { +1608 var n = parseInt(s, 2); +1609 return inttobitstr(n); +1610 } catch(ex) { +1611 return null; +1612 } +1613 } +1614 +1615 // ======================================================= +1616 /** +1617 * set class inheritance<br/> +1618 * @name extendClass +1619 * @function +1620 * @param {Function} subClass sub class to set inheritance +1621 * @param {Function} superClass super class to inherit +1622 * @since jsrsasign 10.3.0 base64x 1.1.21 +1623 * +1624 * @description +1625 * This function extends a class and set an inheritance +1626 * for member variables and methods. +1627 * +1628 * @example +1629 * var Animal = function() { +1630 * this.hello = function(){console.log("Hello")}; +1631 * this.name="Ani"; +1632 * }; +1633 * var Dog = function() { +1634 * Dog.superclass.constructor.call(this); +1635 * this.vow = function(){console.log("Vow wow")}; +1636 * this.tail=true; +1637 * }; +1638 * extendClass(Dog, Animal); +1639 */ +1640 function extendClass(subClass, superClass) { +1641 var F = function() {}; +1642 F.prototype = superClass.prototype; +1643 subClass.prototype = new F(); +1644 subClass.prototype.constructor = subClass; +1645 subClass.superclass = superClass.prototype; +1646 +1647 if (superClass.prototype.constructor == Object.prototype.constructor) { +1648 superClass.prototype.constructor = superClass; +1649 } +1650 }; +1651 +1652
\ No newline at end of file diff --git a/bower.json b/bower.json index 00a9f9cf..6a836c93 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kjur-jsrsasign", - "version": "10.5.3", + "version": "10.5.4", "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 c6d3a69d..5c2d6874 100644 --- a/jsrsasign-all-min.js +++ b/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.5.3 (2022-02-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license + * jsrsasign(all) 10.5.4 (2022-02-15) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -217,15 +217,15 @@ ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBi /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ var jsonParse=(function(){var e="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)";var j='(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';var i='(?:"'+j+'*")';var d=new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|"+e+"|"+i+")","g");var k=new RegExp("\\\\(?:([^u])|u(.{4}))","g");var g={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function h(l,m,n){return m?g[m]:String.fromCharCode(parseInt(n,16))}var c=new String("");var a="\\";var f={"{":Object,"[":Array};var b=Object.hasOwnProperty;return function(u,q){var p=u.match(d);var x;var v=p[0];var l=false;if("{"===v){x={}}else{if("["===v){x=[]}else{x=[];l=true}}var t;var r=[x];for(var o=1-l,m=p.length;o=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -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:a}}}else{return{"enum":parseInt(a,16)}}}else{if(r=="30"||r=="31"){q[f[r]]=b(i);return q}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(r)!=-1){var p=hextoutf8(a);q[f[r]]={str:p};return q}else{if(r.match(/^8[0-9]$/)){return{tag:{tag:r,explicit:false,hex:a}}}else{if(r.match(/^a[0-9]$/)){return{tag:{tag:r,explicit:true,hex:a}}}else{var l=new KJUR.asn1.ASN1Object();l.hV=a;var j=l.getLengthHexFromValue();return{asn1:{tlv:r+j+a}}}}}}}}}}}}}};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;e15){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;e0){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extensions=function(d){KJUR.asn1.x509.Extensions.superclass.constructor.call(this);var c=KJUR,b=c.asn1,a=b.DERSequence,e=b.x509;this.aParam=[];this.setByParam=function(f){this.aParam=f};this.getEncodedHex=function(){var f=[];for(var h=0;h-1){i.push(new f({"int":this.pathLen}))}var h=new b({array:i});this.asn1ExtnValue=h;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(g!==undefined){if(g.cA!==undefined){this.cA=g.cA}if(g.pathLen!==undefined){this.pathLen=g.pathLen}}};extendClass(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(d){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,d);var b=KJUR,a=b.asn1,c=a.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(e){var f=[];for(var g=0;g0){f.push(new b({array:j}))}}var g=new b({array:f});return g.getEncodedHex()};if(d!==undefined){this.params=d}};extendClass(KJUR.asn1.x509.PolicyInformation,KJUR.asn1.ASN1Object);KJUR.asn1.x509.PolicyQualifierInfo=function(e){KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this,e);var c=KJUR.asn1,b=c.DERSequence,d=c.DERIA5String,f=c.DERObjectIdentifier,a=c.x509.UserNotice;this.params=null;this.getEncodedHex=function(){if(this.params.cps!==undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.1"}),new d({str:this.params.cps})]});return g.getEncodedHex()}if(this.params.unotice!=undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.2"}),new a(this.params.unotice)]});return g.getEncodedHex()}};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.PolicyQualifierInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.UserNotice=function(e){KJUR.asn1.x509.UserNotice.superclass.constructor.call(this,e);var a=KJUR.asn1.DERSequence,d=KJUR.asn1.DERInteger,c=KJUR.asn1.x509.DisplayText,b=KJUR.asn1.x509.NoticeReference;this.params=null;this.getEncodedHex=function(){var f=[];if(this.params.noticeref!==undefined){f.push(new b(this.params.noticeref))}if(this.params.exptext!==undefined){f.push(new c(this.params.exptext))}var g=new a({array:f});return g.getEncodedHex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.UserNotice,KJUR.asn1.ASN1Object);KJUR.asn1.x509.NoticeReference=function(d){KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this,d);var a=KJUR.asn1.DERSequence,c=KJUR.asn1.DERInteger,b=KJUR.asn1.x509.DisplayText;this.params=null;this.getEncodedHex=function(){var f=[];if(this.params.org!==undefined){f.push(new b(this.params.org))}if(this.params.noticenum!==undefined){var h=[];var e=this.params.noticenum;for(var j=0;j0){for(var g=0;g0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.X500Name.ldapToOneline=function(a){return KJUR.asn1.x509.X500Name.ldapToCompat(a)};KJUR.asn1.x509.RDN=function(b){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=[];this.paramArray=[];this.sRule="utf8";var a=KJUR.asn1.x509.AttributeTypeAndValue;this.setByParam=function(c){if(c.rule!==undefined){this.sRule=c.rule}if(c.str!==undefined){this.addByMultiValuedString(c.str)}if(c.array!==undefined){this.paramArray=c.array}};this.addByString=function(c){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:c,rule:this.sRule}))};this.addByMultiValuedString=function(e){var c=KJUR.asn1.x509.RDN.parseString(e);for(var d=0;d0){for(var d=0;d0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(c){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);this.sRule="utf8";this.sType=null;this.sValue=null;this.dsType=null;var a=KJUR,g=a.asn1,d=g.DERSequence,l=g.DERUTF8String,i=g.DERPrintableString,h=g.DERTeletexString,b=g.DERIA5String,e=g.DERVisibleString,k=g.DERBMPString,f=a.lang.String.isMail,j=a.lang.String.isPrintable;this.setByParam=function(o){if(o.rule!==undefined){this.sRule=o.rule}if(o.ds!==undefined){this.dsType=o.ds}if(o.value===undefined&&o.str!==undefined){var n=o.str;var m=n.match(/^([^=]+)=(.+)$/);if(m){this.sType=m[1];this.sValue=m[2]}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}}else{this.sType=o.type;this.sValue=o.value}};this.setByString=function(n,o){if(o!==undefined){this.sRule=o}var m=n.match(/^([^=]+)=(.+)$/);if(m){this.setByAttrTypeAndValueStr(m[1],m[2])}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}};this._getDsType=function(){var o=this.sType;var n=this.sValue;var m=this.sRule;if(m==="prn"){if(o=="CN"&&f(n)){return"ia5"}if(j(n)){return"prn"}return"utf8"}else{if(m==="utf8"){if(o=="CN"&&f(n)){return"ia5"}if(o=="C"){return"prn"}return"utf8"}}return"utf8"};this.setByAttrTypeAndValueStr=function(o,n,m){if(m!==undefined){this.sRule=m}this.sType=o;this.sValue=n};this.getValueObj=function(n,m){if(n=="utf8"){return new l({str:m})}if(n=="prn"){return new i({str:m})}if(n=="tel"){return new h({str:m})}if(n=="ia5"){return new b({str:m})}if(n=="vis"){return new e({str:m})}if(n=="bmp"){return new k({str:m})}throw new Error("unsupported directory string type: type="+n+" value="+m)};this.getEncodedHex=function(){if(this.dsType==null){this.dsType=this._getDsType()}var n=KJUR.asn1.x509.OID.atype2obj(this.sType);var m=this.getValueObj(this.dsType,this.sValue);var p=new d({array:[n,m]});this.TLV=p.getEncodedHex();return this.TLV};if(c!==undefined){this.setByParam(c)}};extendClass(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(f){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var l=null,k=null,a=KJUR,j=a.asn1,i=j.DERInteger,b=j.DERBitString,m=j.DERObjectIdentifier,e=j.DERSequence,h=j.ASN1Util.newObject,d=j.x509,o=d.AlgorithmIdentifier,g=a.crypto,n=g.ECDSA,c=g.DSA;this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var p=new e({array:[this.asn1AlgId,this.asn1SubjPKey]});return p};this.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();this.asn1AlgId=new o({name:"rsaEncryption"});this.asn1SubjPKey=new b({hex:"00"+s})}}catch(p){}try{if(q instanceof KJUR.crypto.ECDSA){var r=new m({name:q.curveName});this.asn1AlgId=new o({name:"ecPublicKey",asn1params:r});this.asn1SubjPKey=new b({hex:"00"+q.pubKeyHex})}}catch(p){}try{if(q instanceof KJUR.crypto.DSA){var r=new h({seq:[{"int":{bigint:q.p}},{"int":{bigint:q.q}},{"int":{bigint:q.g}}]});this.asn1AlgId=new o({name:"dsa",asn1params:r});var t=new i({bigint:q.y});this.asn1SubjPKey=new b({hex:"00"+t.getEncodedHex()})}}catch(p){}};if(f!==undefined){this.setPubKey(f)}};extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(f){KJUR.asn1.x509.Time.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.params=null;this.type=null;this.setTimeParams=function(h){this.timeParams=h};this.setByParam=function(h){this.params=h};this.getType=function(h){if(h.match(/^[0-9]{12}Z$/)){return"utc"}if(h.match(/^[0-9]{14}Z$/)){return"gen"}if(h.match(/^[0-9]{12}\.[0-9]+Z$/)){return"utc"}if(h.match(/^[0-9]{14}\.[0-9]+Z$/)){return"gen"}return null};this.getEncodedHex=function(){var i=this.params;var h=null;if(typeof i=="string"){i={str:i}}if(i!=null&&i.str&&(i.type==null||i.type==undefined)){i.type=this.getType(i.str)}if(i!=null&&i.str){if(i.type=="utc"){h=new b(i.str)}if(i.type=="gen"){h=new g(i.str)}}else{if(this.type=="gen"){h=new g()}else{h=new b()}}if(h==null){throw new Error("wrong setting for Time")}this.TLV=h.getEncodedHex();return this.TLV};if(f!=undefined){this.setByParam(f)}};KJUR.asn1.x509.Time_bak=function(f){KJUR.asn1.x509.Time_bak.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.setTimeParams=function(h){this.timeParams=h};this.getEncodedHex=function(){var h=null;if(this.timeParams!=null){if(this.type=="utc"){h=new b(this.timeParams)}else{h=new g(this.timeParams)}}else{if(this.type=="utc"){h=new b()}else{h=new g()}}this.TLV=h.getEncodedHex();return this.TLV};this.type="utc";if(f!==undefined){if(f.type!==undefined){this.type=f.type}else{if(f.str!==undefined){if(f.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(f.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=f}};extendClass(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);this.nameAlg=null;this.asn1Alg=null;this.asn1Params=null;this.paramEmpty=false;var b=KJUR,a=b.asn1,c=a.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV;this.getEncodedHex=function(){if(this.nameAlg===null&&this.asn1Alg===null){throw new Error("algorithm not specified")}if(this.nameAlg!==null){var f=null;for(var h in c){if(h===this.nameAlg){f=c[h]}}if(f!==null){this.hTLV=f;return this.hTLV}}if(this.nameAlg!==null&&this.asn1Alg===null){this.asn1Alg=a.x509.OID.name2obj(this.nameAlg)}var g=[this.asn1Alg];if(this.asn1Params!==null){g.push(this.asn1Params)}var i=new a.DERSequence({array:g});this.hTLV=i.getEncodedHex();return this.hTLV};if(e!==undefined){if(e.name!==undefined){this.nameAlg=e.name}if(e.asn1params!==undefined){this.asn1Params=e.asn1params}if(e.paramempty!==undefined){this.paramEmpty=e.paramempty}}if(this.asn1Params===null&&this.paramEmpty===false&&this.nameAlg!==null){if(this.nameAlg.name!==undefined){this.nameAlg=this.nameAlg.name}var d=this.nameAlg.toLowerCase();if(d.substr(-7,7)!=="withdsa"&&d.substr(-9,9)!=="withecdsa"){this.asn1Params=new a.DERNull()}}};extendClass(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV={SHAwithRSAandMGF1:"300d06092a864886f70d01010a3000",SHA256withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",SHA384withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",SHA512withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140"};KJUR.asn1.x509.GeneralName=function(f){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var l={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},b=KJUR,h=b.asn1,d=h.x509,a=d.X500Name,g=d.OtherName,e=h.DERIA5String,i=h.DERPrintableString,k=h.DEROctetString,c=h.DERTaggedObject,m=h.ASN1Object,j=Error;this.params=null;this.setByParam=function(n){this.params=n};this.getEncodedHex=function(){var p=this.params;var z,w,q;var w=false;if(p.other!==undefined){z="a0",q=new g(p.other)}else{if(p.rfc822!==undefined){z="81";q=new e({str:p.rfc822})}else{if(p.dns!==undefined){z="82";q=new e({str:p.dns})}else{if(p.dn!==undefined){z="a4";w=true;if(typeof p.dn==="string"){q=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){q=p.dn}else{q=new a(p.dn)}}}else{if(p.ldapdn!==undefined){z="a4";w=true;q=new a({ldapstr:p.ldapdn})}else{if(p.certissuer!==undefined||p.certsubj!==undefined){z="a4";w=true;var n,o;var y=null;if(p.certsubj!==undefined){n=false;o=p.certsubj}else{n=true;o=p.certissuer}if(o.match(/^[0-9A-Fa-f]+$/)){y==o}if(o.indexOf("-----BEGIN ")!=-1){y=pemtohex(o)}if(y==null){throw new Error("certsubj/certissuer not cert")}var v=new X509();v.hex=y;var s;if(n){s=v.getIssuerHex()}else{s=v.getSubjectHex()}q=new m();q.hTLV=s}else{if(p.uri!==undefined){z="86";q=new e({str:p.uri})}else{if(p.ip!==undefined){z="87";var t=p.ip;var u;var r="malformed IP address";if(t.match(/^[0-9.]+[.][0-9.]+$/)){u=intarystrtohex("["+t.split(".").join(",")+"]");if(u.length!==8){throw new j(r)}}else{if(t.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){u=ipv6tohex(t)}else{if(t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){u=t}else{throw new j(r)}}}q=new k({hex:u})}else{throw new j("improper params")}}}}}}}}var A=new c({tag:z,explicit:w,obj:q});return A.getEncodedHex()};if(f!==undefined){this.setByParam(f)}};KJUR.asn1.x509.GeneralName_bak=function(o){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var n=null,b=null,r={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},q=KJUR,e=q.asn1,a=_KJURd_asn1.x509,l=e.DERObjectIdentifier,d=e.DERSequence,c=e.DEROctetString,m=e.DERPrintableString,g=e.DERIA5String,i=e.DERTaggedObject,j=e.ASN1Object,k=a.X500Name,h=a.OtherName,f=e.ASN1Util.newObject,p=pemtohex;this.explicit=false;this.setByParam=function(w){var A=null;var E=null;if(w===undefined){return}if(w.rfc822!==undefined){this.type="rfc822";E=new g({str:w[this.type]})}if(w.other!==undefined){this.type="otherName";var D=new l({oid:w[this.type].oid});var y=f(w[this.type].obj);var t=new Array();t.push(D);t.push(y);E=new d({array:t})}if(w.dns!==undefined){this.type="dns";E=new g({str:w[this.type]})}if(w.uri!==undefined){this.type="uri";E=new g({str:w[this.type]})}if(w.dn!==undefined){this.type="dn";this.explicit=true;if(typeof w.dn==="string"){E=new k({str:w.dn})}else{if(w.dn instanceof KJUR.asn1.x509.X500Name){E=w.dn}else{E=new k(w.dn)}}}if(w.ldapdn!==undefined){this.type="dn";this.explicit=true;E=new k({ldapstr:w.ldapdn})}if(w.certissuer!==undefined){this.type="dn";this.explicit=true;var u=w.certissuer;var F=null;if(u.match(/^[0-9A-Fa-f]+$/)){F==u}if(u.indexOf("-----BEGIN ")!=-1){F=p(u)}if(F==null){throw"certissuer param not cert"}var C=new X509();C.hex=F;var G=C.getIssuerHex();E=new j();E.hTLV=G}if(w.certsubj!==undefined){this.type="dn";this.explicit=true;var u=w.certsubj;var F=null;if(u.match(/^[0-9A-Fa-f]+$/)){F==u}if(u.indexOf("-----BEGIN ")!=-1){F=p(u)}if(F==null){throw"certsubj param not cert"}var C=new X509();C.hex=F;var G=C.getSubjectHex();E=new j();E.hTLV=G}if(w.ip!==undefined){this.type="ip";this.explicit=false;var z=w.ip;var B;var s="malformed IP address";if(z.match(/^[0-9.]+[.][0-9.]+$/)){B=intarystrtohex("["+z.split(".").join(",")+"]");if(B.length!==8){throw s}}else{if(z.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){B=ipv6tohex(z)}else{if(z.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){B=z}else{throw s}}}E=new c({hex:B})}if(this.type==null){throw"unsupported type in params="+w}this.asn1Obj=new i({explicit:this.explicit,tag:r[this.type],obj:E})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(o!==undefined){this.setByParam(o)}};extendClass(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(d){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null,c=KJUR,b=c.asn1;this.setByParamArray=function(g){for(var e=0;e0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;mf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--u){v=v.twice2D();v.z=f.ONE;if(t.testBit(u)){if(s.testBit(u)){v=v.add2D(y)}else{v=v.add2D(x)}}else{if(s.testBit(u)){v=v.add2D(w)}}}return v}this.getBigRandom=function(r){return new f(r.bitLength(),a).mod(r.subtract(f.ONE)).add(f.ONE)};this.setNamedCurve=function(r){this.ecparams=c.getByName(r);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=r};this.setPrivateKeyHex=function(r){this.isPrivate=true;this.prvKeyHex=r};this.setPublicKeyHex=function(r){this.isPublic=true;this.pubKeyHex=r};this.getPublicKeyXYHex=function(){var t=this.pubKeyHex;if(t.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var s=this.ecparams.keycharlen;if(t.length!==2+s*2){throw"malformed public key hex length"}var r={};r.x=t.substr(2,s);r.y=t.substr(2+s);return r};this.getShortNISTPCurveName=function(){var r=this.curveName;if(r==="secp256r1"||r==="NIST P-256"||r==="P-256"||r==="prime256v1"){return"P-256"}if(r==="secp384r1"||r==="NIST P-384"||r==="P-384"){return"P-384"}if(r==="secp521r1"||r==="NIST P-521"||r==="P-521"){return"P-521"}return null};this.generateKeyPairHex=function(){var s=this.ecparams.n;var u=this.getBigRandom(s);var r=this.ecparams.keycharlen;var t=("0000000000"+u.toString(16)).slice(-r);this.setPrivateKeyHex(t);var v=this.generatePublicKeyHex();return{ecprvhex:t,ecpubhex:v}};this.generatePublicKeyHex=function(){var u=new f(this.prvKeyHex,16);var w=this.ecparams.G.multiply(u);var t=w.getX().toBigInteger();var s=w.getY().toBigInteger();var r=this.ecparams.keycharlen;var y=("0000000000"+t.toString(16)).slice(-r);var v=("0000000000"+s.toString(16)).slice(-r);var x="04"+y+v;this.setPublicKeyHex(x);return x};this.signWithMessageHash=function(r){return this.signHex(r,this.prvKeyHex)};this.signHex=function(x,u){var A=new f(u,16);var v=this.ecparams.n;var z=new f(x.substring(0,this.ecparams.keycharlen),16);do{var w=this.getBigRandom(v);var B=this.ecparams.G;var y=B.multiply(w);var t=y.getX().toBigInteger().mod(v)}while(t.compareTo(f.ZERO)<=0);var C=w.modInverse(v).multiply(z.add(A.multiply(t))).mod(v);return m.biRSSigToASN1Sig(t,C)};this.sign=function(w,B){var z=B;var u=this.ecparams.n;var y=f.fromByteArrayUnsigned(w);do{var v=this.getBigRandom(u);var A=this.ecparams.G;var x=A.multiply(v);var t=x.getX().toBigInteger().mod(u)}while(t.compareTo(BigInteger.ZERO)<=0);var C=v.modInverse(u).multiply(y.add(z.multiply(t))).mod(u);return this.serializeSig(t,C)};this.verifyWithMessageHash=function(s,r){return this.verifyHex(s,r,this.pubKeyHex)};this.verifyHex=function(v,y,u){try{var t,B;var w=m.parseSigHex(y);t=w.r;B=w.s;var x=h.decodeFromHex(this.ecparams.curve,u);var z=new f(v.substring(0,this.ecparams.keycharlen),16);return this.verifyRaw(z,t,B,x)}catch(A){return false}};this.verify=function(z,A,u){var w,t;if(Bitcoin.Util.isArray(A)){var y=this.parseSig(A);w=y.r;t=y.s}else{if("object"===typeof A&&A.r&&A.s){w=A.r;t=A.s}else{throw"Invalid value for signature"}}var v;if(u instanceof ECPointFp){v=u}else{if(Bitcoin.Util.isArray(u)){v=h.decodeFrom(this.ecparams.curve,u)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var x=f.fromByteArrayUnsigned(z);return this.verifyRaw(x,w,t,v)};this.verifyRaw=function(z,t,E,y){var x=this.ecparams.n;var D=this.ecparams.G;if(t.compareTo(f.ONE)<0||t.compareTo(x)>=0){return false}if(E.compareTo(f.ONE)<0||E.compareTo(x)>=0){return false}var A=E.modInverse(x);var w=z.multiply(A).mod(x);var u=t.multiply(A).mod(x);var B=D.multiply(w).add(y.multiply(u));var C=B.getX().toBigInteger().mod(x);return C.equals(t)};this.serializeSig=function(v,u){var w=v.toByteArraySigned();var t=u.toByteArraySigned();var x=[];x.push(2);x.push(w.length);x=x.concat(w);x.push(2);x.push(t.length);x=x.concat(t);x.unshift(x.length);x.unshift(48);return x};this.parseSig=function(y){var x;if(y[0]!=48){throw new Error("Signature not a valid DERSequence")}x=2;if(y[x]!=2){throw new Error("First element in signature must be a DERInteger")}var w=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];if(y[x]!=2){throw new Error("Second element in signature must be a DERInteger")}var t=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];var v=f.fromByteArrayUnsigned(w);var u=f.fromByteArrayUnsigned(t);return{r:v,s:u}};this.parseSigCompact=function(w){if(w.length!==65){throw"Signature has the wrong length"}var t=w[0]-27;if(t<0||t>7){throw"Invalid signature type"}var x=this.ecparams.n;var v=f.fromByteArrayUnsigned(w.slice(1,33)).mod(x);var u=f.fromByteArrayUnsigned(w.slice(33,65)).mod(x);return{r:v,s:u,i:t}};this.readPKCS5PrvKeyHex=function(u){if(k(u)===false){throw new Error("not ASN.1 hex string")}var r,t,v;try{r=n(u,0,["[0]",0],"06");t=n(u,0,[1],"04");try{v=n(u,0,["[1]",0],"03")}catch(s){}}catch(s){throw new Error("malformed PKCS#1/5 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v);this.setPrivateKeyHex(t);this.isPublic=false};this.readPKCS8PrvKeyHex=function(v){if(k(v)===false){throw new j("not ASN.1 hex string")}var t,r,u,w;try{t=n(v,0,[1,0],"06");r=n(v,0,[1,1],"06");u=n(v,0,[2,0,1],"04");try{w=n(v,0,[2,0,"[1]",0],"03")}catch(s){}}catch(s){throw new j("malformed PKCS#8 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(w);this.setPrivateKeyHex(u);this.isPublic=false};this.readPKCS8PubKeyHex=function(u){if(k(u)===false){throw new j("not ASN.1 hex string")}var t,r,v;try{t=n(u,0,[0,0],"06");r=n(u,0,[0,1],"06");v=n(u,0,[1],"03")}catch(s){throw new j("malformed PKCS#8 ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v)};this.readCertPubKeyHex=function(t,v){if(k(t)===false){throw new j("not ASN.1 hex string")}var r,u;try{r=n(t,0,[0,5,0,1],"06");u=n(t,0,[0,5,1],"03")}catch(s){throw new j("malformed X.509 certificate ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(u)};if(e!==undefined){if(e.curve!==undefined){this.curveName=e.curve}}if(this.curveName===undefined){this.curveName=g}this.setNamedCurve(this.curveName);if(e!==undefined){if(e.prv!==undefined){this.setPrivateKeyHex(e.prv)}if(e.pub!==undefined){this.setPublicKeyHex(e.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(f){var j=ASN1HEX,i=j.getChildIdx,g=j.getV;j.checkStrictDER(f,0);if(f.substr(0,2)!="30"){throw new Error("signature is not a ASN.1 sequence")}var h=i(f,0);if(h.length!=2){throw new Error("signature shall have two elements")}var e=h[0];var d=h[1];if(f.substr(e,2)!="02"){throw new Error("1st item not ASN.1 integer")}if(f.substr(d,2)!="02"){throw new Error("2nd item not ASN.1 integer")}var c=g(f,e);var b=g(f,d);return{r:c,s:b}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(d){var e=KJUR.crypto.ECDSA.parseSigHexInHexRS(d);var b=e.r;var a=e.s;if(b.length>=130&&b.length<=134){if(b.length%2!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%2!=0){throw Error("unknown ECDSA sig s length error")}if(b.substr(0,2)=="00"){b=b.substr(2)}if(a.substr(0,2)=="00"){a=a.substr(2)}var c=Math.max(b.length,a.length);b=("000000"+b).slice(-c);a=("000000"+a).slice(-c);return b+a}if(b.substr(0,2)=="00"&&(b.length%32)==2){b=b.substr(2)}if(a.substr(0,2)=="00"&&(a.length%32)==2){a=a.substr(2)}if((b.length%32)==30){b="00"+b}if((a.length%32)==30){a="00"+a}if(b.length%32!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%32!=0){throw Error("unknown ECDSA sig s length error")}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if(a.length%4!=0){throw Error("unknown ECDSA concatinated r-s sig length error")}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(f,d){var c=KJUR.asn1;var b=new c.DERInteger({bigint:f});var a=new c.DERInteger({bigint:d});var e=new c.DERSequence({array:[b,a]});return e.getEncodedHex()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2b8104001f"){return"secp192k1"}if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040021"){return"secp224r1"}if(a==="2b81040022"){return"secp384r1"}if(a==="2b81040023"){return"secp521r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp224r1|NIST P-224|P-224|".indexOf(a)!==-1){return"secp224r1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}if("|secp521r1|NIST P-521|P-521|".indexOf(a)!==-1){return"secp521r1"}return null}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["keycharlen"]=Math.ceil(l/8)*2;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;v=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f0){var b=":"+n.join(":")+":";if(b.indexOf(":"+k+":")==-1){throw"algorithm '"+k+"' not accepted in the list"}}if(k!="none"&&B===null){throw"key shall be specified to verify."}if(typeof B=="string"&&B.indexOf("-----BEGIN ")!=-1){B=KEYUTIL.getKey(B)}if(z=="RS"||z=="PS"){if(!(B instanceof m)){throw"key shall be a RSAKey obj for RS* and PS* algs"}}if(z=="ES"){if(!(B instanceof p)){throw"key shall be a ECDSA obj for ES* algs"}}if(k=="none"){}var u=null;if(t.jwsalg2sigalg[l.alg]===undefined){throw"unsupported alg name: "+k}else{u=t.jwsalg2sigalg[k]}if(u=="none"){throw"not supported"}else{if(u.substr(0,4)=="Hmac"){var o=null;if(B===undefined){throw"hexadecimal key shall be specified for HMAC"}var j=new s({alg:u,pass:B});j.updateString(c);o=j.doFinal();return A==o}else{if(u.indexOf("withECDSA")!=-1){var h=null;try{h=p.concatSigToASN1Sig(A)}catch(v){return false}var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(h)}else{var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(A)}}}};KJUR.jws.JWS.parse=function(g){var c=g.split(".");var b={};var f,e,d;if(c.length!=2&&c.length!=3){throw"malformed sJWS: wrong number of '.' splitted elements"}f=c[0];e=c[1];if(c.length==3){d=c[2]}b.headerObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(f));b.payloadObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(e));b.headerPP=JSON.stringify(b.headerObj,null," ");if(b.payloadObj==null){b.payloadPP=b64utoutf8(e)}else{b.payloadPP=JSON.stringify(b.payloadObj,null," ")}if(d!==undefined){b.sigHex=b64utohex(d)}return b};KJUR.jws.JWS.verifyJWT=function(e,l,r){var d=KJUR,j=d.jws,o=j.JWS,n=o.readSafeJSONString,p=o.inArray,f=o.includedArray;var k=e.split(".");var c=k[0];var i=k[1];var q=c+"."+i;var m=b64utohex(k[2]);var h=n(b64utoutf8(c));var g=n(b64utoutf8(i));if(h.alg===undefined){return false}if(r.alg===undefined){throw"acceptField.alg shall be specified"}if(!p(h.alg,r.alg)){return false}if(g.iss!==undefined&&typeof r.iss==="object"){if(!p(g.iss,r.iss)){return false}}if(g.sub!==undefined&&typeof r.sub==="object"){if(!p(g.sub,r.sub)){return false}}if(g.aud!==undefined&&typeof r.aud==="object"){if(typeof g.aud=="string"){if(!p(g.aud,r.aud)){return false}}else{if(typeof g.aud=="object"){if(!f(g.aud,r.aud)){return false}}}}var b=j.IntDate.getNow();if(r.verifyAt!==undefined&&typeof r.verifyAt==="number"){b=r.verifyAt}if(r.gracePeriod===undefined||typeof r.gracePeriod!=="number"){r.gracePeriod=0}if(g.exp!==undefined&&typeof g.exp=="number"){if(g.exp+r.gracePeriod=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashHex(rstrtohex(d),c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{throw"Invalid RSA private key"}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;this.isPublic=false;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{throw"Invalid RSA private key in RSASetPrivateEx"}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);if(this.n.bitLength()==b){this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){if(b.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){if(e.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw new Error("ASN.1 length too long to represent by 8x: n = "+j.toString(16))}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.getEncodedHex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:a}}}else{return{"enum":parseInt(a,16)}}}else{if(r=="30"||r=="31"){q[f[r]]=b(i);return q}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(r)!=-1){var p=hextoutf8(a);q[f[r]]={str:p};return q}else{if(r.match(/^8[0-9]$/)){return{tag:{tag:r,explicit:false,hex:a}}}else{if(r.match(/^a[0-9]$/)){return{tag:{tag:r,explicit:true,hex:a}}}else{var l=new KJUR.asn1.ASN1Object();l.hV=a;var j=l.getLengthHexFromValue();return{asn1:{tlv:r+j+a}}}}}}}}}}}}}};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){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 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.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}}; 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;q15){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||715){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:a}}}else{return{"enum":parseInt(a,16)}}}else{if(r=="30"||r=="31"){q[f[r]]=b(i);return q}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(r)!=-1){var p=hextoutf8(a);q[f[r]]={str:p};return q}else{if(r.match(/^8[0-9]$/)){return{tag:{tag:r,explicit:false,hex:a}}}else{if(r.match(/^a[0-9]$/)){return{tag:{tag:r,explicit:true,hex:a}}}else{var l=new KJUR.asn1.ASN1Object();l.hV=a;var j=l.getLengthHexFromValue();return{asn1:{tlv:r+j+a}}}}}}}}}}}}}};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;e=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){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; \ No newline at end of file +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; \ No newline at end of file diff --git a/npm/lib/jsrsasign-all-min.js b/npm/lib/jsrsasign-all-min.js index c6d3a69d..5c2d6874 100644 --- a/npm/lib/jsrsasign-all-min.js +++ b/npm/lib/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.5.3 (2022-02-10) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license + * jsrsasign(all) 10.5.4 (2022-02-15) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -217,15 +217,15 @@ ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBi /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ var jsonParse=(function(){var e="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)";var j='(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';var i='(?:"'+j+'*")';var d=new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|"+e+"|"+i+")","g");var k=new RegExp("\\\\(?:([^u])|u(.{4}))","g");var g={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function h(l,m,n){return m?g[m]:String.fromCharCode(parseInt(n,16))}var c=new String("");var a="\\";var f={"{":Object,"[":Array};var b=Object.hasOwnProperty;return function(u,q){var p=u.match(d);var x;var v=p[0];var l=false;if("{"===v){x={}}else{if("["===v){x=[]}else{x=[];l=true}}var t;var r=[x];for(var o=1-l,m=p.length;o=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -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:a}}}else{return{"enum":parseInt(a,16)}}}else{if(r=="30"||r=="31"){q[f[r]]=b(i);return q}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(r)!=-1){var p=hextoutf8(a);q[f[r]]={str:p};return q}else{if(r.match(/^8[0-9]$/)){return{tag:{tag:r,explicit:false,hex:a}}}else{if(r.match(/^a[0-9]$/)){return{tag:{tag:r,explicit:true,hex:a}}}else{var l=new KJUR.asn1.ASN1Object();l.hV=a;var j=l.getLengthHexFromValue();return{asn1:{tlv:r+j+a}}}}}}}}}}}}}};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;e15){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;e0){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extensions=function(d){KJUR.asn1.x509.Extensions.superclass.constructor.call(this);var c=KJUR,b=c.asn1,a=b.DERSequence,e=b.x509;this.aParam=[];this.setByParam=function(f){this.aParam=f};this.getEncodedHex=function(){var f=[];for(var h=0;h-1){i.push(new f({"int":this.pathLen}))}var h=new b({array:i});this.asn1ExtnValue=h;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(g!==undefined){if(g.cA!==undefined){this.cA=g.cA}if(g.pathLen!==undefined){this.pathLen=g.pathLen}}};extendClass(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(d){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,d);var b=KJUR,a=b.asn1,c=a.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(e){var f=[];for(var g=0;g0){f.push(new b({array:j}))}}var g=new b({array:f});return g.getEncodedHex()};if(d!==undefined){this.params=d}};extendClass(KJUR.asn1.x509.PolicyInformation,KJUR.asn1.ASN1Object);KJUR.asn1.x509.PolicyQualifierInfo=function(e){KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this,e);var c=KJUR.asn1,b=c.DERSequence,d=c.DERIA5String,f=c.DERObjectIdentifier,a=c.x509.UserNotice;this.params=null;this.getEncodedHex=function(){if(this.params.cps!==undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.1"}),new d({str:this.params.cps})]});return g.getEncodedHex()}if(this.params.unotice!=undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.2"}),new a(this.params.unotice)]});return g.getEncodedHex()}};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.PolicyQualifierInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.UserNotice=function(e){KJUR.asn1.x509.UserNotice.superclass.constructor.call(this,e);var a=KJUR.asn1.DERSequence,d=KJUR.asn1.DERInteger,c=KJUR.asn1.x509.DisplayText,b=KJUR.asn1.x509.NoticeReference;this.params=null;this.getEncodedHex=function(){var f=[];if(this.params.noticeref!==undefined){f.push(new b(this.params.noticeref))}if(this.params.exptext!==undefined){f.push(new c(this.params.exptext))}var g=new a({array:f});return g.getEncodedHex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.UserNotice,KJUR.asn1.ASN1Object);KJUR.asn1.x509.NoticeReference=function(d){KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this,d);var a=KJUR.asn1.DERSequence,c=KJUR.asn1.DERInteger,b=KJUR.asn1.x509.DisplayText;this.params=null;this.getEncodedHex=function(){var f=[];if(this.params.org!==undefined){f.push(new b(this.params.org))}if(this.params.noticenum!==undefined){var h=[];var e=this.params.noticenum;for(var j=0;j0){for(var g=0;g0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.X500Name.ldapToOneline=function(a){return KJUR.asn1.x509.X500Name.ldapToCompat(a)};KJUR.asn1.x509.RDN=function(b){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=[];this.paramArray=[];this.sRule="utf8";var a=KJUR.asn1.x509.AttributeTypeAndValue;this.setByParam=function(c){if(c.rule!==undefined){this.sRule=c.rule}if(c.str!==undefined){this.addByMultiValuedString(c.str)}if(c.array!==undefined){this.paramArray=c.array}};this.addByString=function(c){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:c,rule:this.sRule}))};this.addByMultiValuedString=function(e){var c=KJUR.asn1.x509.RDN.parseString(e);for(var d=0;d0){for(var d=0;d0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(c){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);this.sRule="utf8";this.sType=null;this.sValue=null;this.dsType=null;var a=KJUR,g=a.asn1,d=g.DERSequence,l=g.DERUTF8String,i=g.DERPrintableString,h=g.DERTeletexString,b=g.DERIA5String,e=g.DERVisibleString,k=g.DERBMPString,f=a.lang.String.isMail,j=a.lang.String.isPrintable;this.setByParam=function(o){if(o.rule!==undefined){this.sRule=o.rule}if(o.ds!==undefined){this.dsType=o.ds}if(o.value===undefined&&o.str!==undefined){var n=o.str;var m=n.match(/^([^=]+)=(.+)$/);if(m){this.sType=m[1];this.sValue=m[2]}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}}else{this.sType=o.type;this.sValue=o.value}};this.setByString=function(n,o){if(o!==undefined){this.sRule=o}var m=n.match(/^([^=]+)=(.+)$/);if(m){this.setByAttrTypeAndValueStr(m[1],m[2])}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}};this._getDsType=function(){var o=this.sType;var n=this.sValue;var m=this.sRule;if(m==="prn"){if(o=="CN"&&f(n)){return"ia5"}if(j(n)){return"prn"}return"utf8"}else{if(m==="utf8"){if(o=="CN"&&f(n)){return"ia5"}if(o=="C"){return"prn"}return"utf8"}}return"utf8"};this.setByAttrTypeAndValueStr=function(o,n,m){if(m!==undefined){this.sRule=m}this.sType=o;this.sValue=n};this.getValueObj=function(n,m){if(n=="utf8"){return new l({str:m})}if(n=="prn"){return new i({str:m})}if(n=="tel"){return new h({str:m})}if(n=="ia5"){return new b({str:m})}if(n=="vis"){return new e({str:m})}if(n=="bmp"){return new k({str:m})}throw new Error("unsupported directory string type: type="+n+" value="+m)};this.getEncodedHex=function(){if(this.dsType==null){this.dsType=this._getDsType()}var n=KJUR.asn1.x509.OID.atype2obj(this.sType);var m=this.getValueObj(this.dsType,this.sValue);var p=new d({array:[n,m]});this.TLV=p.getEncodedHex();return this.TLV};if(c!==undefined){this.setByParam(c)}};extendClass(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(f){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var l=null,k=null,a=KJUR,j=a.asn1,i=j.DERInteger,b=j.DERBitString,m=j.DERObjectIdentifier,e=j.DERSequence,h=j.ASN1Util.newObject,d=j.x509,o=d.AlgorithmIdentifier,g=a.crypto,n=g.ECDSA,c=g.DSA;this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var p=new e({array:[this.asn1AlgId,this.asn1SubjPKey]});return p};this.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();this.asn1AlgId=new o({name:"rsaEncryption"});this.asn1SubjPKey=new b({hex:"00"+s})}}catch(p){}try{if(q instanceof KJUR.crypto.ECDSA){var r=new m({name:q.curveName});this.asn1AlgId=new o({name:"ecPublicKey",asn1params:r});this.asn1SubjPKey=new b({hex:"00"+q.pubKeyHex})}}catch(p){}try{if(q instanceof KJUR.crypto.DSA){var r=new h({seq:[{"int":{bigint:q.p}},{"int":{bigint:q.q}},{"int":{bigint:q.g}}]});this.asn1AlgId=new o({name:"dsa",asn1params:r});var t=new i({bigint:q.y});this.asn1SubjPKey=new b({hex:"00"+t.getEncodedHex()})}}catch(p){}};if(f!==undefined){this.setPubKey(f)}};extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(f){KJUR.asn1.x509.Time.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.params=null;this.type=null;this.setTimeParams=function(h){this.timeParams=h};this.setByParam=function(h){this.params=h};this.getType=function(h){if(h.match(/^[0-9]{12}Z$/)){return"utc"}if(h.match(/^[0-9]{14}Z$/)){return"gen"}if(h.match(/^[0-9]{12}\.[0-9]+Z$/)){return"utc"}if(h.match(/^[0-9]{14}\.[0-9]+Z$/)){return"gen"}return null};this.getEncodedHex=function(){var i=this.params;var h=null;if(typeof i=="string"){i={str:i}}if(i!=null&&i.str&&(i.type==null||i.type==undefined)){i.type=this.getType(i.str)}if(i!=null&&i.str){if(i.type=="utc"){h=new b(i.str)}if(i.type=="gen"){h=new g(i.str)}}else{if(this.type=="gen"){h=new g()}else{h=new b()}}if(h==null){throw new Error("wrong setting for Time")}this.TLV=h.getEncodedHex();return this.TLV};if(f!=undefined){this.setByParam(f)}};KJUR.asn1.x509.Time_bak=function(f){KJUR.asn1.x509.Time_bak.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.setTimeParams=function(h){this.timeParams=h};this.getEncodedHex=function(){var h=null;if(this.timeParams!=null){if(this.type=="utc"){h=new b(this.timeParams)}else{h=new g(this.timeParams)}}else{if(this.type=="utc"){h=new b()}else{h=new g()}}this.TLV=h.getEncodedHex();return this.TLV};this.type="utc";if(f!==undefined){if(f.type!==undefined){this.type=f.type}else{if(f.str!==undefined){if(f.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(f.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=f}};extendClass(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);this.nameAlg=null;this.asn1Alg=null;this.asn1Params=null;this.paramEmpty=false;var b=KJUR,a=b.asn1,c=a.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV;this.getEncodedHex=function(){if(this.nameAlg===null&&this.asn1Alg===null){throw new Error("algorithm not specified")}if(this.nameAlg!==null){var f=null;for(var h in c){if(h===this.nameAlg){f=c[h]}}if(f!==null){this.hTLV=f;return this.hTLV}}if(this.nameAlg!==null&&this.asn1Alg===null){this.asn1Alg=a.x509.OID.name2obj(this.nameAlg)}var g=[this.asn1Alg];if(this.asn1Params!==null){g.push(this.asn1Params)}var i=new a.DERSequence({array:g});this.hTLV=i.getEncodedHex();return this.hTLV};if(e!==undefined){if(e.name!==undefined){this.nameAlg=e.name}if(e.asn1params!==undefined){this.asn1Params=e.asn1params}if(e.paramempty!==undefined){this.paramEmpty=e.paramempty}}if(this.asn1Params===null&&this.paramEmpty===false&&this.nameAlg!==null){if(this.nameAlg.name!==undefined){this.nameAlg=this.nameAlg.name}var d=this.nameAlg.toLowerCase();if(d.substr(-7,7)!=="withdsa"&&d.substr(-9,9)!=="withecdsa"){this.asn1Params=new a.DERNull()}}};extendClass(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV={SHAwithRSAandMGF1:"300d06092a864886f70d01010a3000",SHA256withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",SHA384withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",SHA512withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140"};KJUR.asn1.x509.GeneralName=function(f){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var l={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},b=KJUR,h=b.asn1,d=h.x509,a=d.X500Name,g=d.OtherName,e=h.DERIA5String,i=h.DERPrintableString,k=h.DEROctetString,c=h.DERTaggedObject,m=h.ASN1Object,j=Error;this.params=null;this.setByParam=function(n){this.params=n};this.getEncodedHex=function(){var p=this.params;var z,w,q;var w=false;if(p.other!==undefined){z="a0",q=new g(p.other)}else{if(p.rfc822!==undefined){z="81";q=new e({str:p.rfc822})}else{if(p.dns!==undefined){z="82";q=new e({str:p.dns})}else{if(p.dn!==undefined){z="a4";w=true;if(typeof p.dn==="string"){q=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){q=p.dn}else{q=new a(p.dn)}}}else{if(p.ldapdn!==undefined){z="a4";w=true;q=new a({ldapstr:p.ldapdn})}else{if(p.certissuer!==undefined||p.certsubj!==undefined){z="a4";w=true;var n,o;var y=null;if(p.certsubj!==undefined){n=false;o=p.certsubj}else{n=true;o=p.certissuer}if(o.match(/^[0-9A-Fa-f]+$/)){y==o}if(o.indexOf("-----BEGIN ")!=-1){y=pemtohex(o)}if(y==null){throw new Error("certsubj/certissuer not cert")}var v=new X509();v.hex=y;var s;if(n){s=v.getIssuerHex()}else{s=v.getSubjectHex()}q=new m();q.hTLV=s}else{if(p.uri!==undefined){z="86";q=new e({str:p.uri})}else{if(p.ip!==undefined){z="87";var t=p.ip;var u;var r="malformed IP address";if(t.match(/^[0-9.]+[.][0-9.]+$/)){u=intarystrtohex("["+t.split(".").join(",")+"]");if(u.length!==8){throw new j(r)}}else{if(t.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){u=ipv6tohex(t)}else{if(t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){u=t}else{throw new j(r)}}}q=new k({hex:u})}else{throw new j("improper params")}}}}}}}}var A=new c({tag:z,explicit:w,obj:q});return A.getEncodedHex()};if(f!==undefined){this.setByParam(f)}};KJUR.asn1.x509.GeneralName_bak=function(o){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var n=null,b=null,r={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},q=KJUR,e=q.asn1,a=_KJURd_asn1.x509,l=e.DERObjectIdentifier,d=e.DERSequence,c=e.DEROctetString,m=e.DERPrintableString,g=e.DERIA5String,i=e.DERTaggedObject,j=e.ASN1Object,k=a.X500Name,h=a.OtherName,f=e.ASN1Util.newObject,p=pemtohex;this.explicit=false;this.setByParam=function(w){var A=null;var E=null;if(w===undefined){return}if(w.rfc822!==undefined){this.type="rfc822";E=new g({str:w[this.type]})}if(w.other!==undefined){this.type="otherName";var D=new l({oid:w[this.type].oid});var y=f(w[this.type].obj);var t=new Array();t.push(D);t.push(y);E=new d({array:t})}if(w.dns!==undefined){this.type="dns";E=new g({str:w[this.type]})}if(w.uri!==undefined){this.type="uri";E=new g({str:w[this.type]})}if(w.dn!==undefined){this.type="dn";this.explicit=true;if(typeof w.dn==="string"){E=new k({str:w.dn})}else{if(w.dn instanceof KJUR.asn1.x509.X500Name){E=w.dn}else{E=new k(w.dn)}}}if(w.ldapdn!==undefined){this.type="dn";this.explicit=true;E=new k({ldapstr:w.ldapdn})}if(w.certissuer!==undefined){this.type="dn";this.explicit=true;var u=w.certissuer;var F=null;if(u.match(/^[0-9A-Fa-f]+$/)){F==u}if(u.indexOf("-----BEGIN ")!=-1){F=p(u)}if(F==null){throw"certissuer param not cert"}var C=new X509();C.hex=F;var G=C.getIssuerHex();E=new j();E.hTLV=G}if(w.certsubj!==undefined){this.type="dn";this.explicit=true;var u=w.certsubj;var F=null;if(u.match(/^[0-9A-Fa-f]+$/)){F==u}if(u.indexOf("-----BEGIN ")!=-1){F=p(u)}if(F==null){throw"certsubj param not cert"}var C=new X509();C.hex=F;var G=C.getSubjectHex();E=new j();E.hTLV=G}if(w.ip!==undefined){this.type="ip";this.explicit=false;var z=w.ip;var B;var s="malformed IP address";if(z.match(/^[0-9.]+[.][0-9.]+$/)){B=intarystrtohex("["+z.split(".").join(",")+"]");if(B.length!==8){throw s}}else{if(z.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){B=ipv6tohex(z)}else{if(z.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){B=z}else{throw s}}}E=new c({hex:B})}if(this.type==null){throw"unsupported type in params="+w}this.asn1Obj=new i({explicit:this.explicit,tag:r[this.type],obj:E})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(o!==undefined){this.setByParam(o)}};extendClass(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(d){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null,c=KJUR,b=c.asn1;this.setByParamArray=function(g){for(var e=0;e0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;mf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--u){v=v.twice2D();v.z=f.ONE;if(t.testBit(u)){if(s.testBit(u)){v=v.add2D(y)}else{v=v.add2D(x)}}else{if(s.testBit(u)){v=v.add2D(w)}}}return v}this.getBigRandom=function(r){return new f(r.bitLength(),a).mod(r.subtract(f.ONE)).add(f.ONE)};this.setNamedCurve=function(r){this.ecparams=c.getByName(r);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=r};this.setPrivateKeyHex=function(r){this.isPrivate=true;this.prvKeyHex=r};this.setPublicKeyHex=function(r){this.isPublic=true;this.pubKeyHex=r};this.getPublicKeyXYHex=function(){var t=this.pubKeyHex;if(t.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var s=this.ecparams.keycharlen;if(t.length!==2+s*2){throw"malformed public key hex length"}var r={};r.x=t.substr(2,s);r.y=t.substr(2+s);return r};this.getShortNISTPCurveName=function(){var r=this.curveName;if(r==="secp256r1"||r==="NIST P-256"||r==="P-256"||r==="prime256v1"){return"P-256"}if(r==="secp384r1"||r==="NIST P-384"||r==="P-384"){return"P-384"}if(r==="secp521r1"||r==="NIST P-521"||r==="P-521"){return"P-521"}return null};this.generateKeyPairHex=function(){var s=this.ecparams.n;var u=this.getBigRandom(s);var r=this.ecparams.keycharlen;var t=("0000000000"+u.toString(16)).slice(-r);this.setPrivateKeyHex(t);var v=this.generatePublicKeyHex();return{ecprvhex:t,ecpubhex:v}};this.generatePublicKeyHex=function(){var u=new f(this.prvKeyHex,16);var w=this.ecparams.G.multiply(u);var t=w.getX().toBigInteger();var s=w.getY().toBigInteger();var r=this.ecparams.keycharlen;var y=("0000000000"+t.toString(16)).slice(-r);var v=("0000000000"+s.toString(16)).slice(-r);var x="04"+y+v;this.setPublicKeyHex(x);return x};this.signWithMessageHash=function(r){return this.signHex(r,this.prvKeyHex)};this.signHex=function(x,u){var A=new f(u,16);var v=this.ecparams.n;var z=new f(x.substring(0,this.ecparams.keycharlen),16);do{var w=this.getBigRandom(v);var B=this.ecparams.G;var y=B.multiply(w);var t=y.getX().toBigInteger().mod(v)}while(t.compareTo(f.ZERO)<=0);var C=w.modInverse(v).multiply(z.add(A.multiply(t))).mod(v);return m.biRSSigToASN1Sig(t,C)};this.sign=function(w,B){var z=B;var u=this.ecparams.n;var y=f.fromByteArrayUnsigned(w);do{var v=this.getBigRandom(u);var A=this.ecparams.G;var x=A.multiply(v);var t=x.getX().toBigInteger().mod(u)}while(t.compareTo(BigInteger.ZERO)<=0);var C=v.modInverse(u).multiply(y.add(z.multiply(t))).mod(u);return this.serializeSig(t,C)};this.verifyWithMessageHash=function(s,r){return this.verifyHex(s,r,this.pubKeyHex)};this.verifyHex=function(v,y,u){try{var t,B;var w=m.parseSigHex(y);t=w.r;B=w.s;var x=h.decodeFromHex(this.ecparams.curve,u);var z=new f(v.substring(0,this.ecparams.keycharlen),16);return this.verifyRaw(z,t,B,x)}catch(A){return false}};this.verify=function(z,A,u){var w,t;if(Bitcoin.Util.isArray(A)){var y=this.parseSig(A);w=y.r;t=y.s}else{if("object"===typeof A&&A.r&&A.s){w=A.r;t=A.s}else{throw"Invalid value for signature"}}var v;if(u instanceof ECPointFp){v=u}else{if(Bitcoin.Util.isArray(u)){v=h.decodeFrom(this.ecparams.curve,u)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var x=f.fromByteArrayUnsigned(z);return this.verifyRaw(x,w,t,v)};this.verifyRaw=function(z,t,E,y){var x=this.ecparams.n;var D=this.ecparams.G;if(t.compareTo(f.ONE)<0||t.compareTo(x)>=0){return false}if(E.compareTo(f.ONE)<0||E.compareTo(x)>=0){return false}var A=E.modInverse(x);var w=z.multiply(A).mod(x);var u=t.multiply(A).mod(x);var B=D.multiply(w).add(y.multiply(u));var C=B.getX().toBigInteger().mod(x);return C.equals(t)};this.serializeSig=function(v,u){var w=v.toByteArraySigned();var t=u.toByteArraySigned();var x=[];x.push(2);x.push(w.length);x=x.concat(w);x.push(2);x.push(t.length);x=x.concat(t);x.unshift(x.length);x.unshift(48);return x};this.parseSig=function(y){var x;if(y[0]!=48){throw new Error("Signature not a valid DERSequence")}x=2;if(y[x]!=2){throw new Error("First element in signature must be a DERInteger")}var w=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];if(y[x]!=2){throw new Error("Second element in signature must be a DERInteger")}var t=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];var v=f.fromByteArrayUnsigned(w);var u=f.fromByteArrayUnsigned(t);return{r:v,s:u}};this.parseSigCompact=function(w){if(w.length!==65){throw"Signature has the wrong length"}var t=w[0]-27;if(t<0||t>7){throw"Invalid signature type"}var x=this.ecparams.n;var v=f.fromByteArrayUnsigned(w.slice(1,33)).mod(x);var u=f.fromByteArrayUnsigned(w.slice(33,65)).mod(x);return{r:v,s:u,i:t}};this.readPKCS5PrvKeyHex=function(u){if(k(u)===false){throw new Error("not ASN.1 hex string")}var r,t,v;try{r=n(u,0,["[0]",0],"06");t=n(u,0,[1],"04");try{v=n(u,0,["[1]",0],"03")}catch(s){}}catch(s){throw new Error("malformed PKCS#1/5 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v);this.setPrivateKeyHex(t);this.isPublic=false};this.readPKCS8PrvKeyHex=function(v){if(k(v)===false){throw new j("not ASN.1 hex string")}var t,r,u,w;try{t=n(v,0,[1,0],"06");r=n(v,0,[1,1],"06");u=n(v,0,[2,0,1],"04");try{w=n(v,0,[2,0,"[1]",0],"03")}catch(s){}}catch(s){throw new j("malformed PKCS#8 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(w);this.setPrivateKeyHex(u);this.isPublic=false};this.readPKCS8PubKeyHex=function(u){if(k(u)===false){throw new j("not ASN.1 hex string")}var t,r,v;try{t=n(u,0,[0,0],"06");r=n(u,0,[0,1],"06");v=n(u,0,[1],"03")}catch(s){throw new j("malformed PKCS#8 ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v)};this.readCertPubKeyHex=function(t,v){if(k(t)===false){throw new j("not ASN.1 hex string")}var r,u;try{r=n(t,0,[0,5,0,1],"06");u=n(t,0,[0,5,1],"03")}catch(s){throw new j("malformed X.509 certificate ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(u)};if(e!==undefined){if(e.curve!==undefined){this.curveName=e.curve}}if(this.curveName===undefined){this.curveName=g}this.setNamedCurve(this.curveName);if(e!==undefined){if(e.prv!==undefined){this.setPrivateKeyHex(e.prv)}if(e.pub!==undefined){this.setPublicKeyHex(e.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(f){var j=ASN1HEX,i=j.getChildIdx,g=j.getV;j.checkStrictDER(f,0);if(f.substr(0,2)!="30"){throw new Error("signature is not a ASN.1 sequence")}var h=i(f,0);if(h.length!=2){throw new Error("signature shall have two elements")}var e=h[0];var d=h[1];if(f.substr(e,2)!="02"){throw new Error("1st item not ASN.1 integer")}if(f.substr(d,2)!="02"){throw new Error("2nd item not ASN.1 integer")}var c=g(f,e);var b=g(f,d);return{r:c,s:b}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(d){var e=KJUR.crypto.ECDSA.parseSigHexInHexRS(d);var b=e.r;var a=e.s;if(b.length>=130&&b.length<=134){if(b.length%2!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%2!=0){throw Error("unknown ECDSA sig s length error")}if(b.substr(0,2)=="00"){b=b.substr(2)}if(a.substr(0,2)=="00"){a=a.substr(2)}var c=Math.max(b.length,a.length);b=("000000"+b).slice(-c);a=("000000"+a).slice(-c);return b+a}if(b.substr(0,2)=="00"&&(b.length%32)==2){b=b.substr(2)}if(a.substr(0,2)=="00"&&(a.length%32)==2){a=a.substr(2)}if((b.length%32)==30){b="00"+b}if((a.length%32)==30){a="00"+a}if(b.length%32!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%32!=0){throw Error("unknown ECDSA sig s length error")}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if(a.length%4!=0){throw Error("unknown ECDSA concatinated r-s sig length error")}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(f,d){var c=KJUR.asn1;var b=new c.DERInteger({bigint:f});var a=new c.DERInteger({bigint:d});var e=new c.DERSequence({array:[b,a]});return e.getEncodedHex()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2b8104001f"){return"secp192k1"}if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040021"){return"secp224r1"}if(a==="2b81040022"){return"secp384r1"}if(a==="2b81040023"){return"secp521r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp224r1|NIST P-224|P-224|".indexOf(a)!==-1){return"secp224r1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}if("|secp521r1|NIST P-521|P-521|".indexOf(a)!==-1){return"secp521r1"}return null}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["keycharlen"]=Math.ceil(l/8)*2;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;v=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f0){var b=":"+n.join(":")+":";if(b.indexOf(":"+k+":")==-1){throw"algorithm '"+k+"' not accepted in the list"}}if(k!="none"&&B===null){throw"key shall be specified to verify."}if(typeof B=="string"&&B.indexOf("-----BEGIN ")!=-1){B=KEYUTIL.getKey(B)}if(z=="RS"||z=="PS"){if(!(B instanceof m)){throw"key shall be a RSAKey obj for RS* and PS* algs"}}if(z=="ES"){if(!(B instanceof p)){throw"key shall be a ECDSA obj for ES* algs"}}if(k=="none"){}var u=null;if(t.jwsalg2sigalg[l.alg]===undefined){throw"unsupported alg name: "+k}else{u=t.jwsalg2sigalg[k]}if(u=="none"){throw"not supported"}else{if(u.substr(0,4)=="Hmac"){var o=null;if(B===undefined){throw"hexadecimal key shall be specified for HMAC"}var j=new s({alg:u,pass:B});j.updateString(c);o=j.doFinal();return A==o}else{if(u.indexOf("withECDSA")!=-1){var h=null;try{h=p.concatSigToASN1Sig(A)}catch(v){return false}var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(h)}else{var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(A)}}}};KJUR.jws.JWS.parse=function(g){var c=g.split(".");var b={};var f,e,d;if(c.length!=2&&c.length!=3){throw"malformed sJWS: wrong number of '.' splitted elements"}f=c[0];e=c[1];if(c.length==3){d=c[2]}b.headerObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(f));b.payloadObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(e));b.headerPP=JSON.stringify(b.headerObj,null," ");if(b.payloadObj==null){b.payloadPP=b64utoutf8(e)}else{b.payloadPP=JSON.stringify(b.payloadObj,null," ")}if(d!==undefined){b.sigHex=b64utohex(d)}return b};KJUR.jws.JWS.verifyJWT=function(e,l,r){var d=KJUR,j=d.jws,o=j.JWS,n=o.readSafeJSONString,p=o.inArray,f=o.includedArray;var k=e.split(".");var c=k[0];var i=k[1];var q=c+"."+i;var m=b64utohex(k[2]);var h=n(b64utoutf8(c));var g=n(b64utoutf8(i));if(h.alg===undefined){return false}if(r.alg===undefined){throw"acceptField.alg shall be specified"}if(!p(h.alg,r.alg)){return false}if(g.iss!==undefined&&typeof r.iss==="object"){if(!p(g.iss,r.iss)){return false}}if(g.sub!==undefined&&typeof r.sub==="object"){if(!p(g.sub,r.sub)){return false}}if(g.aud!==undefined&&typeof r.aud==="object"){if(typeof g.aud=="string"){if(!p(g.aud,r.aud)){return false}}else{if(typeof g.aud=="object"){if(!f(g.aud,r.aud)){return false}}}}var b=j.IntDate.getNow();if(r.verifyAt!==undefined&&typeof r.verifyAt==="number"){b=r.verifyAt}if(r.gracePeriod===undefined||typeof r.gracePeriod!=="number"){r.gracePeriod=0}if(g.exp!==undefined&&typeof g.exp=="number"){if(g.exp+r.gracePeriod=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashHex(rstrtohex(d),c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{throw"Invalid RSA private key"}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;this.isPublic=false;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{throw"Invalid RSA private key in RSASetPrivateEx"}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);if(this.n.bitLength()==b){this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){if(b.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){if(e.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw new Error("ASN.1 length too long to represent by 8x: n = "+j.toString(16))}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.getEncodedHex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:a}}}else{return{"enum":parseInt(a,16)}}}else{if(r=="30"||r=="31"){q[f[r]]=b(i);return q}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(r)!=-1){var p=hextoutf8(a);q[f[r]]={str:p};return q}else{if(r.match(/^8[0-9]$/)){return{tag:{tag:r,explicit:false,hex:a}}}else{if(r.match(/^a[0-9]$/)){return{tag:{tag:r,explicit:true,hex:a}}}else{var l=new KJUR.asn1.ASN1Object();l.hV=a;var j=l.getLengthHexFromValue();return{asn1:{tlv:r+j+a}}}}}}}}}}}}}};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){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 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.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}}; 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;q=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -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:a}}}else{return{"enum":parseInt(a,16)}}}else{if(r=="30"||r=="31"){q[f[r]]=b(i);return q}else{if(":0c:13:14:16:17:18:1a:1e:".indexOf(r)!=-1){var p=hextoutf8(a);q[f[r]]={str:p};return q}else{if(r.match(/^8[0-9]$/)){return{tag:{tag:r,explicit:false,hex:a}}}else{if(r.match(/^a[0-9]$/)){return{tag:{tag:r,explicit:true,hex:a}}}else{var l=new KJUR.asn1.ASN1Object();l.hV=a;var j=l.getLengthHexFromValue();return{asn1:{tlv:r+j+a}}}}}}}}}}}}}};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;e15){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;e0){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extensions=function(d){KJUR.asn1.x509.Extensions.superclass.constructor.call(this);var c=KJUR,b=c.asn1,a=b.DERSequence,e=b.x509;this.aParam=[];this.setByParam=function(f){this.aParam=f};this.getEncodedHex=function(){var f=[];for(var h=0;h-1){i.push(new f({"int":this.pathLen}))}var h=new b({array:i});this.asn1ExtnValue=h;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(g!==undefined){if(g.cA!==undefined){this.cA=g.cA}if(g.pathLen!==undefined){this.pathLen=g.pathLen}}};extendClass(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(d){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,d);var b=KJUR,a=b.asn1,c=a.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(e){var f=[];for(var g=0;g0){f.push(new b({array:j}))}}var g=new b({array:f});return g.getEncodedHex()};if(d!==undefined){this.params=d}};extendClass(KJUR.asn1.x509.PolicyInformation,KJUR.asn1.ASN1Object);KJUR.asn1.x509.PolicyQualifierInfo=function(e){KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this,e);var c=KJUR.asn1,b=c.DERSequence,d=c.DERIA5String,f=c.DERObjectIdentifier,a=c.x509.UserNotice;this.params=null;this.getEncodedHex=function(){if(this.params.cps!==undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.1"}),new d({str:this.params.cps})]});return g.getEncodedHex()}if(this.params.unotice!=undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.2"}),new a(this.params.unotice)]});return g.getEncodedHex()}};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.PolicyQualifierInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.UserNotice=function(e){KJUR.asn1.x509.UserNotice.superclass.constructor.call(this,e);var a=KJUR.asn1.DERSequence,d=KJUR.asn1.DERInteger,c=KJUR.asn1.x509.DisplayText,b=KJUR.asn1.x509.NoticeReference;this.params=null;this.getEncodedHex=function(){var f=[];if(this.params.noticeref!==undefined){f.push(new b(this.params.noticeref))}if(this.params.exptext!==undefined){f.push(new c(this.params.exptext))}var g=new a({array:f});return g.getEncodedHex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.UserNotice,KJUR.asn1.ASN1Object);KJUR.asn1.x509.NoticeReference=function(d){KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this,d);var a=KJUR.asn1.DERSequence,c=KJUR.asn1.DERInteger,b=KJUR.asn1.x509.DisplayText;this.params=null;this.getEncodedHex=function(){var f=[];if(this.params.org!==undefined){f.push(new b(this.params.org))}if(this.params.noticenum!==undefined){var h=[];var e=this.params.noticenum;for(var j=0;j0){for(var g=0;g0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.X500Name.ldapToOneline=function(a){return KJUR.asn1.x509.X500Name.ldapToCompat(a)};KJUR.asn1.x509.RDN=function(b){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=[];this.paramArray=[];this.sRule="utf8";var a=KJUR.asn1.x509.AttributeTypeAndValue;this.setByParam=function(c){if(c.rule!==undefined){this.sRule=c.rule}if(c.str!==undefined){this.addByMultiValuedString(c.str)}if(c.array!==undefined){this.paramArray=c.array}};this.addByString=function(c){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:c,rule:this.sRule}))};this.addByMultiValuedString=function(e){var c=KJUR.asn1.x509.RDN.parseString(e);for(var d=0;d0){for(var d=0;d0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(c){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);this.sRule="utf8";this.sType=null;this.sValue=null;this.dsType=null;var a=KJUR,g=a.asn1,d=g.DERSequence,l=g.DERUTF8String,i=g.DERPrintableString,h=g.DERTeletexString,b=g.DERIA5String,e=g.DERVisibleString,k=g.DERBMPString,f=a.lang.String.isMail,j=a.lang.String.isPrintable;this.setByParam=function(o){if(o.rule!==undefined){this.sRule=o.rule}if(o.ds!==undefined){this.dsType=o.ds}if(o.value===undefined&&o.str!==undefined){var n=o.str;var m=n.match(/^([^=]+)=(.+)$/);if(m){this.sType=m[1];this.sValue=m[2]}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}}else{this.sType=o.type;this.sValue=o.value}};this.setByString=function(n,o){if(o!==undefined){this.sRule=o}var m=n.match(/^([^=]+)=(.+)$/);if(m){this.setByAttrTypeAndValueStr(m[1],m[2])}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}};this._getDsType=function(){var o=this.sType;var n=this.sValue;var m=this.sRule;if(m==="prn"){if(o=="CN"&&f(n)){return"ia5"}if(j(n)){return"prn"}return"utf8"}else{if(m==="utf8"){if(o=="CN"&&f(n)){return"ia5"}if(o=="C"){return"prn"}return"utf8"}}return"utf8"};this.setByAttrTypeAndValueStr=function(o,n,m){if(m!==undefined){this.sRule=m}this.sType=o;this.sValue=n};this.getValueObj=function(n,m){if(n=="utf8"){return new l({str:m})}if(n=="prn"){return new i({str:m})}if(n=="tel"){return new h({str:m})}if(n=="ia5"){return new b({str:m})}if(n=="vis"){return new e({str:m})}if(n=="bmp"){return new k({str:m})}throw new Error("unsupported directory string type: type="+n+" value="+m)};this.getEncodedHex=function(){if(this.dsType==null){this.dsType=this._getDsType()}var n=KJUR.asn1.x509.OID.atype2obj(this.sType);var m=this.getValueObj(this.dsType,this.sValue);var p=new d({array:[n,m]});this.TLV=p.getEncodedHex();return this.TLV};if(c!==undefined){this.setByParam(c)}};extendClass(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(f){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var l=null,k=null,a=KJUR,j=a.asn1,i=j.DERInteger,b=j.DERBitString,m=j.DERObjectIdentifier,e=j.DERSequence,h=j.ASN1Util.newObject,d=j.x509,o=d.AlgorithmIdentifier,g=a.crypto,n=g.ECDSA,c=g.DSA;this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var p=new e({array:[this.asn1AlgId,this.asn1SubjPKey]});return p};this.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();this.asn1AlgId=new o({name:"rsaEncryption"});this.asn1SubjPKey=new b({hex:"00"+s})}}catch(p){}try{if(q instanceof KJUR.crypto.ECDSA){var r=new m({name:q.curveName});this.asn1AlgId=new o({name:"ecPublicKey",asn1params:r});this.asn1SubjPKey=new b({hex:"00"+q.pubKeyHex})}}catch(p){}try{if(q instanceof KJUR.crypto.DSA){var r=new h({seq:[{"int":{bigint:q.p}},{"int":{bigint:q.q}},{"int":{bigint:q.g}}]});this.asn1AlgId=new o({name:"dsa",asn1params:r});var t=new i({bigint:q.y});this.asn1SubjPKey=new b({hex:"00"+t.getEncodedHex()})}}catch(p){}};if(f!==undefined){this.setPubKey(f)}};extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(f){KJUR.asn1.x509.Time.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.params=null;this.type=null;this.setTimeParams=function(h){this.timeParams=h};this.setByParam=function(h){this.params=h};this.getType=function(h){if(h.match(/^[0-9]{12}Z$/)){return"utc"}if(h.match(/^[0-9]{14}Z$/)){return"gen"}if(h.match(/^[0-9]{12}\.[0-9]+Z$/)){return"utc"}if(h.match(/^[0-9]{14}\.[0-9]+Z$/)){return"gen"}return null};this.getEncodedHex=function(){var i=this.params;var h=null;if(typeof i=="string"){i={str:i}}if(i!=null&&i.str&&(i.type==null||i.type==undefined)){i.type=this.getType(i.str)}if(i!=null&&i.str){if(i.type=="utc"){h=new b(i.str)}if(i.type=="gen"){h=new g(i.str)}}else{if(this.type=="gen"){h=new g()}else{h=new b()}}if(h==null){throw new Error("wrong setting for Time")}this.TLV=h.getEncodedHex();return this.TLV};if(f!=undefined){this.setByParam(f)}};KJUR.asn1.x509.Time_bak=function(f){KJUR.asn1.x509.Time_bak.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.setTimeParams=function(h){this.timeParams=h};this.getEncodedHex=function(){var h=null;if(this.timeParams!=null){if(this.type=="utc"){h=new b(this.timeParams)}else{h=new g(this.timeParams)}}else{if(this.type=="utc"){h=new b()}else{h=new g()}}this.TLV=h.getEncodedHex();return this.TLV};this.type="utc";if(f!==undefined){if(f.type!==undefined){this.type=f.type}else{if(f.str!==undefined){if(f.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(f.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=f}};extendClass(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);this.nameAlg=null;this.asn1Alg=null;this.asn1Params=null;this.paramEmpty=false;var b=KJUR,a=b.asn1,c=a.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV;this.getEncodedHex=function(){if(this.nameAlg===null&&this.asn1Alg===null){throw new Error("algorithm not specified")}if(this.nameAlg!==null){var f=null;for(var h in c){if(h===this.nameAlg){f=c[h]}}if(f!==null){this.hTLV=f;return this.hTLV}}if(this.nameAlg!==null&&this.asn1Alg===null){this.asn1Alg=a.x509.OID.name2obj(this.nameAlg)}var g=[this.asn1Alg];if(this.asn1Params!==null){g.push(this.asn1Params)}var i=new a.DERSequence({array:g});this.hTLV=i.getEncodedHex();return this.hTLV};if(e!==undefined){if(e.name!==undefined){this.nameAlg=e.name}if(e.asn1params!==undefined){this.asn1Params=e.asn1params}if(e.paramempty!==undefined){this.paramEmpty=e.paramempty}}if(this.asn1Params===null&&this.paramEmpty===false&&this.nameAlg!==null){if(this.nameAlg.name!==undefined){this.nameAlg=this.nameAlg.name}var d=this.nameAlg.toLowerCase();if(d.substr(-7,7)!=="withdsa"&&d.substr(-9,9)!=="withecdsa"){this.asn1Params=new a.DERNull()}}};extendClass(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV={SHAwithRSAandMGF1:"300d06092a864886f70d01010a3000",SHA256withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",SHA384withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",SHA512withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140"};KJUR.asn1.x509.GeneralName=function(f){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var l={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},b=KJUR,h=b.asn1,d=h.x509,a=d.X500Name,g=d.OtherName,e=h.DERIA5String,i=h.DERPrintableString,k=h.DEROctetString,c=h.DERTaggedObject,m=h.ASN1Object,j=Error;this.params=null;this.setByParam=function(n){this.params=n};this.getEncodedHex=function(){var p=this.params;var z,w,q;var w=false;if(p.other!==undefined){z="a0",q=new g(p.other)}else{if(p.rfc822!==undefined){z="81";q=new e({str:p.rfc822})}else{if(p.dns!==undefined){z="82";q=new e({str:p.dns})}else{if(p.dn!==undefined){z="a4";w=true;if(typeof p.dn==="string"){q=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){q=p.dn}else{q=new a(p.dn)}}}else{if(p.ldapdn!==undefined){z="a4";w=true;q=new a({ldapstr:p.ldapdn})}else{if(p.certissuer!==undefined||p.certsubj!==undefined){z="a4";w=true;var n,o;var y=null;if(p.certsubj!==undefined){n=false;o=p.certsubj}else{n=true;o=p.certissuer}if(o.match(/^[0-9A-Fa-f]+$/)){y==o}if(o.indexOf("-----BEGIN ")!=-1){y=pemtohex(o)}if(y==null){throw new Error("certsubj/certissuer not cert")}var v=new X509();v.hex=y;var s;if(n){s=v.getIssuerHex()}else{s=v.getSubjectHex()}q=new m();q.hTLV=s}else{if(p.uri!==undefined){z="86";q=new e({str:p.uri})}else{if(p.ip!==undefined){z="87";var t=p.ip;var u;var r="malformed IP address";if(t.match(/^[0-9.]+[.][0-9.]+$/)){u=intarystrtohex("["+t.split(".").join(",")+"]");if(u.length!==8){throw new j(r)}}else{if(t.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){u=ipv6tohex(t)}else{if(t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){u=t}else{throw new j(r)}}}q=new k({hex:u})}else{throw new j("improper params")}}}}}}}}var A=new c({tag:z,explicit:w,obj:q});return A.getEncodedHex()};if(f!==undefined){this.setByParam(f)}};KJUR.asn1.x509.GeneralName_bak=function(o){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var n=null,b=null,r={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},q=KJUR,e=q.asn1,a=_KJURd_asn1.x509,l=e.DERObjectIdentifier,d=e.DERSequence,c=e.DEROctetString,m=e.DERPrintableString,g=e.DERIA5String,i=e.DERTaggedObject,j=e.ASN1Object,k=a.X500Name,h=a.OtherName,f=e.ASN1Util.newObject,p=pemtohex;this.explicit=false;this.setByParam=function(w){var A=null;var E=null;if(w===undefined){return}if(w.rfc822!==undefined){this.type="rfc822";E=new g({str:w[this.type]})}if(w.other!==undefined){this.type="otherName";var D=new l({oid:w[this.type].oid});var y=f(w[this.type].obj);var t=new Array();t.push(D);t.push(y);E=new d({array:t})}if(w.dns!==undefined){this.type="dns";E=new g({str:w[this.type]})}if(w.uri!==undefined){this.type="uri";E=new g({str:w[this.type]})}if(w.dn!==undefined){this.type="dn";this.explicit=true;if(typeof w.dn==="string"){E=new k({str:w.dn})}else{if(w.dn instanceof KJUR.asn1.x509.X500Name){E=w.dn}else{E=new k(w.dn)}}}if(w.ldapdn!==undefined){this.type="dn";this.explicit=true;E=new k({ldapstr:w.ldapdn})}if(w.certissuer!==undefined){this.type="dn";this.explicit=true;var u=w.certissuer;var F=null;if(u.match(/^[0-9A-Fa-f]+$/)){F==u}if(u.indexOf("-----BEGIN ")!=-1){F=p(u)}if(F==null){throw"certissuer param not cert"}var C=new X509();C.hex=F;var G=C.getIssuerHex();E=new j();E.hTLV=G}if(w.certsubj!==undefined){this.type="dn";this.explicit=true;var u=w.certsubj;var F=null;if(u.match(/^[0-9A-Fa-f]+$/)){F==u}if(u.indexOf("-----BEGIN ")!=-1){F=p(u)}if(F==null){throw"certsubj param not cert"}var C=new X509();C.hex=F;var G=C.getSubjectHex();E=new j();E.hTLV=G}if(w.ip!==undefined){this.type="ip";this.explicit=false;var z=w.ip;var B;var s="malformed IP address";if(z.match(/^[0-9.]+[.][0-9.]+$/)){B=intarystrtohex("["+z.split(".").join(",")+"]");if(B.length!==8){throw s}}else{if(z.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){B=ipv6tohex(z)}else{if(z.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){B=z}else{throw s}}}E=new c({hex:B})}if(this.type==null){throw"unsupported type in params="+w}this.asn1Obj=new i({explicit:this.explicit,tag:r[this.type],obj:E})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(o!==undefined){this.setByParam(o)}};extendClass(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(d){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null,c=KJUR,b=c.asn1;this.setByParamArray=function(g){for(var e=0;e0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;mf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){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 extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; +var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;cf.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(a){var b=bitstrtoint(a);if(b==-1){return null}return b.toString(2)}function binstrtobitstr(b){if(typeof b!="string"){return null}if(b.match(/^[01]+$/)==null){return null}try{var c=parseInt(b,2);return inttobitstr(c)}catch(a){return null}}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--u){v=v.twice2D();v.z=f.ONE;if(t.testBit(u)){if(s.testBit(u)){v=v.add2D(y)}else{v=v.add2D(x)}}else{if(s.testBit(u)){v=v.add2D(w)}}}return v}this.getBigRandom=function(r){return new f(r.bitLength(),a).mod(r.subtract(f.ONE)).add(f.ONE)};this.setNamedCurve=function(r){this.ecparams=c.getByName(r);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=r};this.setPrivateKeyHex=function(r){this.isPrivate=true;this.prvKeyHex=r};this.setPublicKeyHex=function(r){this.isPublic=true;this.pubKeyHex=r};this.getPublicKeyXYHex=function(){var t=this.pubKeyHex;if(t.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var s=this.ecparams.keycharlen;if(t.length!==2+s*2){throw"malformed public key hex length"}var r={};r.x=t.substr(2,s);r.y=t.substr(2+s);return r};this.getShortNISTPCurveName=function(){var r=this.curveName;if(r==="secp256r1"||r==="NIST P-256"||r==="P-256"||r==="prime256v1"){return"P-256"}if(r==="secp384r1"||r==="NIST P-384"||r==="P-384"){return"P-384"}if(r==="secp521r1"||r==="NIST P-521"||r==="P-521"){return"P-521"}return null};this.generateKeyPairHex=function(){var s=this.ecparams.n;var u=this.getBigRandom(s);var r=this.ecparams.keycharlen;var t=("0000000000"+u.toString(16)).slice(-r);this.setPrivateKeyHex(t);var v=this.generatePublicKeyHex();return{ecprvhex:t,ecpubhex:v}};this.generatePublicKeyHex=function(){var u=new f(this.prvKeyHex,16);var w=this.ecparams.G.multiply(u);var t=w.getX().toBigInteger();var s=w.getY().toBigInteger();var r=this.ecparams.keycharlen;var y=("0000000000"+t.toString(16)).slice(-r);var v=("0000000000"+s.toString(16)).slice(-r);var x="04"+y+v;this.setPublicKeyHex(x);return x};this.signWithMessageHash=function(r){return this.signHex(r,this.prvKeyHex)};this.signHex=function(x,u){var A=new f(u,16);var v=this.ecparams.n;var z=new f(x.substring(0,this.ecparams.keycharlen),16);do{var w=this.getBigRandom(v);var B=this.ecparams.G;var y=B.multiply(w);var t=y.getX().toBigInteger().mod(v)}while(t.compareTo(f.ZERO)<=0);var C=w.modInverse(v).multiply(z.add(A.multiply(t))).mod(v);return m.biRSSigToASN1Sig(t,C)};this.sign=function(w,B){var z=B;var u=this.ecparams.n;var y=f.fromByteArrayUnsigned(w);do{var v=this.getBigRandom(u);var A=this.ecparams.G;var x=A.multiply(v);var t=x.getX().toBigInteger().mod(u)}while(t.compareTo(BigInteger.ZERO)<=0);var C=v.modInverse(u).multiply(y.add(z.multiply(t))).mod(u);return this.serializeSig(t,C)};this.verifyWithMessageHash=function(s,r){return this.verifyHex(s,r,this.pubKeyHex)};this.verifyHex=function(v,y,u){try{var t,B;var w=m.parseSigHex(y);t=w.r;B=w.s;var x=h.decodeFromHex(this.ecparams.curve,u);var z=new f(v.substring(0,this.ecparams.keycharlen),16);return this.verifyRaw(z,t,B,x)}catch(A){return false}};this.verify=function(z,A,u){var w,t;if(Bitcoin.Util.isArray(A)){var y=this.parseSig(A);w=y.r;t=y.s}else{if("object"===typeof A&&A.r&&A.s){w=A.r;t=A.s}else{throw"Invalid value for signature"}}var v;if(u instanceof ECPointFp){v=u}else{if(Bitcoin.Util.isArray(u)){v=h.decodeFrom(this.ecparams.curve,u)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var x=f.fromByteArrayUnsigned(z);return this.verifyRaw(x,w,t,v)};this.verifyRaw=function(z,t,E,y){var x=this.ecparams.n;var D=this.ecparams.G;if(t.compareTo(f.ONE)<0||t.compareTo(x)>=0){return false}if(E.compareTo(f.ONE)<0||E.compareTo(x)>=0){return false}var A=E.modInverse(x);var w=z.multiply(A).mod(x);var u=t.multiply(A).mod(x);var B=D.multiply(w).add(y.multiply(u));var C=B.getX().toBigInteger().mod(x);return C.equals(t)};this.serializeSig=function(v,u){var w=v.toByteArraySigned();var t=u.toByteArraySigned();var x=[];x.push(2);x.push(w.length);x=x.concat(w);x.push(2);x.push(t.length);x=x.concat(t);x.unshift(x.length);x.unshift(48);return x};this.parseSig=function(y){var x;if(y[0]!=48){throw new Error("Signature not a valid DERSequence")}x=2;if(y[x]!=2){throw new Error("First element in signature must be a DERInteger")}var w=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];if(y[x]!=2){throw new Error("Second element in signature must be a DERInteger")}var t=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];var v=f.fromByteArrayUnsigned(w);var u=f.fromByteArrayUnsigned(t);return{r:v,s:u}};this.parseSigCompact=function(w){if(w.length!==65){throw"Signature has the wrong length"}var t=w[0]-27;if(t<0||t>7){throw"Invalid signature type"}var x=this.ecparams.n;var v=f.fromByteArrayUnsigned(w.slice(1,33)).mod(x);var u=f.fromByteArrayUnsigned(w.slice(33,65)).mod(x);return{r:v,s:u,i:t}};this.readPKCS5PrvKeyHex=function(u){if(k(u)===false){throw new Error("not ASN.1 hex string")}var r,t,v;try{r=n(u,0,["[0]",0],"06");t=n(u,0,[1],"04");try{v=n(u,0,["[1]",0],"03")}catch(s){}}catch(s){throw new Error("malformed PKCS#1/5 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v);this.setPrivateKeyHex(t);this.isPublic=false};this.readPKCS8PrvKeyHex=function(v){if(k(v)===false){throw new j("not ASN.1 hex string")}var t,r,u,w;try{t=n(v,0,[1,0],"06");r=n(v,0,[1,1],"06");u=n(v,0,[2,0,1],"04");try{w=n(v,0,[2,0,"[1]",0],"03")}catch(s){}}catch(s){throw new j("malformed PKCS#8 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(w);this.setPrivateKeyHex(u);this.isPublic=false};this.readPKCS8PubKeyHex=function(u){if(k(u)===false){throw new j("not ASN.1 hex string")}var t,r,v;try{t=n(u,0,[0,0],"06");r=n(u,0,[0,1],"06");v=n(u,0,[1],"03")}catch(s){throw new j("malformed PKCS#8 ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v)};this.readCertPubKeyHex=function(t,v){if(k(t)===false){throw new j("not ASN.1 hex string")}var r,u;try{r=n(t,0,[0,5,0,1],"06");u=n(t,0,[0,5,1],"03")}catch(s){throw new j("malformed X.509 certificate ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(u)};if(e!==undefined){if(e.curve!==undefined){this.curveName=e.curve}}if(this.curveName===undefined){this.curveName=g}this.setNamedCurve(this.curveName);if(e!==undefined){if(e.prv!==undefined){this.setPrivateKeyHex(e.prv)}if(e.pub!==undefined){this.setPublicKeyHex(e.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(f){var j=ASN1HEX,i=j.getChildIdx,g=j.getV;j.checkStrictDER(f,0);if(f.substr(0,2)!="30"){throw new Error("signature is not a ASN.1 sequence")}var h=i(f,0);if(h.length!=2){throw new Error("signature shall have two elements")}var e=h[0];var d=h[1];if(f.substr(e,2)!="02"){throw new Error("1st item not ASN.1 integer")}if(f.substr(d,2)!="02"){throw new Error("2nd item not ASN.1 integer")}var c=g(f,e);var b=g(f,d);return{r:c,s:b}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(d){var e=KJUR.crypto.ECDSA.parseSigHexInHexRS(d);var b=e.r;var a=e.s;if(b.length>=130&&b.length<=134){if(b.length%2!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%2!=0){throw Error("unknown ECDSA sig s length error")}if(b.substr(0,2)=="00"){b=b.substr(2)}if(a.substr(0,2)=="00"){a=a.substr(2)}var c=Math.max(b.length,a.length);b=("000000"+b).slice(-c);a=("000000"+a).slice(-c);return b+a}if(b.substr(0,2)=="00"&&(b.length%32)==2){b=b.substr(2)}if(a.substr(0,2)=="00"&&(a.length%32)==2){a=a.substr(2)}if((b.length%32)==30){b="00"+b}if((a.length%32)==30){a="00"+a}if(b.length%32!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%32!=0){throw Error("unknown ECDSA sig s length error")}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if(a.length%4!=0){throw Error("unknown ECDSA concatinated r-s sig length error")}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(f,d){var c=KJUR.asn1;var b=new c.DERInteger({bigint:f});var a=new c.DERInteger({bigint:d});var e=new c.DERSequence({array:[b,a]});return e.getEncodedHex()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2b8104001f"){return"secp192k1"}if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040021"){return"secp224r1"}if(a==="2b81040022"){return"secp384r1"}if(a==="2b81040023"){return"secp521r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp224r1|NIST P-224|P-224|".indexOf(a)!==-1){return"secp224r1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}if("|secp521r1|NIST P-521|P-521|".indexOf(a)!==-1){return"secp521r1"}return null}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["keycharlen"]=Math.ceil(l/8)*2;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;vMIT License */ @@ -1041,7 +1041,7 @@ KJUR.asn1.DERBitString = function(params) { * NOTE: Trailing zeros '0' will be ignored. * @example * o = new KJUR.asn1.DERBitString(); - * o.setByBooleanArray("01011"); + * o.setByBinaryString("01011"); */ this.setByBinaryString = function(binaryString) { binaryString = binaryString.replace(/0+$/, ''); @@ -1756,12 +1756,17 @@ extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured); KJUR.asn1.DERTaggedObject = function(params) { KJUR.asn1.DERTaggedObject.superclass.constructor.call(this); - var _KJUR_asn1 = KJUR.asn1; + var _KJUR_asn1 = KJUR.asn1, + _ASN1HEX = ASN1HEX, + _getV = _ASN1HEX.getV, + _isASN1HEX = _ASN1HEX.isASN1HEX, + _newObject = _KJUR_asn1.ASN1Util.newObject; this.hT = "a0"; this.hV = ''; this.isExplicit = true; this.asn1Object = null; + this.params = {tag: "a0", explicit: true}; //"tag": "a0, "explicit": true}; /** * set value by an ASN1Object @@ -1771,53 +1776,60 @@ KJUR.asn1.DERTaggedObject = function(params) { * @param {Boolean} isExplicitFlag flag for explicit/implicit tag * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag * @param {ASN1Object} asn1Object ASN.1 to encapsulate + * @deprecated since jsrsasign 10.5.4 please use setByParam instead */ this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) { - this.hT = tagNoHex; - this.isExplicit = isExplicitFlag; - this.asn1Object = asn1Object; - if (this.isExplicit) { - this.hV = this.asn1Object.getEncodedHex(); - this.hTLV = null; - this.isModified = true; - } else { - this.hV = null; - this.hTLV = asn1Object.getEncodedHex(); - this.hTLV = this.hTLV.replace(/^../, tagNoHex); - this.isModified = false; - } + this.params = {tag: tagNoHex, + explicit: isExplicitFlag, + obj: asn1Object}; }; this.getFreshValueHex = function() { - return this.hV; - }; + var params = this.params; + + if (params.explicit == undefined) params.explicit = true; - this.setByParam = function(params) { - if (params.tag != undefined) { - this.hT = params.tag; - } - if (params.explicit != undefined) { - this.isExplicit = params.explicit; - } if (params.tage != undefined) { - this.hT = params.tage; - this.isExplicit = true; + params.tag = params.tage; + params.explicit = true; } if (params.tagi != undefined) { - this.hT = params.tagi; - this.isExplicit = false; + params.tag = params.tagi; + params.explicit = false; } - if (params.obj != undefined) { + + if (params.str != undefined) { + this.hV = utf8tohex(params.str); + } else if (params.hex != undefined) { + this.hV = params.hex; + } else if (params.obj != undefined) { + var hV1; if (params.obj instanceof _KJUR_asn1.ASN1Object) { - this.asn1Object = params.obj; - this.setASN1Object(this.isExplicit, this.hT, this.asn1Object); + hV1 = params.obj.getEncodedHex(); } else if (typeof params.obj == "object") { - this.asn1Object = _KJUR_asn1.ASN1Util.newObject(params.obj); - this.setASN1Object(this.isExplicit, this.hT, this.asn1Object); + hV1 = _newObject(params.obj).getEncodedHex(); } - } + if (params.explicit) { + this.hV = hV1; + } else { + this.hV = _getV(hV1, 0); + } + } else { + throw new Error("str, hex nor obj not specified"); + } + + if (params.tag == undefined) params.tag = "a0"; + this.hT = params.tag; + this.hTLV = null; + this.isModified = true; + + return this.hV; }; - if (params != undefined) this.setByParam(params); + this.setByParam = function(params) { + this.params = params; + }; + + if (params !== undefined) this.setByParam(params); }; extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); diff --git a/src/asn1hex-1.1.js b/src/asn1hex-1.1.js index f062bc4a..94a44664 100644 --- a/src/asn1hex-1.1.js +++ b/src/asn1hex-1.1.js @@ -1,4 +1,4 @@ -/* asn1hex-1.2.10.js (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license +/* asn1hex-1.2.11.js (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license */ /* * asn1hex.js - Hexadecimal represented ASN.1 string library @@ -16,7 +16,7 @@ * @fileOverview * @name asn1hex-1.1.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version jsrsasign 10.5.3 asn1hex 1.2.10 (2022-Feb-10) + * @version jsrsasign 10.5.4 asn1hex 1.2.11 (2022-Feb-14) * @license MIT License */ @@ -1019,12 +1019,17 @@ ASN1HEX.dump = function(hexOrObj, flags, idx, indent) { * @example */ ASN1HEX.parse = function(h) { - var _ASN1HEX = ASN1HEX; - var _parse = _ASN1HEX.parse; - var _getV = _ASN1HEX.getV; - var _getTLV = _ASN1HEX.getTLV; - var _dump = _ASN1HEX.dump; - var _getChildIdx = _ASN1HEX.getChildIdx; + var _ASN1HEX = ASN1HEX, + _parse = _ASN1HEX.parse, + _isASN1HEX = _ASN1HEX.isASN1HEX, + _getV = _ASN1HEX.getV, + _getTLV = _ASN1HEX.getTLV, + _getChildIdx = _ASN1HEX.getChildIdx, + _KJUR_asn1 = KJUR.asn1, + _oidHexToInt = _KJUR_asn1.ASN1Util.oidHexToInt, + _oid2name = _KJUR_asn1.x509.OID.oid2name, + _hextoutf8 = hextoutf8; + var tagName = { "0c": "utf8str", "13": "prnstr", "14": "telstr", "16": "ia5str", "17": "utctime", "18": "gentime", @@ -1053,15 +1058,37 @@ ASN1HEX.parse = function(h) { } else if (tag == "02") { return {"int": {hex: hV}}; } else if (tag == "03") { - return {bitstr: {hex: hV}}; + try { + if (hV.substr(0, 2) != "00") throw "not encap"; + var hV1 = hV.substr(2); + if (! _isASN1HEX(hV1)) throw "not encap"; + return {bitstr: {obj: _parse(hV1)}}; + } catch(ex) { + var bV = null; + if (hV.length <= 6) bV = bitstrtobinstr(hV); + if (bV == null) { + return {bitstr: {hex: hV}}; + } else { + return {bitstr: {bin: bV}}; + } + } } else if (tag == "04") { - return {octstr: {hex: hV}}; + try { + if (! _isASN1HEX(hV)) throw "not encap"; + return {octstr: {obj: _parse(hV)}}; + } catch(ex) { + return {octstr: {hex: hV}}; + } } else if (tag == "05") { return {"null": ''}; } else if (tag == "06") { - var oidDot = KJUR.asn1.ASN1Util.oidHexToInt(hV); - var oidName = KJUR.asn1.x509.OID.oid2name(oidDot); - return {oid: oidName}; + var oidDot = _oidHexToInt(hV); + var oidName = _oid2name(oidDot); + if (oidName == "") { + return {oid: oidDot}; + } else { + return {oid: oidName}; + } } else if (tag == "0a") { if (hV.length > 4) { return {"enum": {hex: hV}}; @@ -1072,13 +1099,28 @@ ASN1HEX.parse = function(h) { result[tagName[tag]] = _parseChild(h); return result; } else if (":0c:13:14:16:17:18:1a:1e:".indexOf(tag) != -1) { - var s = hextoutf8(hV); + var s = _hextoutf8(hV); result[tagName[tag]] = {str: s}; return result; } else if (tag.match(/^8[0-9]$/)) { - return {"tag": {"tag": tag, explicit: false, hex: hV}}; + var s = _hextoutf8(hV); + if (s == null | + s == "" | + (s.match(/[\x00-\x1F\x7F-\x9F]/) != null) | + (s.match(/[\u0000-\u001F\u0080–\u009F]/) != null)) { + return {"tag": {"tag": tag, explicit: false, hex: hV}}; + } else { + return {"tag": {"tag": tag, explicit: false, str: s}}; + } } else if (tag.match(/^a[0-9]$/)) { - return {"tag": {"tag": tag, explicit: true, hex: hV}}; + try { + if (! _isASN1HEX(hV)) throw "not encap"; + return {"tag": {"tag": tag, + explicit: true, + obj: _parse(hV)}}; + } catch(ex) { + return {"tag": {"tag": tag, explicit: true, hex: hV}}; + } } else { var d = new KJUR.asn1.ASN1Object(); d.hV = hV; diff --git a/src/base64x-1.1.js b/src/base64x-1.1.js index 03da8832..148b5327 100644 --- a/src/base64x-1.1.js +++ b/src/base64x-1.1.js @@ -1,9 +1,9 @@ -/* base64x-1.1.20 (c) 2012-2021 Kenji Urushima | kjur.github.io/jsrsasign/license +/* base64x-1.1.21 (c) 2012-2022 Kenji Urushima | kjur.github.io/jsrsasign/license */ /* * base64x.js - Base64url and supplementary functions for Tom Wu's base64.js library * - * Copyright (c) 2012-2021 Kenji Urushima (kenji.urushima@gmail.com) + * Copyright (c) 2012-2022 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * https://kjur.github.io/jsrsasign/license @@ -16,7 +16,7 @@ * @fileOverview * @name base64x-1.1.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version jsrsasign 10.1.13 base64x 1.1.20 (2021-Mar-07) + * @version jsrsasign 10.5.4 base64x 1.1.21 (2022-Feb-14) * @since jsrsasign 2.1 * @license MIT License */ @@ -322,7 +322,7 @@ function b64toutf8(s) { * @since 1.1.1 */ function utf8tohex(s) { - return uricmptohex(encodeURIComponentAll(s)); + return uricmptohex(encodeURIComponentAll(s)).toLowerCase(); } /** @@ -336,7 +336,11 @@ function utf8tohex(s) { * @since 1.1.1 */ function hextoutf8(s) { - return decodeURIComponent(hextouricmp(s)); + try { + return decodeURIComponent(hextouricmp(s)); + } catch(ex) { + return null; + } } /** @@ -1467,7 +1471,9 @@ var strpad = function(s, len, padchar) { * * @description * This function converts from hexadecimal string of ASN.1 BitString - * value with unused bit to its integer value. + * value with unused bit to its integer value.
+ * When an improper hexadecimal string of BitString value + * is applied, this returns -1. * * @example * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25 @@ -1475,24 +1481,33 @@ var strpad = function(s, len, padchar) { * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02 * // 11111111111110b → 16382 * bitstrtoint("02fff8") → 16382 + * bitstrtoint("05a0") → 5 (=101b) + * bitstrtoint("ff00") → -1 // for improper BitString value + * bitstrtoint("05a0").toString(2) → "101" + * bitstrtoint("07a080").toString(2) → "101000001" */ function bitstrtoint(h) { + if (h.length % 2 != 0) return -1; + h = h.toLowerCase(); + if (h.match(/^[0-9a-f]+$/) == null) return -1; try { var hUnusedbit = h.substr(0, 2); if (hUnusedbit == "00") return parseInt(h.substr(2), 16); var iUnusedbit = parseInt(hUnusedbit, 16); + if (iUnusedbit > 7) return -1; var hValue = h.substr(2); var bValue = parseInt(hValue, 16).toString(2); if (bValue == "0") bValue = "00000000"; bValue = bValue.slice(0, 0 - iUnusedbit); - return parseInt(bValue, 2); + var iValue = parseInt(bValue, 2); + if (iValue == NaN) return -1; + return iValue; } catch(ex) { return -1; } }; - /** * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit
* @name inttobitstr @@ -1507,13 +1522,21 @@ function bitstrtoint(h) { * @description * This function converts from an integer value to * hexadecimal string of ASN.1 BitString value - * with unused bit. + * with unused bit.
+ * When "n" is not non-negative number, this returns null * * @example * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8" * inttobitstr(25) → "03c8" + * inttobitstr(-3) → null + * inttobitstr("abc") → null + * inttobitstr(parseInt("11001", 2)) → "03c8" + * inttobitstr(parseInt("101", 2)) → "05a0" + * inttobitstr(parseInt("101000001", 2)) → "07a080" */ function inttobitstr(n) { + if (typeof n != "number") return null; + if (n < 0) return null; var bValue = Number(n).toString(2); var iUnusedbit = 8 - bValue.length % 8; if (iUnusedbit == 8) iUnusedbit = 0; @@ -1524,6 +1547,72 @@ function inttobitstr(n) { return hUnusedbit + hValue; }; +// ==== bitstr hex / binary string ======================= + +/** + * convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string
+ * @name bitstrtobinstr + * @function + * @param {string} h hexadecimal string of ASN.1 BitString value with unused bit + * @return {string} binary string + * @since jsrsasign 10.5.4 base64x 1.1.21 + * @see binstrtobitstr + * @see inttobitstr + * + * @description + * This function converts from hexadecimal string of ASN.1 BitString + * value with unused bit to its integer value.
+ * When an improper hexadecimal string of BitString value + * is applied, this returns null. + * + * @example + * bitstrtobinstr("05a0") → "101" + * bitstrtobinstr("07a080") → "101000001" + * bitstrtoint(502) → null // non ASN.1 BitString value + * bitstrtoint("ff00") → -1 // for improper BitString value + */ +function bitstrtobinstr(h) { + var n = bitstrtoint(h); + if (n == -1) return null; + return n.toString(2); +} + +/** + * convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit
+ * @name binstrtobitstr + * @function + * @param {string} s binary string (ex. "101") + * @return {string} hexadecimal string of ASN.1 BitString value with unused bit + * @since jsrsasign 10.5.4 base64x 1.1.21 + * @see bitstrtobinstr + * @see inttobitstr + * @see KJUR.asn1.DERBitString + * + * @description + * This function converts from an binary string (ex. "101") to + * hexadecimal string of ASN.1 BitString value + * with unused bit (ex. "05a0").
+ * When "s" is not binary string, this returns null. + * + * @example + * binstrtobitstr("101") → "05a0" + * binstrtobitstr("11001") → "03c8" + * binstrtobitstr("101000001") → "07a080" + * binstrtobitstr(101) → null // not number + * binstrtobitstr("xyz") → null // not binary string + */ +function binstrtobitstr(s) { + if (typeof s != "string") return null; + if (s.match(/^[01]+$/) == null) return null; + try { + var n = parseInt(s, 2); + return inttobitstr(n); + } catch(ex) { + return null; + } +} + +// ======================================================= /** * set class inheritance
* @name extendClass diff --git a/test/qunit-do-asn1.html b/test/qunit-do-asn1.html index 49f11b90..da64e275 100755 --- a/test/qunit-do-asn1.html +++ b/test/qunit-do-asn1.html @@ -423,6 +423,7 @@ var _DERTaggedObject = KJUR.asn1.DERTaggedObject; var _DERInteger = KJUR.asn1.DERInteger; +var d; var d1a = new KJUR.asn1.DERUTF8String(); d1a.setString('a'); // 0c0161 var d1 = new KJUR.asn1.DERTaggedObject(); @@ -441,29 +442,41 @@ var d4 = new KJUR.asn1.DERTaggedObject({'obj':d2a}); equal(d4.getEncodedHex(), "a0030c0161", "constructor with defaults"); -var d5 = new _DERTaggedObject({ +d = new _DERTaggedObject({ tage: "a2", obj: new _DERInteger({int: 7}) }); -equal(d5.getEncodedHex(), "a203020107", "tage a2 DERInteger(7)"); +equal(d.getEncodedHex(), "a203020107", "tage a2 DERInteger(7)"); -var d6 = new _DERTaggedObject({ +d = new _DERTaggedObject({ tage: "a2", obj: {'int': {'int': 7}} }); -equal(d6.getEncodedHex(), "a203020107", "tage a2 {int: {int: 7}}"); +equal(d.getEncodedHex(), "a203020107", "tage a2 {int: {int: 7}}"); -var d7 = new _DERTaggedObject({ +d = new _DERTaggedObject({ tagi: "82", obj: {'int': {'int': 7}} }); -equal(d7.getEncodedHex(), "820107", "tagi 82 {int: {int: 7}}"); +equal(d.getEncodedHex(), "820107", "tagi 82 {int: {int: 7}}"); -var d8 = new _DERTaggedObject({ +d = new _DERTaggedObject({ tage: "a2", obj: {'asn1': {'tlv': '020107'}} }); -equal(d8.getEncodedHex(), "a203020107", "tage a2 {asn1: {tlv: ''020107'}}"); +equal(d.getEncodedHex(), "a203020107", "tage a2 {asn1: {tlv: ''020107'}}"); + +d = new _DERTaggedObject({ + tag: "81", + str: "aaa" +}); +equal(d.getEncodedHex(), "8103616161", "tag 81, str: aaa"); + +d = new _DERTaggedObject({ + tag: "81", + hex: "616161" +}); +equal(d.getEncodedHex(), "8103616161", "tag 81, hex: 616161"); }); diff --git a/test/qunit-do-asn1hex-parse.html b/test/qunit-do-asn1hex-parse.html index b57f9b63..a6e955da 100755 --- a/test/qunit-do-asn1hex-parse.html +++ b/test/qunit-do-asn1hex-parse.html @@ -21,7 +21,7 @@