Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3380397
D11448.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D11448.diff
View Options
diff --git a/native/cpp/CommonCpp/CryptoTools/Tools.h b/native/cpp/CommonCpp/CryptoTools/Tools.h
--- a/native/cpp/CommonCpp/CryptoTools/Tools.h
+++ b/native/cpp/CommonCpp/CryptoTools/Tools.h
@@ -11,8 +11,6 @@
#define ID_KEYS_PREFIX_OFFSET 15
#define SIGNING_KEYS_PREFIX_OFFSET 71
-#define ENCRYPTED_MESSAGE_TYPE 1
-
namespace comm {
namespace crypto {
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
@@ -125,8 +125,10 @@
jsi::String deviceID) override;
virtual jsi::Value
encrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override;
- virtual jsi::Value
- decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override;
+ virtual jsi::Value decrypt(
+ jsi::Runtime &rt,
+ jsi::Object encryptedDataJSI,
+ jsi::String deviceID) override;
virtual jsi::Value
signMessage(jsi::Runtime &rt, jsi::String message) override;
virtual void terminate(jsi::Runtime &rt) override;
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
@@ -1240,9 +1240,12 @@
jsi::Value CommCoreModule::decrypt(
jsi::Runtime &rt,
- jsi::String message,
+ jsi::Object encryptedDataJSI,
jsi::String deviceID) {
- auto messageCpp{message.utf8(rt)};
+ size_t messageType =
+ std::lround(encryptedDataJSI.getProperty(rt, "messageType").asNumber());
+ std::string message =
+ encryptedDataJSI.getProperty(rt, "message").asString(rt).utf8(rt);
auto deviceIDCpp{deviceID.utf8(rt)};
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
@@ -1251,8 +1254,8 @@
std::string decryptedMessage;
try {
crypto::EncryptedData encryptedData{
- std::vector<uint8_t>(messageCpp.begin(), messageCpp.end()),
- ENCRYPTED_MESSAGE_TYPE};
+ std::vector<uint8_t>(message.begin(), message.end()),
+ messageType};
decryptedMessage =
this->contentCryptoModule->decrypt(deviceIDCpp, encryptedData);
this->persistCryptoModules(true, false);
diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
--- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
+++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
@@ -109,7 +109,7 @@
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->encrypt(rt, args[0].asString(rt), args[1].asString(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_decrypt(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
- return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->decrypt(rt, args[0].asString(rt), args[1].asString(rt));
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->decrypt(rt, args[0].asObject(rt), args[1].asString(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_signMessage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->signMessage(rt, args[0].asString(rt));
diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h
--- a/native/cpp/CommonCpp/_generated/commJSI.h
+++ b/native/cpp/CommonCpp/_generated/commJSI.h
@@ -51,7 +51,7 @@
virtual jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKey, jsi::String deviceID) = 0;
virtual jsi::Value initializeContentInboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String encryptedMessage, jsi::String deviceID) = 0;
virtual jsi::Value encrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0;
- virtual jsi::Value decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0;
+ virtual jsi::Value decrypt(jsi::Runtime &rt, jsi::Object encryptedData, jsi::String deviceID) = 0;
virtual jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) = 0;
virtual double getCodeVersion(jsi::Runtime &rt) = 0;
virtual void terminate(jsi::Runtime &rt) = 0;
@@ -343,13 +343,13 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::encrypt, jsInvoker_, instance_, std::move(message), std::move(deviceID));
}
- jsi::Value decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override {
+ jsi::Value decrypt(jsi::Runtime &rt, jsi::Object encryptedData, jsi::String deviceID) override {
static_assert(
bridging::getParameterCount(&T::decrypt) == 3,
"Expected decrypt(...) to have 3 parameters");
return bridging::callFromJs<jsi::Value>(
- rt, &T::decrypt, jsInvoker_, instance_, std::move(message), std::move(deviceID));
+ rt, &T::decrypt, jsInvoker_, instance_, std::move(encryptedData), std::move(deviceID));
}
jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) override {
static_assert(
diff --git a/native/crypto/olm-api.js b/native/crypto/olm-api.js
--- a/native/crypto/olm-api.js
+++ b/native/crypto/olm-api.js
@@ -6,7 +6,6 @@
type OneTimeKeysResultValues,
type OlmAPI,
type OLMIdentityKeys,
- type EncryptedData,
} from 'lib/types/crypto-types.js';
import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js';
@@ -18,12 +17,7 @@
},
getUserPublicKey: commCoreModule.getUserPublicKey,
encrypt: commCoreModule.encrypt,
- async decrypt(
- encryptedData: EncryptedData,
- deviceID: string,
- ): Promise<string> {
- return commCoreModule.decrypt(encryptedData.message, deviceID);
- },
+ decrypt: commCoreModule.decrypt,
async contentInboundSessionCreator(
contentIdentityKeys: OLMIdentityKeys,
initialEncryptedContent: string,
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -109,7 +109,7 @@
deviceID: string,
) => Promise<string>;
+encrypt: (message: string, deviceID: string) => Promise<EncryptedData>;
- +decrypt: (message: string, deviceID: string) => Promise<string>;
+ +decrypt: (encryptedData: Object, deviceID: string) => Promise<string>;
+signMessage: (message: string) => Promise<string>;
+getCodeVersion: () => number;
+terminate: () => void;
@@ -147,6 +147,7 @@
password: string,
backupID: string,
) => Promise<ArrayBuffer>;
+ +decrypt: (encryptedData: EncryptedData, deviceID: string) => Promise<string>;
}
export default (TurboModuleRegistry.getEnforcing<Spec>(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 11:22 PM (18 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595157
Default Alt Text
D11448.diff (6 KB)
Attached To
Mode
D11448: [native] update `decrypt` method use `EncryptedData`
Attached
Detach File
Event Timeline
Log In to Comment