Skip to content

Commit

Permalink
Fixed environment detection in web worker.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzcoder committed Jan 31, 2016
1 parent f637c44 commit fb40aed
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-rsa",
"version": "0.3.1",
"version": "0.3.2",
"description": "Node.js RSA library",
"main": "src/NodeRSA.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/NodeRSA.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ module.exports = (function () {

/**
* Exporting key
* @param format {string}
* @param [format] {string}
*/
NodeRSA.prototype.exportKey = function (format) {
format = format || DEFAULT_EXPORT_FORMAT;
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/pkcs1.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module.exports.makeScheme = function (key, options) {

Scheme.prototype.sign = function (buffer) {
var hashAlgorithm = this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION;
if (this.options.environment == 'browser') {
if (this.options.environment === 'browser') {
hashAlgorithm = SIGN_ALG_TO_HASH_ALIASES[hashAlgorithm] || hashAlgorithm;

var hasher = crypt.createHash(hashAlgorithm);
Expand All @@ -132,7 +132,7 @@ module.exports.makeScheme = function (key, options) {

Scheme.prototype.verify = function (buffer, signature, signature_encoding) {
var hashAlgorithm = this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION;
if (this.options.environment == 'browser') {
if (this.options.environment === 'browser') {
hashAlgorithm = SIGN_ALG_TO_HASH_ALIASES[hashAlgorithm] || hashAlgorithm;

if (signature_encoding) {
Expand Down
7 changes: 3 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var crypt = require('crypto');
* @returns {string}
*/
module.exports.linebrk = function (str, maxLen) {
var res = "";
var res = '';
var i = 0;
while (i + maxLen < str.length) {
res += str.substring(i, i + maxLen) + "\n";
Expand All @@ -22,11 +22,10 @@ module.exports.linebrk = function (str, maxLen) {
};

module.exports.detectEnvironment = function () {
if (process && process.title != 'browser') {
return 'node';
} else if (typeof(window) !== 'undefined' && window) {
if (process && process.title === 'browser' || (typeof(window) !== 'undefined' && window)) {
return 'browser';
}

return 'node';
};

Expand Down

0 comments on commit fb40aed

Please sign in to comment.