Skip to content

Commit 682f62c

Browse files
committed
Expose internal base64 encoder on top of the bcrypt namespace + tests, fixes #23
1 parent 1b9770e commit 682f62c

7 files changed

Lines changed: 365 additions & 327 deletions

File tree

dist/bcrypt.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@
3131
* Released under the Apache License, Version 2.0
3232
* see: https://github.com/dcodeIO/bcrypt.js for details
3333
*/
34-
(function(global) {
34+
(function(global, factory) {
35+
36+
/* AMD */ if (typeof define === 'function' && define["amd"])
37+
define([], factory);
38+
/* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"])
39+
module["exports"] = factory();
40+
/* Global */ else
41+
(global["dcodeIO"] = global["dcodeIO"] || {})["bcrypt"] = factory();
42+
43+
}(this, function() {
3544
"use strict";
3645

3746
/**
@@ -1169,12 +1178,25 @@
11691178
}
11701179
}
11711180

1181+
/**
1182+
* Encodes a byte array to base64 with up to len bytes of input, using the custom bcrypt alphabet.
1183+
* @function
1184+
* @param {!Array.<number>} b Byte array
1185+
* @param {number} len Maximum input length
1186+
* @returns {string}
1187+
* @expose
1188+
*/
1189+
bcrypt.encodeBase64 = base64_encode;
11721190

1173-
/* CommonJS */ if (typeof module !== 'undefined' && module["exports"])
1174-
module["exports"] = bcrypt;
1175-
/* AMD */ else if (typeof define !== 'undefined' && define["amd"])
1176-
define(function() { return bcrypt; });
1177-
/* Global */ else
1178-
(global["dcodeIO"] = global["dcodeIO"] || {})["bcrypt"] = bcrypt;
1191+
/**
1192+
* Decodes a base64 encoded string to up to len bytes of output, using the custom bcrypt alphabet.
1193+
* @function
1194+
* @param {string} s String to decode
1195+
* @param {number} len Maximum output length
1196+
* @returns {!Array.<number>}
1197+
* @expose
1198+
*/
1199+
bcrypt.decodeBase64 = base64_decode;
11791200

1180-
})(this);
1201+
return bcrypt;
1202+
}));

dist/bcrypt.min.js

Lines changed: 40 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bcrypt.min.map

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var scope = {
1717
console.log("Building bcrypt.js with scope", JSON.stringify(scope, null, 2));
1818
fs.writeFileSync(
1919
path.join(distDir, "bcrypt.js"),
20-
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "bcrypt.js")), filename, scope, srcDir)
20+
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir)
2121
);
2222

2323
// Make isaac build - see: https://github.com/dcodeIO/bcrypt.js/issues/16

0 commit comments

Comments
 (0)