Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclass MXCrypto to enable work-in-progress Rust sdk #1496

Merged
merged 6 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,8 @@
ED44F01528180EAB00452A5D /* MXSharedHistoryKeyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED44F01328180EAB00452A5D /* MXSharedHistoryKeyManager.swift */; };
ED44F01A28180F4000452A5D /* MXSharedHistoryKeyManagerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED44F01728180F1C00452A5D /* MXSharedHistoryKeyManagerUnitTests.swift */; };
ED44F01B28180F4000452A5D /* MXSharedHistoryKeyManagerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED44F01728180F1C00452A5D /* MXSharedHistoryKeyManagerUnitTests.swift */; };
ED47CB6D28523995004FD755 /* MXCryptoV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED47CB6C28523995004FD755 /* MXCryptoV2.swift */; };
ED47CB6E28523995004FD755 /* MXCryptoV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED47CB6C28523995004FD755 /* MXCryptoV2.swift */; };
ED51943928462D130006EEC6 /* MXRoomStateUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED51943828462D130006EEC6 /* MXRoomStateUnitTests.swift */; };
ED51943A28462D130006EEC6 /* MXRoomStateUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED51943828462D130006EEC6 /* MXRoomStateUnitTests.swift */; };
ED51943C284630090006EEC6 /* MXRestClientStub.m in Sources */ = {isa = PBXBuildFile; fileRef = ED51943B284630090006EEC6 /* MXRestClientStub.m */; };
Expand Down Expand Up @@ -2808,6 +2810,7 @@
ED44F01028180BCC00452A5D /* MXSharedHistoryKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXSharedHistoryKeyRequest.swift; sourceTree = "<group>"; };
ED44F01328180EAB00452A5D /* MXSharedHistoryKeyManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXSharedHistoryKeyManager.swift; sourceTree = "<group>"; };
ED44F01728180F1C00452A5D /* MXSharedHistoryKeyManagerUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSharedHistoryKeyManagerUnitTests.swift; sourceTree = "<group>"; };
ED47CB6C28523995004FD755 /* MXCryptoV2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXCryptoV2.swift; sourceTree = "<group>"; };
ED51943828462D130006EEC6 /* MXRoomStateUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXRoomStateUnitTests.swift; sourceTree = "<group>"; };
ED51943B284630090006EEC6 /* MXRestClientStub.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXRestClientStub.m; sourceTree = "<group>"; };
ED51943E284630100006EEC6 /* MXRestClientStub.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXRestClientStub.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3151,6 +3154,7 @@
3252DCAB224BE59E0032264F /* Verification */,
322A51B41D9AB15900C8536D /* MXCrypto.h */,
322A51B51D9AB15900C8536D /* MXCrypto.m */,
ED47CB6C28523995004FD755 /* MXCryptoV2.swift */,
325D1C251DFECE0D0070B8BF /* MXCrypto_Private.h */,
322A51C51D9BBD3C00C8536D /* MXOlmDevice.h */,
322A51C61D9BBD3C00C8536D /* MXOlmDevice.m */,
Expand Down Expand Up @@ -6188,6 +6192,7 @@
B105CDD8261F54C8006EB204 /* MXSpaceChildContent.m in Sources */,
327E9ABD2284521C00A98BC1 /* MXEventUnsignedData.m in Sources */,
32AF9286240EA2430008A0FD /* MXSecretShareRequest.m in Sources */,
ED47CB6D28523995004FD755 /* MXCryptoV2.swift in Sources */,
32A1513A1DAD292400400192 /* MXMegolmEncryption.m in Sources */,
EC60EDFE265CFFD200B39A4E /* MXInvitedGroupSync.m in Sources */,
8EC5110C256822B400EC4E5B /* MXTaggedEvents.m in Sources */,
Expand Down Expand Up @@ -6747,6 +6752,7 @@
B14EF2062397E90400758AF0 /* MXGroup.m in Sources */,
B14EF2072397E90400758AF0 /* MXAutoDiscovery.m in Sources */,
3297913123AA126500F7BB9B /* MXKeyVerificationStatusResolver.m in Sources */,
ED47CB6E28523995004FD755 /* MXCryptoV2.swift in Sources */,
B14EF2082397E90400758AF0 /* MX3PidAddManager.m in Sources */,
ECD2899026EB3B3400F268CF /* MXRoomListData.swift in Sources */,
B14EF2092397E90400758AF0 /* MXCallKitConfiguration.m in Sources */,
Expand Down Expand Up @@ -7237,6 +7243,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "-D DEBUG";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the addition of this flag, otherwise DEBUG macro in Swift is incompatible with the one in objective-c

SDKROOT = "";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 5.0;
Expand Down
21 changes: 20 additions & 1 deletion MatrixSDK/Crypto/MXCrypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ + (MXCrypto *)createCryptoWithMatrixSession:(MXSession *)mxSession
__block MXCrypto *crypto;

#ifdef MX_CRYPTO


#if DEBUG
// If running non-production build AND build flag enabled,
// switch to work-in-progress Rust implementation of crypto.
if (MXSDKOptions.sharedInstance.enableCryptoV2)
{
return [[MXCryptoV2 alloc] init];
}
#endif

dispatch_queue_t cryptoQueue = [MXCrypto dispatchQueueForUser:mxSession.matrixRestClient.credentials.userId];
dispatch_sync(cryptoQueue, ^{

Expand All @@ -161,6 +170,16 @@ + (MXCrypto *)createCryptoWithMatrixSession:(MXSession *)mxSession
+ (void)checkCryptoWithMatrixSession:(MXSession*)mxSession complete:(void (^)(MXCrypto *crypto))complete
{
#ifdef MX_CRYPTO

#if DEBUG
// If running non-production build AND build flag enabled,
// switch to work-in-progress Rust implementation of crypto.
if (MXSDKOptions.sharedInstance.enableCryptoV2)
{
complete([[MXCryptoV2 alloc] init]);
return;
}
#endif

MXLogDebug(@"[MXCrypto] checkCryptoWithMatrixSession for %@", mxSession.matrixRestClient.credentials.userId);

Expand Down
Loading