Skip to content

Commit d8699d4

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 d8699d4

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

binding.gyp

Lines changed: 22 additions & 2 deletions
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',
@@ -8,8 +12,24 @@
812
'sources': [
913
'src/blowfish.cc',
1014
'src/bcrypt.cc',
11-
'src/bcrypt_node.cc'
12-
]
15+
'src/bcrypt_node.cc',
16+
'src/node_blf.h'
17+
],
18+
'conditions': [
19+
[ 'OS=="win"', {
20+
'defines': [
21+
'uint=unsigned int',
22+
# we need to use node's preferred "win32" rather than gyp's preferred "win"
23+
'PLATFORM="win32"',
24+
],
25+
'libraries': [
26+
'-l<(openssl_Root)/lib/libeay32.lib',
27+
],
28+
'include_dirs': [
29+
'<(openssl_Root)/include',
30+
],
31+
}],
32+
],
1333
}
1434
]
1535
}

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)