Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 7, 2014
1 parent a4174d1 commit d6bfbac
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 265 deletions.
26 changes: 9 additions & 17 deletions bcrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,13 @@
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 52, 53, -1, -1, -1, -1, -1];

/**
* Length-delimited base64 encoder and decoder.
* @type {Object.<string,function(string, number)>}
* @private
*/
var base64 = {};

/**
* Encodes a byte array to base64 with up to len bytes of input.
* @param {Array.<number>} b Byte array
* @param {number} len Maximum input length
* @returns {string}
* @private
*/
base64.encode = function(b, len) {
function base64_encode(b, len) {
var off = 0;
var rs = [];
var c1;
Expand Down Expand Up @@ -103,16 +95,15 @@
rs.push(BASE64_CODE[c2 & 0x3f]);
}
return rs.join('');
};
}

/**
* Decodes a base64 encoded string to up to len bytes of output.
* @param {string} s String to decode
* @param {number} len Maximum output length
* @returns {Array.<number>}
* @private
*/
base64.decode = function(s, len) {
function base64_decode(s, len) {
var off = 0;
var slen = s.length;
var olen = 0;
Expand Down Expand Up @@ -156,7 +147,8 @@
res.push(rs[off].charCodeAt(0));
}
return res;
};
}

// ref: http://mths.be/fromcodepoint v0.1.0 by @mathias
/* if (!String.fromCodePoint) {
(function () {
Expand Down Expand Up @@ -843,7 +835,7 @@

var passwordb = _stringToBytes(s);
var saltb = [];
saltb = base64.decode(real_salt, BCRYPT_SALT_LEN);
saltb = base64_decode(real_salt, BCRYPT_SALT_LEN);

/**
* Finishs hashing.
Expand All @@ -859,8 +851,8 @@
if (rounds < 10) res.push("0");
res.push(rounds.toString());
res.push("$");
res.push(base64.encode(saltb, saltb.length));
res.push(base64.encode(bytes, C_ORIG.length * 4 - 1));
res.push(base64_encode(saltb, saltb.length));
res.push(base64_encode(bytes, C_ORIG.length * 4 - 1));
return res.join('');
}

Expand Down Expand Up @@ -925,7 +917,7 @@
salt.push(rounds.toString());
salt.push('$');
try {
salt.push(base64.encode(_randomBytes(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN));
salt.push(base64_encode(_randomBytes(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN));
return salt.join('');
} catch(err) {
throw(err);
Expand Down
Loading

0 comments on commit d6bfbac

Please sign in to comment.