Skip to content

Commit d6bfbac

Browse files
committed
Cleanup
1 parent a4174d1 commit d6bfbac

File tree

6 files changed

+56
-265
lines changed

6 files changed

+56
-265
lines changed

bcrypt.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,13 @@
5959
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
6060
49, 50, 51, 52, 53, -1, -1, -1, -1, -1];
6161

62-
/**
63-
* Length-delimited base64 encoder and decoder.
64-
* @type {Object.<string,function(string, number)>}
65-
* @private
66-
*/
67-
var base64 = {};
68-
6962
/**
7063
* Encodes a byte array to base64 with up to len bytes of input.
7164
* @param {Array.<number>} b Byte array
7265
* @param {number} len Maximum input length
7366
* @returns {string}
74-
* @private
7567
*/
76-
base64.encode = function(b, len) {
68+
function base64_encode(b, len) {
7769
var off = 0;
7870
var rs = [];
7971
var c1;
@@ -103,16 +95,15 @@
10395
rs.push(BASE64_CODE[c2 & 0x3f]);
10496
}
10597
return rs.join('');
106-
};
98+
}
10799

108100
/**
109101
* Decodes a base64 encoded string to up to len bytes of output.
110102
* @param {string} s String to decode
111103
* @param {number} len Maximum output length
112104
* @returns {Array.<number>}
113-
* @private
114105
*/
115-
base64.decode = function(s, len) {
106+
function base64_decode(s, len) {
116107
var off = 0;
117108
var slen = s.length;
118109
var olen = 0;
@@ -156,7 +147,8 @@
156147
res.push(rs[off].charCodeAt(0));
157148
}
158149
return res;
159-
};
150+
}
151+
160152
// ref: http://mths.be/fromcodepoint v0.1.0 by @mathias
161153
/* if (!String.fromCodePoint) {
162154
(function () {
@@ -843,7 +835,7 @@
843835

844836
var passwordb = _stringToBytes(s);
845837
var saltb = [];
846-
saltb = base64.decode(real_salt, BCRYPT_SALT_LEN);
838+
saltb = base64_decode(real_salt, BCRYPT_SALT_LEN);
847839

848840
/**
849841
* Finishs hashing.
@@ -859,8 +851,8 @@
859851
if (rounds < 10) res.push("0");
860852
res.push(rounds.toString());
861853
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));
864856
return res.join('');
865857
}
866858

@@ -925,7 +917,7 @@
925917
salt.push(rounds.toString());
926918
salt.push('$');
927919
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));
929921
return salt.join('');
930922
} catch(err) {
931923
throw(err);

0 commit comments

Comments
 (0)