|
59 | 59 | 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, |
60 | 60 | 49, 50, 51, 52, 53, -1, -1, -1, -1, -1]; |
61 | 61 |
|
62 | | - /** |
63 | | - * Length-delimited base64 encoder and decoder. |
64 | | - * @type {Object.<string,function(string, number)>} |
65 | | - * @private |
66 | | - */ |
67 | | - var base64 = {}; |
68 | | - |
69 | 62 | /** |
70 | 63 | * Encodes a byte array to base64 with up to len bytes of input. |
71 | 64 | * @param {Array.<number>} b Byte array |
72 | 65 | * @param {number} len Maximum input length |
73 | 66 | * @returns {string} |
74 | | - * @private |
75 | 67 | */ |
76 | | - base64.encode = function(b, len) { |
| 68 | + function base64_encode(b, len) { |
77 | 69 | var off = 0; |
78 | 70 | var rs = []; |
79 | 71 | var c1; |
|
103 | 95 | rs.push(BASE64_CODE[c2 & 0x3f]); |
104 | 96 | } |
105 | 97 | return rs.join(''); |
106 | | - }; |
| 98 | + } |
107 | 99 |
|
108 | 100 | /** |
109 | 101 | * Decodes a base64 encoded string to up to len bytes of output. |
110 | 102 | * @param {string} s String to decode |
111 | 103 | * @param {number} len Maximum output length |
112 | 104 | * @returns {Array.<number>} |
113 | | - * @private |
114 | 105 | */ |
115 | | - base64.decode = function(s, len) { |
| 106 | + function base64_decode(s, len) { |
116 | 107 | var off = 0; |
117 | 108 | var slen = s.length; |
118 | 109 | var olen = 0; |
|
156 | 147 | res.push(rs[off].charCodeAt(0)); |
157 | 148 | } |
158 | 149 | return res; |
159 | | - }; |
| 150 | + } |
| 151 | + |
160 | 152 | // ref: http://mths.be/fromcodepoint v0.1.0 by @mathias |
161 | 153 | /* if (!String.fromCodePoint) { |
162 | 154 | (function () { |
|
843 | 835 |
|
844 | 836 | var passwordb = _stringToBytes(s); |
845 | 837 | var saltb = []; |
846 | | - saltb = base64.decode(real_salt, BCRYPT_SALT_LEN); |
| 838 | + saltb = base64_decode(real_salt, BCRYPT_SALT_LEN); |
847 | 839 |
|
848 | 840 | /** |
849 | 841 | * Finishs hashing. |
|
859 | 851 | if (rounds < 10) res.push("0"); |
860 | 852 | res.push(rounds.toString()); |
861 | 853 | res.push("$"); |
862 | | - res.push(base64.encode(saltb, saltb.length)); |
863 | | - res.push(base64.encode(bytes, C_ORIG.length * 4 - 1)); |
| 854 | + res.push(base64_encode(saltb, saltb.length)); |
| 855 | + res.push(base64_encode(bytes, C_ORIG.length * 4 - 1)); |
864 | 856 | return res.join(''); |
865 | 857 | } |
866 | 858 |
|
|
925 | 917 | salt.push(rounds.toString()); |
926 | 918 | salt.push('$'); |
927 | 919 | try { |
928 | | - salt.push(base64.encode(_randomBytes(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN)); |
| 920 | + salt.push(base64_encode(_randomBytes(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN)); |
929 | 921 | return salt.join(''); |
930 | 922 | } catch(err) { |
931 | 923 | throw(err); |
|
0 commit comments