Skip to content

Commit 0357a0e

Browse files
committed
Windows compatibility
- Win32 code - updating binding.gyp to work with Windows expects user to have downloaded OpenSSL-Win32 from http://slproweb.com/products/Win32OpenSSL.html and installed in default location, C:/OpenSSL-Win32
1 parent 0f43c88 commit 0357a0e

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

binding.gyp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
'variables': {
3+
# The default install location of OpenSSL-Win32
4+
'openssl_Root': 'C:/OpenSSL-Win32'
5+
},
26
'targets': [
37
{
48
'target_name': 'bcrypt_lib',
@@ -9,7 +13,22 @@
913
'src/blowfish.cc',
1014
'src/bcrypt.cc',
1115
'src/bcrypt_node.cc'
12-
]
16+
],
17+
'conditions': [
18+
[ 'OS=="win"', {
19+
'defines': [
20+
'uint=unsigned int',
21+
# we need to use node's preferred "win32" rather than gyp's preferred "win"
22+
'PLATFORM="win32"',
23+
],
24+
'libraries': [
25+
'-l<(openssl_Root)/lib/libeay32.lib',
26+
],
27+
'include_dirs': [
28+
'<(openssl_Root)/include',
29+
],
30+
}],
31+
],
1332
}
1433
]
1534
}

src/bcrypt.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@
4949
#include <stdlib.h>
5050
#include <sys/types.h>
5151
#include <string.h>
52-
#include <pwd.h>
5352
#include "node_blf.h"
5453

54+
#ifdef _WIN32
55+
#define snprintf _snprintf
56+
#endif
57+
5558
//#if !defined(__APPLE__) && !defined(__MACH__)
5659
//#include "bsd/stdlib.h"
5760
//#endif

src/bcrypt_node.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ static void crypto_lock_init(void) {
6969

7070
static void crypto_lock_cb(int mode, int n, const char* file, int line) {
7171
if (mode & CRYPTO_LOCK)
72-
WaitForSingleObject(locks[type], INFINITE);
72+
WaitForSingleObject(locks[n], INFINITE);
7373
else
74-
ReleaseMutex(locks[type]);
74+
ReleaseMutex(locks[n]);
7575
}
7676

7777
static unsigned long crypto_id_cb(void) {
@@ -475,3 +475,4 @@ extern "C" void init(Handle<Object> target) {
475475
NODE_SET_METHOD(target, "compare", Compare);
476476
};
477477

478+
NODE_MODULE(bcrypt_lib, init);

src/node_blf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
#define u_int64_t uint64_t
4343
#endif
4444

45+
#ifdef _WIN32
46+
#define u_int8_t unsigned __int8
47+
#define u_int16_t unsigned __int16
48+
#define u_int32_t unsigned __int32
49+
#define u_int64_t unsigned __int64
50+
#endif
51+
4552
#define BCRYPT_VERSION '2'
4653
#define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */
4754
#define BCRYPT_BLOCKS 6 /* Ciphertext blocks */

0 commit comments

Comments
 (0)