Skip to content

Commit ba5c337

Browse files
committed
feat: add library and link
1 parent 3e8fb2f commit ba5c337

File tree

9 files changed

+1218
-17
lines changed

9 files changed

+1218
-17
lines changed

android/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
cmake_minimum_required(VERSION 3.4.1)
22
project(BcryptCpp)
33

4-
set (CMAKE_VERBOSE_MAKEFILE ON)
4+
set(CMAKE_VERBOSE_MAKEFILE ON)
55

66
add_compile_options(
77
-fexceptions
88
-frtti
99
-std=c++17
1010
)
1111

12-
add_library(react-native-bcrypt-cpp STATIC
13-
../cpp/NativeBcryptCppTurboModule.cpp
14-
)
12+
# Add bcrypt library
13+
add_library(bcrypt STATIC
14+
../cpp/bcrypt/bcrypt.cpp
15+
../cpp/bcrypt/blowfish.cpp
16+
../cpp/bcrypt/node_blf.h
17+
../cpp/bcrypt/openbsd.h)
18+
19+
add_library(react-native-bcrypt-cpp STATIC
20+
../cpp/NativeBcryptCppTurboModule.cpp)
21+
22+
target_include_directories(bcrypt
23+
PUBLIC
24+
../cpp/bcrypt)
1525

1626
target_include_directories(react-native-bcrypt-cpp
1727
PUBLIC
1828
../cpp
1929
)
2030

2131
target_link_libraries(react-native-bcrypt-cpp
32+
bcrypt
2233
jsi
2334
react_nativemodule_core
2435
react_codegen_RNBcryptCppSpec

android/cpp-adapter.cpp

Lines changed: 0 additions & 8 deletions
This file was deleted.

cpp/NativeBcryptCppTurboModule.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
#include "NativeBcryptCppTurboModule.h"
2+
//#import <QuartzCore/QuartzCore.h>
33

44

55

@@ -15,11 +15,12 @@ jsi::Value NativeBcryptCppTurboModule::validatePassword(jsi::Runtime &rt, std::s
1515
return jsi::Value::undefined();
1616
}
1717
std::string NativeBcryptCppTurboModule::generateHashSync(jsi::Runtime &rt, std::string password, double workload){
18-
19-
return "generateHashSync";
18+
19+
std::string generatedHash = bcrypt::generateHash(password, workload);
20+
return generatedHash;
2021
}
2122
bool NativeBcryptCppTurboModule::validatePasswordSync(jsi::Runtime &rt, std::string password, std::string hash) {
22-
return "validatePasswordSync";
23+
return bcrypt::validatePassword(password, hash);
2324
}
2425

2526
}

cpp/NativeBcryptCppTurboModule.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
#include "RNBcryptCppSpecJSI.h"
55
#endif
66

7+
#if __has_include("bcrypt/bcrypt.h")
8+
#include "bcrypt/bcrypt.h"
9+
#elif __has_include("bcrypt.h")
10+
#include "bcrypt.h"
11+
#endif
12+
713

814
namespace facebook::react {
915
class NativeBcryptCppTurboModule: public NativeBcryptCppCxxSpec<NativeBcryptCppTurboModule> {
1016
public:
1117
NativeBcryptCppTurboModule(std::shared_ptr<CallInvoker> jsInvoker);
12-
18+
1319
jsi::Value generateHash(jsi::Runtime &rt, std::string password, double workload);
1420
jsi::Value validatePassword(jsi::Runtime &rt, std::string password, std::string hash);
1521
std::string generateHashSync(jsi::Runtime &rt, std::string password, double workload);

0 commit comments

Comments
 (0)