diff --git a/native/android/app/CMakeLists.txt b/native/android/app/CMakeLists.txt --- a/native/android/app/CMakeLists.txt +++ b/native/android/app/CMakeLists.txt @@ -131,6 +131,7 @@ list(APPEND RUST_NATIVE_CODE "../../native_rust_library/RustCallback.cpp" "../../native_rust_library/RustAESCrypto.cpp" + "../../native_rust_library/RustSecureStore.cpp" ) file(GLOB CRYPTO_NATIVE_CODE "../../cpp/CommonCpp/CryptoTools/*.cpp") file(GLOB DB_NATIVE_CODE "../../cpp/CommonCpp/DatabaseManagers/*.cpp") diff --git a/native/ios/Comm.xcodeproj/project.pbxproj b/native/ios/Comm.xcodeproj/project.pbxproj --- a/native/ios/Comm.xcodeproj/project.pbxproj +++ b/native/ios/Comm.xcodeproj/project.pbxproj @@ -84,6 +84,7 @@ D7DB6E0F85B2DBE15B01EC21 /* libPods-Comm.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 994BEBDD4E4959F69CEA0BC3 /* libPods-Comm.a */; }; DFD5E77E2B05264000C32B6A /* AESCrypto.mm in Sources */ = {isa = PBXBuildFile; fileRef = DFD5E77D2B05264000C32B6A /* AESCrypto.mm */; }; DFD5E7862B052B1400C32B6A /* RustAESCrypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFD5E7842B052B1400C32B6A /* RustAESCrypto.cpp */; }; + DFD5E77C2B05181400C32B6A /* RustSecureStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFD5E77B2B05181400C32B6A /* RustSecureStore.cpp */; }; F02C296C528B51ADAB5AA19D /* libPods-NotificationService.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EE4DCB430B05EC9DE7D7B01 /* libPods-NotificationService.a */; }; /* End PBXBuildFile section */ @@ -279,6 +280,8 @@ DFD5E7802B05264F00C32B6A /* AESCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AESCrypto.h; sourceTree = ""; }; DFD5E7842B052B1400C32B6A /* RustAESCrypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RustAESCrypto.cpp; sourceTree = ""; }; DFD5E7852B052B1400C32B6A /* RustAESCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RustAESCrypto.h; sourceTree = ""; }; + DFD5E77A2B05181400C32B6A /* RustSecureStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RustSecureStore.h; sourceTree = ""; }; + DFD5E77B2B05181400C32B6A /* RustSecureStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RustSecureStore.cpp; sourceTree = ""; }; F53DA7B3F26C2798DCE74A94 /* Pods-Comm.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Comm.debug.xcconfig"; path = "Target Support Files/Pods-Comm/Pods-Comm.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -589,6 +592,8 @@ children = ( DFD5E7842B052B1400C32B6A /* RustAESCrypto.cpp */, DFD5E7852B052B1400C32B6A /* RustAESCrypto.h */, + DFD5E77B2B05181400C32B6A /* RustSecureStore.cpp */, + DFD5E77A2B05181400C32B6A /* RustSecureStore.h */, 8B652FA4295EA9F1009F8163 /* RustCallback.h */, 8B99BAAD28D511FF00EB5ADB /* lib.rs.cc */, 8B99AF6D28D50D4800EB5ADB /* lib.rs.h */, @@ -1091,6 +1096,7 @@ 71762A75270D8AAE00F565ED /* PlatformSpecificTools.mm in Sources */, 71BF5B7126B3FF0900EDE27D /* Session.cpp in Sources */, 8EF7756E2A7513F40046A385 /* MessageStore.cpp in Sources */, + DFD5E77C2B05181400C32B6A /* RustSecureStore.cpp in Sources */, 71BF5B7526B401D300EDE27D /* Tools.cpp in Sources */, 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */, 7FE4D9F5291DFE9300667BF6 /* commJSI-generated.cpp in Sources */, diff --git a/native/native_rust_library/RustSecureStore.h b/native/native_rust_library/RustSecureStore.h new file mode 100644 --- /dev/null +++ b/native/native_rust_library/RustSecureStore.h @@ -0,0 +1,10 @@ +#pragma once + +#include "cxx.h" + +namespace comm { + +void secureStoreSet(rust::Str key, rust::String value); +rust::String secureStoreGet(rust::Str key); + +} // namespace comm diff --git a/native/native_rust_library/RustSecureStore.cpp b/native/native_rust_library/RustSecureStore.cpp new file mode 100644 --- /dev/null +++ b/native/native_rust_library/RustSecureStore.cpp @@ -0,0 +1,16 @@ +#include "RustSecureStore.h" +#include "../cpp/CommonCpp/Tools/CommSecureStore.h" +#include "../cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h" +#include "lib.rs.h" + +namespace comm { + +void secureStoreSet(rust::Str key, rust::String value) { + CommSecureStore::set(std::string(key), std::string(value)); +} + +rust::String secureStoreGet(rust::Str key){ + return rust::String(CommSecureStore::get(std::string(key)).value()); +} + +} diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -205,6 +205,20 @@ promise_id: u32, ); } + + // Secure store + #[namespace = "comm"] + unsafe extern "C++" { + include!("RustSecureStore.h"); + + #[allow(unused)] + #[cxx_name = "secureStoreSet"] + fn secure_store_set(key: &str, value: String) -> Result<()>; + + #[allow(unused)] + #[cxx_name = "secureStoreGet"] + fn secure_store_get(key: &str) -> Result; + } } fn handle_string_result_as_callback(