diff --git a/ChangeLog.txt b/ChangeLog.txt index bc24f3c2..45d1cdf0 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,20 @@ ChangeLog for jsrsasign +AdobeTimeStamp X.509v3 certificate extension added +* Changes from 10.0.0 to 10.0.1 (2020-Oct-13) + - src/asn1x509.js + - AdobeTimeStamp class added + - add AdobeTimeStamp support in Extension class + - add "adobeTimeStamp" OID in OID class + - src/x509.js + - add getExtAdobeTimeStamp method to X509 class + - add "adobeTimeStamp" support in getExtParam + - src/asn1.js + - DERBoolean add support for "false" value. + - test/qunit-do-{asn1,asn1x509,x509}.html + - updated to follow above + Major update for CMS SigneData TimeStamp and CAdES * Changes from 9.1.9 to 10.0.0 (2020-Sep-24) - major update for CMS SignedData related classes diff --git a/README.md b/README.md index 72dfd0af..90a7e4e6 100755 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Your bugfix and pull request contribution are always welcomed :) NEWS ---- +- 2020-Oct-05: jsrsasign won [Google Open Source Peer Bonus Award](https://opensource.googleblog.com/2020/10/announcing-latest-google-open-source.html). Thank you Google. - 2020-Sep-23: 10.0.0 released for CMS SignedData related class including timestamp and CAdES architecture update - 2020-Aug-24: 9.1.0 released to new CRL APIs align with certificate - 2020-Aug-19: 9.0.0 released for major update of certificate and CSR generation and parsing without backward compatibility. Please see [migration guide](https://github.com/kjur/jsrsasign/wiki/NOTE-jsrsasign-8.0.x-to-9.0.0-Certificate-and-CSR-API-migration-guide) in detail. @@ -32,7 +33,7 @@ HIGHLIGHTS - no dependency to other library - no dependency to [W3C Web Cryptography API](https://www.w3.org/TR/WebCryptoAPI/) nor [OpenSSL](https://www.openssl.org/) - no dependency on newer ECMAScirpt function. So old browsers also supported. -- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2020-09-02) +- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2020-10-11) INSTALL ------- diff --git a/api/files.html b/api/files.html index 4a3d2008..9724605b 100644 --- a/api/files.html +++ b/api/files.html @@ -382,6 +382,8 @@
new KJUR.asn1.DERBoolean(true) +new KJUR.asn1.DERBoolean(false)+ + + diff --git a/api/symbols/KJUR.asn1.DEREnumerated.html b/api/symbols/KJUR.asn1.DEREnumerated.html index 91cb0e85..4432115d 100644 --- a/api/symbols/KJUR.asn1.DEREnumerated.html +++ b/api/symbols/KJUR.asn1.DEREnumerated.html @@ -387,6 +387,8 @@
+adbe- OBJECT IDENTIFIER ::= { adbe(1.2.840.113583) acrobat(1) security(1) x509Ext(9) 1 } + ::= SEQUENCE { + version INTEGER { v1(1) }, -- extension version + location GeneralName (In v1 GeneralName can be only uniformResourceIdentifier) + requiresAuth boolean (default false), OPTIONAL } ++
x.getExtAdobeTimeStamp(<+ + + + +>) → +{ extname: "adobeTimeStamp", uri: "http://tsa.example.com/" reqauth: true }
1 /* asn1-1.0.19.js (c) 2013-2020 Kenji Urushima | kjur.github.com/jsrsasign/license +1 /* asn1-1.0.20.js (c) 2013-2020 Kenji Urushima | kjur.github.com/jsrsasign/license 2 */ 3 /* 4 * asn1.js - ASN.1 DER encoder classes @@ -23,7 +23,7 @@ 16 * @fileOverview 17 * @name asn1-1.0.js 18 * @author Kenji Urushima kenji.urushima@gmail.com - 19 * @version jsrsasign 10.0.0 asn1 1.0.19 (2020-Sep-22) + 19 * @version jsrsasign 10.0.1 asn1 1.0.20 (2020-Oct-11) 20 * @since jsrsasign 2.1 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -797,992 +797,1000 @@ 790 * @name KJUR.asn1.DERBoolean 791 * @class class for ASN.1 DER Boolean 792 * @extends KJUR.asn1.ASN1Object -793 * @description -794 * @see KJUR.asn1.ASN1Object - superclass -795 */ -796 KJUR.asn1.DERBoolean = function() { -797 KJUR.asn1.DERBoolean.superclass.constructor.call(this); -798 this.hT = "01"; -799 this.hTLV = "0101ff"; -800 }; -801 YAHOO.lang.extend(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object); -802 -803 // ******************************************************************** -804 /** -805 * class for ASN.1 DER Integer -806 * @name KJUR.asn1.DERInteger -807 * @class class for ASN.1 DER Integer -808 * @extends KJUR.asn1.ASN1Object -809 * @description -810 * <br/> -811 * As for argument 'params' for constructor, you can specify one of -812 * following properties: -813 * <ul> -814 * <li>int - specify initial ASN.1 value(V) by integer value</li> -815 * <li>bigint - specify initial ASN.1 value(V) by BigInteger object</li> -816 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -817 * </ul> -818 * NOTE: 'params' can be omitted. -819 */ -820 KJUR.asn1.DERInteger = function(params) { -821 KJUR.asn1.DERInteger.superclass.constructor.call(this); -822 this.hT = "02"; -823 -824 /** -825 * set value by Tom Wu's BigInteger object -826 * @name setByBigInteger -827 * @memberOf KJUR.asn1.DERInteger# -828 * @function -829 * @param {BigInteger} bigIntegerValue to set -830 */ -831 this.setByBigInteger = function(bigIntegerValue) { -832 this.hTLV = null; -833 this.isModified = true; -834 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); -835 }; -836 -837 /** -838 * set value by integer value -839 * @name setByInteger -840 * @memberOf KJUR.asn1.DERInteger -841 * @function -842 * @param {Integer} integer value to set -843 */ -844 this.setByInteger = function(intValue) { -845 var bi = new BigInteger(String(intValue), 10); -846 this.setByBigInteger(bi); -847 }; -848 -849 /** -850 * set value by integer value -851 * @name setValueHex -852 * @memberOf KJUR.asn1.DERInteger# -853 * @function -854 * @param {String} hexadecimal string of integer value -855 * @description -856 * <br/> -857 * NOTE: Value shall be represented by minimum octet length of -858 * two's complement representation. -859 * @example -860 * new KJUR.asn1.DERInteger(123); -861 * new KJUR.asn1.DERInteger({'int': 123}); -862 * new KJUR.asn1.DERInteger({'hex': '1fad'}); -863 */ -864 this.setValueHex = function(newHexString) { -865 this.hV = newHexString; -866 }; -867 -868 this.getFreshValueHex = function() { -869 return this.hV; -870 }; -871 -872 if (typeof params != "undefined") { -873 if (typeof params['bigint'] != "undefined") { -874 this.setByBigInteger(params['bigint']); -875 } else if (typeof params['int'] != "undefined") { -876 this.setByInteger(params['int']); -877 } else if (typeof params == "number") { -878 this.setByInteger(params); -879 } else if (typeof params['hex'] != "undefined") { -880 this.setValueHex(params['hex']); -881 } -882 } -883 }; -884 YAHOO.lang.extend(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object); -885 -886 // ******************************************************************** -887 /** -888 * class for ASN.1 DER encoded BitString primitive -889 * @name KJUR.asn1.DERBitString -890 * @class class for ASN.1 DER encoded BitString primitive -891 * @extends KJUR.asn1.ASN1Object -892 * @description -893 * <br/> -894 * As for argument 'params' for constructor, you can specify one of -895 * following properties: -896 * <ul> -897 * <li>bin - specify binary string (ex. '10111')</li> -898 * <li>array - specify array of boolean (ex. [true,false,true,true])</li> -899 * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li> -900 * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} -901 * argument for "BitString encapsulates" structure.</li> -902 * </ul> -903 * NOTE1: 'params' can be omitted.<br/> -904 * NOTE2: 'obj' parameter have been supported since -905 * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/> -906 * @example -907 * // default constructor -908 * o = new KJUR.asn1.DERBitString(); -909 * // initialize with binary string -910 * o = new KJUR.asn1.DERBitString({bin: "1011"}); -911 * // initialize with boolean array -912 * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]}); -913 * // initialize with hexadecimal string (04 is unused bits) -914 * o = new KJUR.asn1.DEROctetString({hex: "04bac0"}); -915 * // initialize with ASN1Util.newObject argument for encapsulated -916 * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); -917 * // above generates a ASN.1 data like this: -918 * // BIT STRING, encapsulates { -919 * // SEQUENCE { -920 * // INTEGER 3 -921 * // PrintableString 'aaa' -922 * // } -923 * // } -924 */ -925 KJUR.asn1.DERBitString = function(params) { -926 if (params !== undefined && typeof params.obj !== "undefined") { -927 var o = KJUR.asn1.ASN1Util.newObject(params.obj); -928 params.hex = "00" + o.getEncodedHex(); -929 } -930 KJUR.asn1.DERBitString.superclass.constructor.call(this); -931 this.hT = "03"; -932 -933 /** -934 * set ASN.1 value(V) by a hexadecimal string including unused bits -935 * @name setHexValueIncludingUnusedBits -936 * @memberOf KJUR.asn1.DERBitString# -937 * @function -938 * @param {String} newHexStringIncludingUnusedBits -939 */ -940 this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) { -941 this.hTLV = null; -942 this.isModified = true; -943 this.hV = newHexStringIncludingUnusedBits; -944 }; -945 -946 /** -947 * set ASN.1 value(V) by unused bit and hexadecimal string of value -948 * @name setUnusedBitsAndHexValue -949 * @memberOf KJUR.asn1.DERBitString# -950 * @function -951 * @param {Integer} unusedBits -952 * @param {String} hValue -953 */ -954 this.setUnusedBitsAndHexValue = function(unusedBits, hValue) { -955 if (unusedBits < 0 || 7 < unusedBits) { -956 throw "unused bits shall be from 0 to 7: u = " + unusedBits; -957 } -958 var hUnusedBits = "0" + unusedBits; -959 this.hTLV = null; -960 this.isModified = true; -961 this.hV = hUnusedBits + hValue; -962 }; -963 -964 /** -965 * set ASN.1 DER BitString by binary string<br/> -966 * @name setByBinaryString -967 * @memberOf KJUR.asn1.DERBitString# -968 * @function -969 * @param {String} binaryString binary value string (i.e. '10111') -970 * @description -971 * Its unused bits will be calculated automatically by length of -972 * 'binaryValue'. <br/> -973 * NOTE: Trailing zeros '0' will be ignored. -974 * @example -975 * o = new KJUR.asn1.DERBitString(); -976 * o.setByBooleanArray("01011"); -977 */ -978 this.setByBinaryString = function(binaryString) { -979 binaryString = binaryString.replace(/0+$/, ''); -980 var unusedBits = 8 - binaryString.length % 8; -981 if (unusedBits == 8) unusedBits = 0; -982 for (var i = 0; i <= unusedBits; i++) { -983 binaryString += '0'; -984 } -985 var h = ''; -986 for (var i = 0; i < binaryString.length - 1; i += 8) { -987 var b = binaryString.substr(i, 8); -988 var x = parseInt(b, 2).toString(16); -989 if (x.length == 1) x = '0' + x; -990 h += x; -991 } -992 this.hTLV = null; -993 this.isModified = true; -994 this.hV = '0' + unusedBits + h; -995 }; -996 -997 /** -998 * set ASN.1 TLV value(V) by an array of boolean<br/> -999 * @name setByBooleanArray -1000 * @memberOf KJUR.asn1.DERBitString# -1001 * @function -1002 * @param {array} booleanArray array of boolean (ex. [true, false, true]) -1003 * @description -1004 * NOTE: Trailing falses will be ignored in the ASN.1 DER Object. -1005 * @example -1006 * o = new KJUR.asn1.DERBitString(); -1007 * o.setByBooleanArray([false, true, false, true, true]); -1008 */ -1009 this.setByBooleanArray = function(booleanArray) { -1010 var s = ''; -1011 for (var i = 0; i < booleanArray.length; i++) { -1012 if (booleanArray[i] == true) { -1013 s += '1'; -1014 } else { -1015 s += '0'; -1016 } -1017 } -1018 this.setByBinaryString(s); -1019 }; -1020 -1021 /** -1022 * generate an array of falses with specified length<br/> -1023 * @name newFalseArray -1024 * @memberOf KJUR.asn1.DERBitString -1025 * @function -1026 * @param {Integer} nLength length of array to generate -1027 * @return {array} array of boolean falses -1028 * @description -1029 * This static method may be useful to initialize boolean array. -1030 * @example -1031 * o = new KJUR.asn1.DERBitString(); -1032 * o.newFalseArray(3) → [false, false, false] -1033 */ -1034 this.newFalseArray = function(nLength) { -1035 var a = new Array(nLength); -1036 for (var i = 0; i < nLength; i++) { -1037 a[i] = false; -1038 } -1039 return a; -1040 }; -1041 -1042 this.getFreshValueHex = function() { -1043 return this.hV; -1044 }; -1045 -1046 if (typeof params != "undefined") { -1047 if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) { -1048 this.setHexValueIncludingUnusedBits(params); -1049 } else if (typeof params['hex'] != "undefined") { -1050 this.setHexValueIncludingUnusedBits(params['hex']); -1051 } else if (typeof params['bin'] != "undefined") { -1052 this.setByBinaryString(params['bin']); -1053 } else if (typeof params['array'] != "undefined") { -1054 this.setByBooleanArray(params['array']); -1055 } -1056 } -1057 }; -1058 YAHOO.lang.extend(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object); -1059 -1060 // ******************************************************************** -1061 /** -1062 * class for ASN.1 DER OctetString<br/> -1063 * @name KJUR.asn1.DEROctetString -1064 * @class class for ASN.1 DER OctetString -1065 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1066 * @extends KJUR.asn1.DERAbstractString -1067 * @description -1068 * This class provides ASN.1 OctetString simple type.<br/> -1069 * Supported "params" attributes are: -1070 * <ul> -1071 * <li>str - to set a string as a value</li> -1072 * <li>hex - to set a hexadecimal string as a value</li> -1073 * <li>obj - to set a encapsulated ASN.1 value by JSON object -1074 * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li> -1075 * </ul> -1076 * NOTE: A parameter 'obj' have been supported -1077 * for "OCTET STRING, encapsulates" structure. -1078 * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25). -1079 * @see KJUR.asn1.DERAbstractString - superclass -1080 * @example -1081 * // default constructor -1082 * o = new KJUR.asn1.DEROctetString(); -1083 * // initialize with string -1084 * o = new KJUR.asn1.DEROctetString({str: "aaa"}); -1085 * // initialize with hexadecimal string -1086 * o = new KJUR.asn1.DEROctetString({hex: "616161"}); -1087 * // initialize with ASN1Util.newObject argument -1088 * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); -1089 * // above generates a ASN.1 data like this: -1090 * // OCTET STRING, encapsulates { -1091 * // SEQUENCE { -1092 * // INTEGER 3 -1093 * // PrintableString 'aaa' -1094 * // } -1095 * // } -1096 */ -1097 KJUR.asn1.DEROctetString = function(params) { -1098 if (params !== undefined && typeof params.obj !== "undefined") { -1099 var o = KJUR.asn1.ASN1Util.newObject(params.obj); -1100 params.hex = o.getEncodedHex(); -1101 } -1102 KJUR.asn1.DEROctetString.superclass.constructor.call(this, params); -1103 this.hT = "04"; -1104 }; -1105 YAHOO.lang.extend(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString); -1106 -1107 // ******************************************************************** -1108 /** -1109 * class for ASN.1 DER Null -1110 * @name KJUR.asn1.DERNull -1111 * @class class for ASN.1 DER Null -1112 * @extends KJUR.asn1.ASN1Object -1113 * @description -1114 * @see KJUR.asn1.ASN1Object - superclass -1115 */ -1116 KJUR.asn1.DERNull = function() { -1117 KJUR.asn1.DERNull.superclass.constructor.call(this); -1118 this.hT = "05"; -1119 this.hTLV = "0500"; -1120 }; -1121 YAHOO.lang.extend(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object); -1122 -1123 // ******************************************************************** -1124 /** -1125 * class for ASN.1 DER ObjectIdentifier -1126 * @name KJUR.asn1.DERObjectIdentifier -1127 * @class class for ASN.1 DER ObjectIdentifier -1128 * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'}) -1129 * @extends KJUR.asn1.ASN1Object -1130 * @description -1131 * <br/> -1132 * As for argument 'params' for constructor, you can specify one of -1133 * following properties: -1134 * <ul> -1135 * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li> -1136 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1137 * </ul> -1138 * NOTE: 'params' can be omitted. -1139 * @example -1140 * new DERObjectIdentifier({"name": "sha1"}) -1141 * new DERObjectIdentifier({"oid": "1.2.3.4"}) -1142 * new DERObjectIdentifier({"hex": "2d..."}) -1143 * new DERObjectIdentifier("1.2.3.4") -1144 * new DERObjectIdentifier("SHA1withRSA") -1145 */ -1146 KJUR.asn1.DERObjectIdentifier = function(params) { -1147 var itox = function(i) { -1148 var h = i.toString(16); -1149 if (h.length == 1) h = '0' + h; -1150 return h; -1151 }; -1152 var roidtox = function(roid) { -1153 var h = ''; -1154 var bi = new BigInteger(roid, 10); -1155 var b = bi.toString(2); -1156 var padLen = 7 - b.length % 7; -1157 if (padLen == 7) padLen = 0; -1158 var bPad = ''; -1159 for (var i = 0; i < padLen; i++) bPad += '0'; -1160 b = bPad + b; -1161 for (var i = 0; i < b.length - 1; i += 7) { -1162 var b8 = b.substr(i, 7); -1163 if (i != b.length - 7) b8 = '1' + b8; -1164 h += itox(parseInt(b8, 2)); -1165 } -1166 return h; -1167 } -1168 -1169 KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this); -1170 this.hT = "06"; -1171 -1172 /** -1173 * set value by a hexadecimal string -1174 * @name setValueHex -1175 * @memberOf KJUR.asn1.DERObjectIdentifier# -1176 * @function -1177 * @param {String} newHexString hexadecimal value of OID bytes -1178 */ -1179 this.setValueHex = function(newHexString) { -1180 this.hTLV = null; -1181 this.isModified = true; -1182 this.s = null; -1183 this.hV = newHexString; -1184 }; -1185 -1186 /** -1187 * set value by a OID string<br/> -1188 * @name setValueOidString -1189 * @memberOf KJUR.asn1.DERObjectIdentifier# -1190 * @function -1191 * @param {String} oidString OID string (ex. 2.5.4.13) -1192 * @example -1193 * o = new KJUR.asn1.DERObjectIdentifier(); -1194 * o.setValueOidString("2.5.4.13"); -1195 */ -1196 this.setValueOidString = function(oidString) { -1197 if (! oidString.match(/^[0-9.]+$/)) { -1198 throw new Error("malformed oid string: " + oidString); -1199 } -1200 var h = ''; -1201 var a = oidString.split('.'); -1202 var i0 = parseInt(a[0]) * 40 + parseInt(a[1]); -1203 h += itox(i0); -1204 a.splice(0, 2); -1205 for (var i = 0; i < a.length; i++) { -1206 h += roidtox(a[i]); +793 * @see KJUR.asn1.ASN1Object - superclass +794 * @description +795 * In ASN.1 DER, DER Boolean "false" shall be omitted. +796 * However this supports boolean false for future BER support. +797 * @example +798 * new KJUR.asn1.DERBoolean(true) +799 * new KJUR.asn1.DERBoolean(false) +800 */ +801 KJUR.asn1.DERBoolean = function(params) { +802 KJUR.asn1.DERBoolean.superclass.constructor.call(this); +803 this.hT = "01"; +804 if (params == false) +805 this.hTLV = "010100"; +806 else +807 this.hTLV = "0101ff"; +808 }; +809 YAHOO.lang.extend(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object); +810 +811 // ******************************************************************** +812 /** +813 * class for ASN.1 DER Integer +814 * @name KJUR.asn1.DERInteger +815 * @class class for ASN.1 DER Integer +816 * @extends KJUR.asn1.ASN1Object +817 * @description +818 * <br/> +819 * As for argument 'params' for constructor, you can specify one of +820 * following properties: +821 * <ul> +822 * <li>int - specify initial ASN.1 value(V) by integer value</li> +823 * <li>bigint - specify initial ASN.1 value(V) by BigInteger object</li> +824 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> +825 * </ul> +826 * NOTE: 'params' can be omitted. +827 */ +828 KJUR.asn1.DERInteger = function(params) { +829 KJUR.asn1.DERInteger.superclass.constructor.call(this); +830 this.hT = "02"; +831 +832 /** +833 * set value by Tom Wu's BigInteger object +834 * @name setByBigInteger +835 * @memberOf KJUR.asn1.DERInteger# +836 * @function +837 * @param {BigInteger} bigIntegerValue to set +838 */ +839 this.setByBigInteger = function(bigIntegerValue) { +840 this.hTLV = null; +841 this.isModified = true; +842 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); +843 }; +844 +845 /** +846 * set value by integer value +847 * @name setByInteger +848 * @memberOf KJUR.asn1.DERInteger +849 * @function +850 * @param {Integer} integer value to set +851 */ +852 this.setByInteger = function(intValue) { +853 var bi = new BigInteger(String(intValue), 10); +854 this.setByBigInteger(bi); +855 }; +856 +857 /** +858 * set value by integer value +859 * @name setValueHex +860 * @memberOf KJUR.asn1.DERInteger# +861 * @function +862 * @param {String} hexadecimal string of integer value +863 * @description +864 * <br/> +865 * NOTE: Value shall be represented by minimum octet length of +866 * two's complement representation. +867 * @example +868 * new KJUR.asn1.DERInteger(123); +869 * new KJUR.asn1.DERInteger({'int': 123}); +870 * new KJUR.asn1.DERInteger({'hex': '1fad'}); +871 */ +872 this.setValueHex = function(newHexString) { +873 this.hV = newHexString; +874 }; +875 +876 this.getFreshValueHex = function() { +877 return this.hV; +878 }; +879 +880 if (typeof params != "undefined") { +881 if (typeof params['bigint'] != "undefined") { +882 this.setByBigInteger(params['bigint']); +883 } else if (typeof params['int'] != "undefined") { +884 this.setByInteger(params['int']); +885 } else if (typeof params == "number") { +886 this.setByInteger(params); +887 } else if (typeof params['hex'] != "undefined") { +888 this.setValueHex(params['hex']); +889 } +890 } +891 }; +892 YAHOO.lang.extend(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object); +893 +894 // ******************************************************************** +895 /** +896 * class for ASN.1 DER encoded BitString primitive +897 * @name KJUR.asn1.DERBitString +898 * @class class for ASN.1 DER encoded BitString primitive +899 * @extends KJUR.asn1.ASN1Object +900 * @description +901 * <br/> +902 * As for argument 'params' for constructor, you can specify one of +903 * following properties: +904 * <ul> +905 * <li>bin - specify binary string (ex. '10111')</li> +906 * <li>array - specify array of boolean (ex. [true,false,true,true])</li> +907 * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li> +908 * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} +909 * argument for "BitString encapsulates" structure.</li> +910 * </ul> +911 * NOTE1: 'params' can be omitted.<br/> +912 * NOTE2: 'obj' parameter have been supported since +913 * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/> +914 * @example +915 * // default constructor +916 * o = new KJUR.asn1.DERBitString(); +917 * // initialize with binary string +918 * o = new KJUR.asn1.DERBitString({bin: "1011"}); +919 * // initialize with boolean array +920 * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]}); +921 * // initialize with hexadecimal string (04 is unused bits) +922 * o = new KJUR.asn1.DEROctetString({hex: "04bac0"}); +923 * // initialize with ASN1Util.newObject argument for encapsulated +924 * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); +925 * // above generates a ASN.1 data like this: +926 * // BIT STRING, encapsulates { +927 * // SEQUENCE { +928 * // INTEGER 3 +929 * // PrintableString 'aaa' +930 * // } +931 * // } +932 */ +933 KJUR.asn1.DERBitString = function(params) { +934 if (params !== undefined && typeof params.obj !== "undefined") { +935 var o = KJUR.asn1.ASN1Util.newObject(params.obj); +936 params.hex = "00" + o.getEncodedHex(); +937 } +938 KJUR.asn1.DERBitString.superclass.constructor.call(this); +939 this.hT = "03"; +940 +941 /** +942 * set ASN.1 value(V) by a hexadecimal string including unused bits +943 * @name setHexValueIncludingUnusedBits +944 * @memberOf KJUR.asn1.DERBitString# +945 * @function +946 * @param {String} newHexStringIncludingUnusedBits +947 */ +948 this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) { +949 this.hTLV = null; +950 this.isModified = true; +951 this.hV = newHexStringIncludingUnusedBits; +952 }; +953 +954 /** +955 * set ASN.1 value(V) by unused bit and hexadecimal string of value +956 * @name setUnusedBitsAndHexValue +957 * @memberOf KJUR.asn1.DERBitString# +958 * @function +959 * @param {Integer} unusedBits +960 * @param {String} hValue +961 */ +962 this.setUnusedBitsAndHexValue = function(unusedBits, hValue) { +963 if (unusedBits < 0 || 7 < unusedBits) { +964 throw "unused bits shall be from 0 to 7: u = " + unusedBits; +965 } +966 var hUnusedBits = "0" + unusedBits; +967 this.hTLV = null; +968 this.isModified = true; +969 this.hV = hUnusedBits + hValue; +970 }; +971 +972 /** +973 * set ASN.1 DER BitString by binary string<br/> +974 * @name setByBinaryString +975 * @memberOf KJUR.asn1.DERBitString# +976 * @function +977 * @param {String} binaryString binary value string (i.e. '10111') +978 * @description +979 * Its unused bits will be calculated automatically by length of +980 * 'binaryValue'. <br/> +981 * NOTE: Trailing zeros '0' will be ignored. +982 * @example +983 * o = new KJUR.asn1.DERBitString(); +984 * o.setByBooleanArray("01011"); +985 */ +986 this.setByBinaryString = function(binaryString) { +987 binaryString = binaryString.replace(/0+$/, ''); +988 var unusedBits = 8 - binaryString.length % 8; +989 if (unusedBits == 8) unusedBits = 0; +990 for (var i = 0; i <= unusedBits; i++) { +991 binaryString += '0'; +992 } +993 var h = ''; +994 for (var i = 0; i < binaryString.length - 1; i += 8) { +995 var b = binaryString.substr(i, 8); +996 var x = parseInt(b, 2).toString(16); +997 if (x.length == 1) x = '0' + x; +998 h += x; +999 } +1000 this.hTLV = null; +1001 this.isModified = true; +1002 this.hV = '0' + unusedBits + h; +1003 }; +1004 +1005 /** +1006 * set ASN.1 TLV value(V) by an array of boolean<br/> +1007 * @name setByBooleanArray +1008 * @memberOf KJUR.asn1.DERBitString# +1009 * @function +1010 * @param {array} booleanArray array of boolean (ex. [true, false, true]) +1011 * @description +1012 * NOTE: Trailing falses will be ignored in the ASN.1 DER Object. +1013 * @example +1014 * o = new KJUR.asn1.DERBitString(); +1015 * o.setByBooleanArray([false, true, false, true, true]); +1016 */ +1017 this.setByBooleanArray = function(booleanArray) { +1018 var s = ''; +1019 for (var i = 0; i < booleanArray.length; i++) { +1020 if (booleanArray[i] == true) { +1021 s += '1'; +1022 } else { +1023 s += '0'; +1024 } +1025 } +1026 this.setByBinaryString(s); +1027 }; +1028 +1029 /** +1030 * generate an array of falses with specified length<br/> +1031 * @name newFalseArray +1032 * @memberOf KJUR.asn1.DERBitString +1033 * @function +1034 * @param {Integer} nLength length of array to generate +1035 * @return {array} array of boolean falses +1036 * @description +1037 * This static method may be useful to initialize boolean array. +1038 * @example +1039 * o = new KJUR.asn1.DERBitString(); +1040 * o.newFalseArray(3) → [false, false, false] +1041 */ +1042 this.newFalseArray = function(nLength) { +1043 var a = new Array(nLength); +1044 for (var i = 0; i < nLength; i++) { +1045 a[i] = false; +1046 } +1047 return a; +1048 }; +1049 +1050 this.getFreshValueHex = function() { +1051 return this.hV; +1052 }; +1053 +1054 if (typeof params != "undefined") { +1055 if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) { +1056 this.setHexValueIncludingUnusedBits(params); +1057 } else if (typeof params['hex'] != "undefined") { +1058 this.setHexValueIncludingUnusedBits(params['hex']); +1059 } else if (typeof params['bin'] != "undefined") { +1060 this.setByBinaryString(params['bin']); +1061 } else if (typeof params['array'] != "undefined") { +1062 this.setByBooleanArray(params['array']); +1063 } +1064 } +1065 }; +1066 YAHOO.lang.extend(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object); +1067 +1068 // ******************************************************************** +1069 /** +1070 * class for ASN.1 DER OctetString<br/> +1071 * @name KJUR.asn1.DEROctetString +1072 * @class class for ASN.1 DER OctetString +1073 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1074 * @extends KJUR.asn1.DERAbstractString +1075 * @description +1076 * This class provides ASN.1 OctetString simple type.<br/> +1077 * Supported "params" attributes are: +1078 * <ul> +1079 * <li>str - to set a string as a value</li> +1080 * <li>hex - to set a hexadecimal string as a value</li> +1081 * <li>obj - to set a encapsulated ASN.1 value by JSON object +1082 * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li> +1083 * </ul> +1084 * NOTE: A parameter 'obj' have been supported +1085 * for "OCTET STRING, encapsulates" structure. +1086 * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25). +1087 * @see KJUR.asn1.DERAbstractString - superclass +1088 * @example +1089 * // default constructor +1090 * o = new KJUR.asn1.DEROctetString(); +1091 * // initialize with string +1092 * o = new KJUR.asn1.DEROctetString({str: "aaa"}); +1093 * // initialize with hexadecimal string +1094 * o = new KJUR.asn1.DEROctetString({hex: "616161"}); +1095 * // initialize with ASN1Util.newObject argument +1096 * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); +1097 * // above generates a ASN.1 data like this: +1098 * // OCTET STRING, encapsulates { +1099 * // SEQUENCE { +1100 * // INTEGER 3 +1101 * // PrintableString 'aaa' +1102 * // } +1103 * // } +1104 */ +1105 KJUR.asn1.DEROctetString = function(params) { +1106 if (params !== undefined && typeof params.obj !== "undefined") { +1107 var o = KJUR.asn1.ASN1Util.newObject(params.obj); +1108 params.hex = o.getEncodedHex(); +1109 } +1110 KJUR.asn1.DEROctetString.superclass.constructor.call(this, params); +1111 this.hT = "04"; +1112 }; +1113 YAHOO.lang.extend(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString); +1114 +1115 // ******************************************************************** +1116 /** +1117 * class for ASN.1 DER Null +1118 * @name KJUR.asn1.DERNull +1119 * @class class for ASN.1 DER Null +1120 * @extends KJUR.asn1.ASN1Object +1121 * @description +1122 * @see KJUR.asn1.ASN1Object - superclass +1123 */ +1124 KJUR.asn1.DERNull = function() { +1125 KJUR.asn1.DERNull.superclass.constructor.call(this); +1126 this.hT = "05"; +1127 this.hTLV = "0500"; +1128 }; +1129 YAHOO.lang.extend(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object); +1130 +1131 // ******************************************************************** +1132 /** +1133 * class for ASN.1 DER ObjectIdentifier +1134 * @name KJUR.asn1.DERObjectIdentifier +1135 * @class class for ASN.1 DER ObjectIdentifier +1136 * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'}) +1137 * @extends KJUR.asn1.ASN1Object +1138 * @description +1139 * <br/> +1140 * As for argument 'params' for constructor, you can specify one of +1141 * following properties: +1142 * <ul> +1143 * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li> +1144 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> +1145 * </ul> +1146 * NOTE: 'params' can be omitted. +1147 * @example +1148 * new DERObjectIdentifier({"name": "sha1"}) +1149 * new DERObjectIdentifier({"oid": "1.2.3.4"}) +1150 * new DERObjectIdentifier({"hex": "2d..."}) +1151 * new DERObjectIdentifier("1.2.3.4") +1152 * new DERObjectIdentifier("SHA1withRSA") +1153 */ +1154 KJUR.asn1.DERObjectIdentifier = function(params) { +1155 var itox = function(i) { +1156 var h = i.toString(16); +1157 if (h.length == 1) h = '0' + h; +1158 return h; +1159 }; +1160 var roidtox = function(roid) { +1161 var h = ''; +1162 var bi = new BigInteger(roid, 10); +1163 var b = bi.toString(2); +1164 var padLen = 7 - b.length % 7; +1165 if (padLen == 7) padLen = 0; +1166 var bPad = ''; +1167 for (var i = 0; i < padLen; i++) bPad += '0'; +1168 b = bPad + b; +1169 for (var i = 0; i < b.length - 1; i += 7) { +1170 var b8 = b.substr(i, 7); +1171 if (i != b.length - 7) b8 = '1' + b8; +1172 h += itox(parseInt(b8, 2)); +1173 } +1174 return h; +1175 } +1176 +1177 KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this); +1178 this.hT = "06"; +1179 +1180 /** +1181 * set value by a hexadecimal string +1182 * @name setValueHex +1183 * @memberOf KJUR.asn1.DERObjectIdentifier# +1184 * @function +1185 * @param {String} newHexString hexadecimal value of OID bytes +1186 */ +1187 this.setValueHex = function(newHexString) { +1188 this.hTLV = null; +1189 this.isModified = true; +1190 this.s = null; +1191 this.hV = newHexString; +1192 }; +1193 +1194 /** +1195 * set value by a OID string<br/> +1196 * @name setValueOidString +1197 * @memberOf KJUR.asn1.DERObjectIdentifier# +1198 * @function +1199 * @param {String} oidString OID string (ex. 2.5.4.13) +1200 * @example +1201 * o = new KJUR.asn1.DERObjectIdentifier(); +1202 * o.setValueOidString("2.5.4.13"); +1203 */ +1204 this.setValueOidString = function(oidString) { +1205 if (! oidString.match(/^[0-9.]+$/)) { +1206 throw new Error("malformed oid string: " + oidString); 1207 } -1208 this.hTLV = null; -1209 this.isModified = true; -1210 this.s = null; -1211 this.hV = h; -1212 }; -1213 -1214 /** -1215 * set value by a OID name -1216 * @name setValueName -1217 * @memberOf KJUR.asn1.DERObjectIdentifier# -1218 * @function -1219 * @param {String} oidName OID name (ex. 'serverAuth') -1220 * @since 1.0.1 -1221 * @description -1222 * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'. -1223 * Otherwise raise error. -1224 * @example -1225 * o = new KJUR.asn1.DERObjectIdentifier(); -1226 * o.setValueName("serverAuth"); -1227 */ -1228 this.setValueName = function(oidName) { -1229 var oid = KJUR.asn1.x509.OID.name2oid(oidName); -1230 if (oid !== '') { -1231 this.setValueOidString(oid); -1232 } else { -1233 throw new Error("DERObjectIdentifier oidName undefined: " + oidName); -1234 } -1235 }; -1236 -1237 this.setValueNameOrOid = function(nameOrOid) { -1238 if (nameOrOid.match(/^[0-2].[0-9.]+$/)) { -1239 this.setValueOidString(nameOrOid); -1240 } else { -1241 this.setValueName(nameOrOid); -1242 } -1243 } +1208 var h = ''; +1209 var a = oidString.split('.'); +1210 var i0 = parseInt(a[0]) * 40 + parseInt(a[1]); +1211 h += itox(i0); +1212 a.splice(0, 2); +1213 for (var i = 0; i < a.length; i++) { +1214 h += roidtox(a[i]); +1215 } +1216 this.hTLV = null; +1217 this.isModified = true; +1218 this.s = null; +1219 this.hV = h; +1220 }; +1221 +1222 /** +1223 * set value by a OID name +1224 * @name setValueName +1225 * @memberOf KJUR.asn1.DERObjectIdentifier# +1226 * @function +1227 * @param {String} oidName OID name (ex. 'serverAuth') +1228 * @since 1.0.1 +1229 * @description +1230 * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'. +1231 * Otherwise raise error. +1232 * @example +1233 * o = new KJUR.asn1.DERObjectIdentifier(); +1234 * o.setValueName("serverAuth"); +1235 */ +1236 this.setValueName = function(oidName) { +1237 var oid = KJUR.asn1.x509.OID.name2oid(oidName); +1238 if (oid !== '') { +1239 this.setValueOidString(oid); +1240 } else { +1241 throw new Error("DERObjectIdentifier oidName undefined: " + oidName); +1242 } +1243 }; 1244 -1245 this.getFreshValueHex = function() { -1246 return this.hV; -1247 }; -1248 -1249 this.setByParam = function(params) { -1250 if (typeof params === "string") { -1251 this.setValueNameOrOid(params); -1252 } else if (params.oid !== undefined) { -1253 this.setValueNameOrOid(params.oid); -1254 } else if (params.name !== undefined) { -1255 this.setValueNameOrOid(params.name); -1256 } else if (params.hex !== undefined) { -1257 this.setValueHex(params.hex); -1258 } -1259 }; -1260 -1261 if (params !== undefined) this.setByParam(params); -1262 }; -1263 YAHOO.lang.extend(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object); -1264 -1265 // ******************************************************************** -1266 /** -1267 * class for ASN.1 DER Enumerated -1268 * @name KJUR.asn1.DEREnumerated -1269 * @class class for ASN.1 DER Enumerated -1270 * @extends KJUR.asn1.ASN1Object -1271 * @description -1272 * <br/> -1273 * As for argument 'params' for constructor, you can specify one of -1274 * following properties: -1275 * <ul> -1276 * <li>int - specify initial ASN.1 value(V) by integer value</li> -1277 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1278 * </ul> -1279 * NOTE: 'params' can be omitted. -1280 * @example -1281 * new KJUR.asn1.DEREnumerated(123); -1282 * new KJUR.asn1.DEREnumerated({int: 123}); -1283 * new KJUR.asn1.DEREnumerated({hex: '1fad'}); -1284 */ -1285 KJUR.asn1.DEREnumerated = function(params) { -1286 KJUR.asn1.DEREnumerated.superclass.constructor.call(this); -1287 this.hT = "0a"; -1288 -1289 /** -1290 * set value by Tom Wu's BigInteger object -1291 * @name setByBigInteger -1292 * @memberOf KJUR.asn1.DEREnumerated# -1293 * @function -1294 * @param {BigInteger} bigIntegerValue to set -1295 */ -1296 this.setByBigInteger = function(bigIntegerValue) { -1297 this.hTLV = null; -1298 this.isModified = true; -1299 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); -1300 }; -1301 -1302 /** -1303 * set value by integer value -1304 * @name setByInteger -1305 * @memberOf KJUR.asn1.DEREnumerated# -1306 * @function -1307 * @param {Integer} integer value to set -1308 */ -1309 this.setByInteger = function(intValue) { -1310 var bi = new BigInteger(String(intValue), 10); -1311 this.setByBigInteger(bi); -1312 }; -1313 -1314 /** -1315 * set value by integer value -1316 * @name setValueHex -1317 * @memberOf KJUR.asn1.DEREnumerated# -1318 * @function -1319 * @param {String} hexadecimal string of integer value -1320 * @description -1321 * <br/> -1322 * NOTE: Value shall be represented by minimum octet length of -1323 * two's complement representation. -1324 */ -1325 this.setValueHex = function(newHexString) { -1326 this.hV = newHexString; -1327 }; -1328 -1329 this.getFreshValueHex = function() { -1330 return this.hV; -1331 }; -1332 -1333 if (typeof params != "undefined") { -1334 if (typeof params['int'] != "undefined") { -1335 this.setByInteger(params['int']); -1336 } else if (typeof params == "number") { -1337 this.setByInteger(params); -1338 } else if (typeof params['hex'] != "undefined") { -1339 this.setValueHex(params['hex']); -1340 } -1341 } -1342 }; -1343 YAHOO.lang.extend(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object); -1344 -1345 // ******************************************************************** -1346 /** -1347 * class for ASN.1 DER UTF8String -1348 * @name KJUR.asn1.DERUTF8String -1349 * @class class for ASN.1 DER UTF8String -1350 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1351 * @extends KJUR.asn1.DERAbstractString -1352 * @description -1353 * @see KJUR.asn1.DERAbstractString - superclass -1354 */ -1355 KJUR.asn1.DERUTF8String = function(params) { -1356 KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params); -1357 this.hT = "0c"; -1358 }; -1359 YAHOO.lang.extend(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString); -1360 -1361 // ******************************************************************** -1362 /** -1363 * class for ASN.1 DER NumericString -1364 * @name KJUR.asn1.DERNumericString -1365 * @class class for ASN.1 DER NumericString -1366 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1367 * @extends KJUR.asn1.DERAbstractString -1368 * @description -1369 * @see KJUR.asn1.DERAbstractString - superclass -1370 */ -1371 KJUR.asn1.DERNumericString = function(params) { -1372 KJUR.asn1.DERNumericString.superclass.constructor.call(this, params); -1373 this.hT = "12"; -1374 }; -1375 YAHOO.lang.extend(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString); -1376 -1377 // ******************************************************************** -1378 /** -1379 * class for ASN.1 DER PrintableString -1380 * @name KJUR.asn1.DERPrintableString -1381 * @class class for ASN.1 DER PrintableString -1382 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1383 * @extends KJUR.asn1.DERAbstractString -1384 * @description -1385 * @see KJUR.asn1.DERAbstractString - superclass -1386 */ -1387 KJUR.asn1.DERPrintableString = function(params) { -1388 KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params); -1389 this.hT = "13"; -1390 }; -1391 YAHOO.lang.extend(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString); -1392 -1393 // ******************************************************************** -1394 /** -1395 * class for ASN.1 DER TeletexString -1396 * @name KJUR.asn1.DERTeletexString -1397 * @class class for ASN.1 DER TeletexString -1398 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1399 * @extends KJUR.asn1.DERAbstractString -1400 * @description -1401 * @see KJUR.asn1.DERAbstractString - superclass -1402 */ -1403 KJUR.asn1.DERTeletexString = function(params) { -1404 KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params); -1405 this.hT = "14"; -1406 }; -1407 YAHOO.lang.extend(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString); -1408 -1409 // ******************************************************************** -1410 /** -1411 * class for ASN.1 DER IA5String -1412 * @name KJUR.asn1.DERIA5String -1413 * @class class for ASN.1 DER IA5String -1414 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1415 * @extends KJUR.asn1.DERAbstractString -1416 * @description -1417 * @see KJUR.asn1.DERAbstractString - superclass -1418 */ -1419 KJUR.asn1.DERIA5String = function(params) { -1420 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); -1421 this.hT = "16"; -1422 }; -1423 YAHOO.lang.extend(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString); -1424 -1425 // ******************************************************************** -1426 /** -1427 * class for ASN.1 DER VisibleString -1428 * @name KJUR.asn1.DERVisibleString -1429 * @class class for ASN.1 DER VisibleString -1430 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1431 * @extends KJUR.asn1.DERAbstractString -1432 * @since jsrsasign 8.0.23 asn1 1.0.15 -1433 * @description -1434 * @see KJUR.asn1.DERAbstractString - superclass -1435 */ -1436 KJUR.asn1.DERVisibleString = function(params) { -1437 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); -1438 this.hT = "1a"; -1439 }; -1440 YAHOO.lang.extend(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString); -1441 -1442 // ******************************************************************** -1443 /** -1444 * class for ASN.1 DER BMPString -1445 * @name KJUR.asn1.DERBMPString -1446 * @class class for ASN.1 DER BMPString -1447 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1448 * @extends KJUR.asn1.DERAbstractString -1449 * @since jsrsasign 8.0.23 asn1 1.0.15 -1450 * @description -1451 * @see KJUR.asn1.DERAbstractString - superclass -1452 */ -1453 KJUR.asn1.DERBMPString = function(params) { -1454 KJUR.asn1.DERBMPString.superclass.constructor.call(this, params); -1455 this.hT = "1e"; -1456 }; -1457 YAHOO.lang.extend(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString); -1458 -1459 // ******************************************************************** -1460 /** -1461 * class for ASN.1 DER UTCTime -1462 * @name KJUR.asn1.DERUTCTime -1463 * @class class for ASN.1 DER UTCTime -1464 * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'}) -1465 * @extends KJUR.asn1.DERAbstractTime -1466 * @description -1467 * <br/> -1468 * As for argument 'params' for constructor, you can specify one of -1469 * following properties: -1470 * <ul> -1471 * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li> -1472 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1473 * <li>date - specify Date object.</li> -1474 * </ul> -1475 * NOTE: 'params' can be omitted. -1476 * <h4>EXAMPLES</h4> -1477 * @example -1478 * d1 = new KJUR.asn1.DERUTCTime(); -1479 * d1.setString('130430125959Z'); -1480 * -1481 * d2 = new KJUR.asn1.DERUTCTime({'str': '130430125959Z'}); -1482 * d3 = new KJUR.asn1.DERUTCTime({'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))}); -1483 * d4 = new KJUR.asn1.DERUTCTime('130430125959Z'); -1484 */ -1485 KJUR.asn1.DERUTCTime = function(params) { -1486 KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params); -1487 this.hT = "17"; -1488 -1489 /** -1490 * set value by a Date object<br/> -1491 * @name setByDate -1492 * @memberOf KJUR.asn1.DERUTCTime# -1493 * @function -1494 * @param {Date} dateObject Date object to set ASN.1 value(V) -1495 * @example -1496 * o = new KJUR.asn1.DERUTCTime(); -1497 * o.setByDate(new Date("2016/12/31")); -1498 */ -1499 this.setByDate = function(dateObject) { -1500 this.hTLV = null; -1501 this.isModified = true; -1502 this.date = dateObject; -1503 this.s = this.formatDate(this.date, 'utc'); -1504 this.hV = stohex(this.s); -1505 }; -1506 -1507 this.getFreshValueHex = function() { -1508 if (typeof this.date == "undefined" && typeof this.s == "undefined") { -1509 this.date = new Date(); -1510 this.s = this.formatDate(this.date, 'utc'); -1511 this.hV = stohex(this.s); -1512 } -1513 return this.hV; -1514 }; -1515 -1516 if (params !== undefined) { -1517 if (params.str !== undefined) { -1518 this.setString(params.str); -1519 } else if (typeof params == "string" && params.match(/^[0-9]{12}Z$/)) { -1520 this.setString(params); -1521 } else if (params.hex !== undefined) { -1522 this.setStringHex(params.hex); -1523 } else if (params.date !== undefined) { -1524 this.setByDate(params.date); -1525 } -1526 } -1527 }; -1528 YAHOO.lang.extend(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime); -1529 -1530 // ******************************************************************** -1531 /** -1532 * class for ASN.1 DER GeneralizedTime -1533 * @name KJUR.asn1.DERGeneralizedTime -1534 * @class class for ASN.1 DER GeneralizedTime -1535 * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'}) -1536 * @property {Boolean} withMillis flag to show milliseconds or not -1537 * @extends KJUR.asn1.DERAbstractTime -1538 * @description -1539 * <br/> -1540 * As for argument 'params' for constructor, you can specify one of -1541 * following properties: -1542 * <ul> -1543 * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li> -1544 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1545 * <li>date - specify Date object.</li> -1546 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> -1547 * </ul> -1548 * NOTE1: 'params' can be omitted. -1549 * NOTE2: 'withMillis' property is supported from asn1 1.0.6. -1550 */ -1551 KJUR.asn1.DERGeneralizedTime = function(params) { -1552 KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params); -1553 this.hT = "18"; -1554 this.withMillis = false; -1555 -1556 /** -1557 * set value by a Date object -1558 * @name setByDate -1559 * @memberOf KJUR.asn1.DERGeneralizedTime# -1560 * @function -1561 * @param {Date} dateObject Date object to set ASN.1 value(V) -1562 * @example -1563 * When you specify UTC time, use 'Date.UTC' method like this:<br/> -1564 * o1 = new DERUTCTime(); -1565 * o1.setByDate(date); -1566 * -1567 * date = new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)); #2015JAN31 23:59:59 -1568 */ -1569 this.setByDate = function(dateObject) { -1570 this.hTLV = null; -1571 this.isModified = true; -1572 this.date = dateObject; -1573 this.s = this.formatDate(this.date, 'gen', this.withMillis); -1574 this.hV = stohex(this.s); -1575 }; -1576 -1577 this.getFreshValueHex = function() { -1578 if (this.date === undefined && this.s === undefined) { -1579 this.date = new Date(); -1580 this.s = this.formatDate(this.date, 'gen', this.withMillis); -1581 this.hV = stohex(this.s); -1582 } -1583 return this.hV; -1584 }; -1585 -1586 if (params !== undefined) { -1587 if (params.str !== undefined) { -1588 this.setString(params.str); -1589 } else if (typeof params == "string" && params.match(/^[0-9]{14}Z$/)) { -1590 this.setString(params); -1591 } else if (params.hex !== undefined) { -1592 this.setStringHex(params.hex); -1593 } else if (params.date !== undefined) { -1594 this.setByDate(params.date); -1595 } -1596 if (params.millis === true) { -1597 this.withMillis = true; -1598 } -1599 } -1600 }; -1601 YAHOO.lang.extend(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime); -1602 -1603 // ******************************************************************** -1604 /** -1605 * class for ASN.1 DER Sequence -1606 * @name KJUR.asn1.DERSequence -1607 * @class class for ASN.1 DER Sequence -1608 * @extends KJUR.asn1.DERAbstractStructured -1609 * @description -1610 * <br/> -1611 * As for argument 'params' for constructor, you can specify one of -1612 * following properties: -1613 * <ul> -1614 * <li>array - specify array of ASN1Object to set elements of content</li> -1615 * </ul> -1616 * NOTE: 'params' can be omitted. -1617 */ -1618 KJUR.asn1.DERSequence = function(params) { -1619 KJUR.asn1.DERSequence.superclass.constructor.call(this, params); -1620 this.hT = "30"; -1621 this.getFreshValueHex = function() { -1622 var h = ''; -1623 for (var i = 0; i < this.asn1Array.length; i++) { -1624 var asn1Obj = this.asn1Array[i]; -1625 h += asn1Obj.getEncodedHex(); -1626 } -1627 this.hV = h; -1628 return this.hV; -1629 }; -1630 }; -1631 YAHOO.lang.extend(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured); -1632 -1633 // ******************************************************************** -1634 /** -1635 * class for ASN.1 DER Set -1636 * @name KJUR.asn1.DERSet -1637 * @class class for ASN.1 DER Set -1638 * @extends KJUR.asn1.DERAbstractStructured -1639 * @description -1640 * <br/> -1641 * As for argument 'params' for constructor, you can specify one of -1642 * following properties: -1643 * <ul> -1644 * <li>array - specify array of ASN1Object to set elements of content</li> -1645 * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li> -1646 * </ul> -1647 * NOTE1: 'params' can be omitted.<br/> -1648 * NOTE2: sortflag is supported since 1.0.5. -1649 */ -1650 KJUR.asn1.DERSet = function(params) { -1651 KJUR.asn1.DERSet.superclass.constructor.call(this, params); -1652 this.hT = "31"; -1653 this.sortFlag = true; // item shall be sorted only in ASN.1 DER -1654 this.getFreshValueHex = function() { -1655 var a = new Array(); -1656 for (var i = 0; i < this.asn1Array.length; i++) { -1657 var asn1Obj = this.asn1Array[i]; -1658 a.push(asn1Obj.getEncodedHex()); -1659 } -1660 if (this.sortFlag == true) a.sort(); -1661 this.hV = a.join(''); -1662 return this.hV; -1663 }; -1664 -1665 if (typeof params != "undefined") { -1666 if (typeof params.sortflag != "undefined" && -1667 params.sortflag == false) -1668 this.sortFlag = false; -1669 } -1670 }; -1671 YAHOO.lang.extend(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured); +1245 this.setValueNameOrOid = function(nameOrOid) { +1246 if (nameOrOid.match(/^[0-2].[0-9.]+$/)) { +1247 this.setValueOidString(nameOrOid); +1248 } else { +1249 this.setValueName(nameOrOid); +1250 } +1251 } +1252 +1253 this.getFreshValueHex = function() { +1254 return this.hV; +1255 }; +1256 +1257 this.setByParam = function(params) { +1258 if (typeof params === "string") { +1259 this.setValueNameOrOid(params); +1260 } else if (params.oid !== undefined) { +1261 this.setValueNameOrOid(params.oid); +1262 } else if (params.name !== undefined) { +1263 this.setValueNameOrOid(params.name); +1264 } else if (params.hex !== undefined) { +1265 this.setValueHex(params.hex); +1266 } +1267 }; +1268 +1269 if (params !== undefined) this.setByParam(params); +1270 }; +1271 YAHOO.lang.extend(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object); +1272 +1273 // ******************************************************************** +1274 /** +1275 * class for ASN.1 DER Enumerated +1276 * @name KJUR.asn1.DEREnumerated +1277 * @class class for ASN.1 DER Enumerated +1278 * @extends KJUR.asn1.ASN1Object +1279 * @description +1280 * <br/> +1281 * As for argument 'params' for constructor, you can specify one of +1282 * following properties: +1283 * <ul> +1284 * <li>int - specify initial ASN.1 value(V) by integer value</li> +1285 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> +1286 * </ul> +1287 * NOTE: 'params' can be omitted. +1288 * @example +1289 * new KJUR.asn1.DEREnumerated(123); +1290 * new KJUR.asn1.DEREnumerated({int: 123}); +1291 * new KJUR.asn1.DEREnumerated({hex: '1fad'}); +1292 */ +1293 KJUR.asn1.DEREnumerated = function(params) { +1294 KJUR.asn1.DEREnumerated.superclass.constructor.call(this); +1295 this.hT = "0a"; +1296 +1297 /** +1298 * set value by Tom Wu's BigInteger object +1299 * @name setByBigInteger +1300 * @memberOf KJUR.asn1.DEREnumerated# +1301 * @function +1302 * @param {BigInteger} bigIntegerValue to set +1303 */ +1304 this.setByBigInteger = function(bigIntegerValue) { +1305 this.hTLV = null; +1306 this.isModified = true; +1307 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); +1308 }; +1309 +1310 /** +1311 * set value by integer value +1312 * @name setByInteger +1313 * @memberOf KJUR.asn1.DEREnumerated# +1314 * @function +1315 * @param {Integer} integer value to set +1316 */ +1317 this.setByInteger = function(intValue) { +1318 var bi = new BigInteger(String(intValue), 10); +1319 this.setByBigInteger(bi); +1320 }; +1321 +1322 /** +1323 * set value by integer value +1324 * @name setValueHex +1325 * @memberOf KJUR.asn1.DEREnumerated# +1326 * @function +1327 * @param {String} hexadecimal string of integer value +1328 * @description +1329 * <br/> +1330 * NOTE: Value shall be represented by minimum octet length of +1331 * two's complement representation. +1332 */ +1333 this.setValueHex = function(newHexString) { +1334 this.hV = newHexString; +1335 }; +1336 +1337 this.getFreshValueHex = function() { +1338 return this.hV; +1339 }; +1340 +1341 if (typeof params != "undefined") { +1342 if (typeof params['int'] != "undefined") { +1343 this.setByInteger(params['int']); +1344 } else if (typeof params == "number") { +1345 this.setByInteger(params); +1346 } else if (typeof params['hex'] != "undefined") { +1347 this.setValueHex(params['hex']); +1348 } +1349 } +1350 }; +1351 YAHOO.lang.extend(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object); +1352 +1353 // ******************************************************************** +1354 /** +1355 * class for ASN.1 DER UTF8String +1356 * @name KJUR.asn1.DERUTF8String +1357 * @class class for ASN.1 DER UTF8String +1358 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1359 * @extends KJUR.asn1.DERAbstractString +1360 * @description +1361 * @see KJUR.asn1.DERAbstractString - superclass +1362 */ +1363 KJUR.asn1.DERUTF8String = function(params) { +1364 KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params); +1365 this.hT = "0c"; +1366 }; +1367 YAHOO.lang.extend(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString); +1368 +1369 // ******************************************************************** +1370 /** +1371 * class for ASN.1 DER NumericString +1372 * @name KJUR.asn1.DERNumericString +1373 * @class class for ASN.1 DER NumericString +1374 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1375 * @extends KJUR.asn1.DERAbstractString +1376 * @description +1377 * @see KJUR.asn1.DERAbstractString - superclass +1378 */ +1379 KJUR.asn1.DERNumericString = function(params) { +1380 KJUR.asn1.DERNumericString.superclass.constructor.call(this, params); +1381 this.hT = "12"; +1382 }; +1383 YAHOO.lang.extend(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString); +1384 +1385 // ******************************************************************** +1386 /** +1387 * class for ASN.1 DER PrintableString +1388 * @name KJUR.asn1.DERPrintableString +1389 * @class class for ASN.1 DER PrintableString +1390 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1391 * @extends KJUR.asn1.DERAbstractString +1392 * @description +1393 * @see KJUR.asn1.DERAbstractString - superclass +1394 */ +1395 KJUR.asn1.DERPrintableString = function(params) { +1396 KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params); +1397 this.hT = "13"; +1398 }; +1399 YAHOO.lang.extend(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString); +1400 +1401 // ******************************************************************** +1402 /** +1403 * class for ASN.1 DER TeletexString +1404 * @name KJUR.asn1.DERTeletexString +1405 * @class class for ASN.1 DER TeletexString +1406 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1407 * @extends KJUR.asn1.DERAbstractString +1408 * @description +1409 * @see KJUR.asn1.DERAbstractString - superclass +1410 */ +1411 KJUR.asn1.DERTeletexString = function(params) { +1412 KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params); +1413 this.hT = "14"; +1414 }; +1415 YAHOO.lang.extend(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString); +1416 +1417 // ******************************************************************** +1418 /** +1419 * class for ASN.1 DER IA5String +1420 * @name KJUR.asn1.DERIA5String +1421 * @class class for ASN.1 DER IA5String +1422 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1423 * @extends KJUR.asn1.DERAbstractString +1424 * @description +1425 * @see KJUR.asn1.DERAbstractString - superclass +1426 */ +1427 KJUR.asn1.DERIA5String = function(params) { +1428 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); +1429 this.hT = "16"; +1430 }; +1431 YAHOO.lang.extend(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString); +1432 +1433 // ******************************************************************** +1434 /** +1435 * class for ASN.1 DER VisibleString +1436 * @name KJUR.asn1.DERVisibleString +1437 * @class class for ASN.1 DER VisibleString +1438 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1439 * @extends KJUR.asn1.DERAbstractString +1440 * @since jsrsasign 8.0.23 asn1 1.0.15 +1441 * @description +1442 * @see KJUR.asn1.DERAbstractString - superclass +1443 */ +1444 KJUR.asn1.DERVisibleString = function(params) { +1445 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); +1446 this.hT = "1a"; +1447 }; +1448 YAHOO.lang.extend(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString); +1449 +1450 // ******************************************************************** +1451 /** +1452 * class for ASN.1 DER BMPString +1453 * @name KJUR.asn1.DERBMPString +1454 * @class class for ASN.1 DER BMPString +1455 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1456 * @extends KJUR.asn1.DERAbstractString +1457 * @since jsrsasign 8.0.23 asn1 1.0.15 +1458 * @description +1459 * @see KJUR.asn1.DERAbstractString - superclass +1460 */ +1461 KJUR.asn1.DERBMPString = function(params) { +1462 KJUR.asn1.DERBMPString.superclass.constructor.call(this, params); +1463 this.hT = "1e"; +1464 }; +1465 YAHOO.lang.extend(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString); +1466 +1467 // ******************************************************************** +1468 /** +1469 * class for ASN.1 DER UTCTime +1470 * @name KJUR.asn1.DERUTCTime +1471 * @class class for ASN.1 DER UTCTime +1472 * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'}) +1473 * @extends KJUR.asn1.DERAbstractTime +1474 * @description +1475 * <br/> +1476 * As for argument 'params' for constructor, you can specify one of +1477 * following properties: +1478 * <ul> +1479 * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li> +1480 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> +1481 * <li>date - specify Date object.</li> +1482 * </ul> +1483 * NOTE: 'params' can be omitted. +1484 * <h4>EXAMPLES</h4> +1485 * @example +1486 * d1 = new KJUR.asn1.DERUTCTime(); +1487 * d1.setString('130430125959Z'); +1488 * +1489 * d2 = new KJUR.asn1.DERUTCTime({'str': '130430125959Z'}); +1490 * d3 = new KJUR.asn1.DERUTCTime({'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))}); +1491 * d4 = new KJUR.asn1.DERUTCTime('130430125959Z'); +1492 */ +1493 KJUR.asn1.DERUTCTime = function(params) { +1494 KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params); +1495 this.hT = "17"; +1496 +1497 /** +1498 * set value by a Date object<br/> +1499 * @name setByDate +1500 * @memberOf KJUR.asn1.DERUTCTime# +1501 * @function +1502 * @param {Date} dateObject Date object to set ASN.1 value(V) +1503 * @example +1504 * o = new KJUR.asn1.DERUTCTime(); +1505 * o.setByDate(new Date("2016/12/31")); +1506 */ +1507 this.setByDate = function(dateObject) { +1508 this.hTLV = null; +1509 this.isModified = true; +1510 this.date = dateObject; +1511 this.s = this.formatDate(this.date, 'utc'); +1512 this.hV = stohex(this.s); +1513 }; +1514 +1515 this.getFreshValueHex = function() { +1516 if (typeof this.date == "undefined" && typeof this.s == "undefined") { +1517 this.date = new Date(); +1518 this.s = this.formatDate(this.date, 'utc'); +1519 this.hV = stohex(this.s); +1520 } +1521 return this.hV; +1522 }; +1523 +1524 if (params !== undefined) { +1525 if (params.str !== undefined) { +1526 this.setString(params.str); +1527 } else if (typeof params == "string" && params.match(/^[0-9]{12}Z$/)) { +1528 this.setString(params); +1529 } else if (params.hex !== undefined) { +1530 this.setStringHex(params.hex); +1531 } else if (params.date !== undefined) { +1532 this.setByDate(params.date); +1533 } +1534 } +1535 }; +1536 YAHOO.lang.extend(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime); +1537 +1538 // ******************************************************************** +1539 /** +1540 * class for ASN.1 DER GeneralizedTime +1541 * @name KJUR.asn1.DERGeneralizedTime +1542 * @class class for ASN.1 DER GeneralizedTime +1543 * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'}) +1544 * @property {Boolean} withMillis flag to show milliseconds or not +1545 * @extends KJUR.asn1.DERAbstractTime +1546 * @description +1547 * <br/> +1548 * As for argument 'params' for constructor, you can specify one of +1549 * following properties: +1550 * <ul> +1551 * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li> +1552 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> +1553 * <li>date - specify Date object.</li> +1554 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> +1555 * </ul> +1556 * NOTE1: 'params' can be omitted. +1557 * NOTE2: 'withMillis' property is supported from asn1 1.0.6. +1558 */ +1559 KJUR.asn1.DERGeneralizedTime = function(params) { +1560 KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params); +1561 this.hT = "18"; +1562 this.withMillis = false; +1563 +1564 /** +1565 * set value by a Date object +1566 * @name setByDate +1567 * @memberOf KJUR.asn1.DERGeneralizedTime# +1568 * @function +1569 * @param {Date} dateObject Date object to set ASN.1 value(V) +1570 * @example +1571 * When you specify UTC time, use 'Date.UTC' method like this:<br/> +1572 * o1 = new DERUTCTime(); +1573 * o1.setByDate(date); +1574 * +1575 * date = new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)); #2015JAN31 23:59:59 +1576 */ +1577 this.setByDate = function(dateObject) { +1578 this.hTLV = null; +1579 this.isModified = true; +1580 this.date = dateObject; +1581 this.s = this.formatDate(this.date, 'gen', this.withMillis); +1582 this.hV = stohex(this.s); +1583 }; +1584 +1585 this.getFreshValueHex = function() { +1586 if (this.date === undefined && this.s === undefined) { +1587 this.date = new Date(); +1588 this.s = this.formatDate(this.date, 'gen', this.withMillis); +1589 this.hV = stohex(this.s); +1590 } +1591 return this.hV; +1592 }; +1593 +1594 if (params !== undefined) { +1595 if (params.str !== undefined) { +1596 this.setString(params.str); +1597 } else if (typeof params == "string" && params.match(/^[0-9]{14}Z$/)) { +1598 this.setString(params); +1599 } else if (params.hex !== undefined) { +1600 this.setStringHex(params.hex); +1601 } else if (params.date !== undefined) { +1602 this.setByDate(params.date); +1603 } +1604 if (params.millis === true) { +1605 this.withMillis = true; +1606 } +1607 } +1608 }; +1609 YAHOO.lang.extend(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime); +1610 +1611 // ******************************************************************** +1612 /** +1613 * class for ASN.1 DER Sequence +1614 * @name KJUR.asn1.DERSequence +1615 * @class class for ASN.1 DER Sequence +1616 * @extends KJUR.asn1.DERAbstractStructured +1617 * @description +1618 * <br/> +1619 * As for argument 'params' for constructor, you can specify one of +1620 * following properties: +1621 * <ul> +1622 * <li>array - specify array of ASN1Object to set elements of content</li> +1623 * </ul> +1624 * NOTE: 'params' can be omitted. +1625 */ +1626 KJUR.asn1.DERSequence = function(params) { +1627 KJUR.asn1.DERSequence.superclass.constructor.call(this, params); +1628 this.hT = "30"; +1629 this.getFreshValueHex = function() { +1630 var h = ''; +1631 for (var i = 0; i < this.asn1Array.length; i++) { +1632 var asn1Obj = this.asn1Array[i]; +1633 h += asn1Obj.getEncodedHex(); +1634 } +1635 this.hV = h; +1636 return this.hV; +1637 }; +1638 }; +1639 YAHOO.lang.extend(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured); +1640 +1641 // ******************************************************************** +1642 /** +1643 * class for ASN.1 DER Set +1644 * @name KJUR.asn1.DERSet +1645 * @class class for ASN.1 DER Set +1646 * @extends KJUR.asn1.DERAbstractStructured +1647 * @description +1648 * <br/> +1649 * As for argument 'params' for constructor, you can specify one of +1650 * following properties: +1651 * <ul> +1652 * <li>array - specify array of ASN1Object to set elements of content</li> +1653 * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li> +1654 * </ul> +1655 * NOTE1: 'params' can be omitted.<br/> +1656 * NOTE2: sortflag is supported since 1.0.5. +1657 */ +1658 KJUR.asn1.DERSet = function(params) { +1659 KJUR.asn1.DERSet.superclass.constructor.call(this, params); +1660 this.hT = "31"; +1661 this.sortFlag = true; // item shall be sorted only in ASN.1 DER +1662 this.getFreshValueHex = function() { +1663 var a = new Array(); +1664 for (var i = 0; i < this.asn1Array.length; i++) { +1665 var asn1Obj = this.asn1Array[i]; +1666 a.push(asn1Obj.getEncodedHex()); +1667 } +1668 if (this.sortFlag == true) a.sort(); +1669 this.hV = a.join(''); +1670 return this.hV; +1671 }; 1672 -1673 // ******************************************************************** -1674 /** -1675 * class for ASN.1 DER TaggedObject -1676 * @name KJUR.asn1.DERTaggedObject -1677 * @class class for ASN.1 DER TaggedObject -1678 * @extends KJUR.asn1.ASN1Object -1679 * -1680 * @description -1681 * <br/> -1682 * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object. -1683 * For example, if you find '[1]' tag in a ASN.1 dump, -1684 * 'tagNoHex' will be 'a1'. -1685 * <br/> -1686 * As for optional argument 'params' for constructor, you can specify *ANY* of -1687 * following properties: -1688 * <ul> -1689 * <li>tag - specify tag (default is 'a0' which means [0])</li> -1690 * <li>explicit - specify true if this is explicit tag otherwise false -1691 * (default is 'true').</li> -1692 * <li>obj - specify ASN1Object which is tagged</li> -1693 * <li>tage - specify tag with explicit</li> -1694 * <li>tagi - specify tag with implicit</li> -1695 * </ul> -1696 * -1697 * @example -1698 * new KJUR.asn1.DERTaggedObject({ -1699 * tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit -1700 * }) -1701 * new KJUR.asn1.DERTaggedObject({ -1702 * tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit -1703 * }) -1704 * new KJUR.asn1.DERTaggedObject({ -1705 * tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit -1706 * }) -1707 * -1708 * // to hexadecimal -1709 * d1 = new KJUR.asn1.DERUTF8String({str':'a'}) -1710 * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1}); -1711 * hex = d2.getEncodedHex(); -1712 */ -1713 KJUR.asn1.DERTaggedObject = function(params) { -1714 KJUR.asn1.DERTaggedObject.superclass.constructor.call(this); -1715 -1716 var _KJUR_asn1 = KJUR.asn1; -1717 -1718 this.hT = "a0"; -1719 this.hV = ''; -1720 this.isExplicit = true; -1721 this.asn1Object = null; -1722 -1723 /** -1724 * set value by an ASN1Object -1725 * @name setString -1726 * @memberOf KJUR.asn1.DERTaggedObject# -1727 * @function -1728 * @param {Boolean} isExplicitFlag flag for explicit/implicit tag -1729 * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag -1730 * @param {ASN1Object} asn1Object ASN.1 to encapsulate -1731 */ -1732 this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) { -1733 this.hT = tagNoHex; -1734 this.isExplicit = isExplicitFlag; -1735 this.asn1Object = asn1Object; -1736 if (this.isExplicit) { -1737 this.hV = this.asn1Object.getEncodedHex(); -1738 this.hTLV = null; -1739 this.isModified = true; -1740 } else { -1741 this.hV = null; -1742 this.hTLV = asn1Object.getEncodedHex(); -1743 this.hTLV = this.hTLV.replace(/^../, tagNoHex); -1744 this.isModified = false; -1745 } -1746 }; -1747 -1748 this.getFreshValueHex = function() { -1749 return this.hV; -1750 }; -1751 -1752 this.setByParam = function(params) { -1753 if (params.tag != undefined) { -1754 this.hT = params.tag; -1755 } -1756 if (params.explicit != undefined) { -1757 this.isExplicit = params.explicit; -1758 } -1759 if (params.tage != undefined) { -1760 this.hT = params.tage; -1761 this.isExplicit = true; -1762 } -1763 if (params.tagi != undefined) { -1764 this.hT = params.tagi; -1765 this.isExplicit = false; -1766 } -1767 if (params.obj != undefined) { -1768 if (params.obj instanceof _KJUR_asn1.ASN1Object) { -1769 this.asn1Object = params.obj; -1770 this.setASN1Object(this.isExplicit, this.hT, this.asn1Object); -1771 } else if (typeof params.obj == "object") { -1772 this.asn1Object = _KJUR_asn1.ASN1Util.newObject(params.obj); -1773 this.setASN1Object(this.isExplicit, this.hT, this.asn1Object); -1774 } -1775 } -1776 }; -1777 -1778 if (params != undefined) this.setByParam(params); -1779 }; -1780 YAHOO.lang.extend(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); -1781