Skip to content

Commit

Permalink
Mac-compatible MatrixSDKCrypto
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed Oct 11, 2022
1 parent 66df019 commit 296214d
Show file tree
Hide file tree
Showing 38 changed files with 64 additions and 70 deletions.
7 changes: 3 additions & 4 deletions MatrixSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Pod::Spec.new do |s|
ss.dependency 'OLMKit', '~> 3.2.5'
ss.dependency 'Realm', '10.27.0'
ss.dependency 'libbase58', '~> 0.1.4'
ss.ios.dependency 'MatrixSDK/CryptoSDK'
ss.dependency 'MatrixSDK/CryptoSDK'
end

s.subspec 'JingleCallStack' do |ss|
Expand All @@ -64,10 +64,9 @@ Pod::Spec.new do |s|
ss.ios.dependency 'JitsiMeetSDK', '5.0.2'
end

# Experimental / NOT production-ready Rust-based crypto library, iOS-only
# Experimental / NOT production-ready Rust-based crypto library
s.subspec 'CryptoSDK' do |ss|
ss.platform = :ios
ss.dependency 'MatrixSDKCrypto', '0.1.0', :configurations => ["DEBUG"]
ss.dependency 'MatrixSDKCrypto', '0.1.2', :configurations => ["DEBUG"]
end

end
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/CrossSigning/Data/MXCrossSigningInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern NSString *const MXCrossSigningInfoTrustLevelDidChangeNotification;
*/
@interface MXCrossSigningInfo : NSObject <NSCoding>

#if DEBUG && TARGET_OS_IPHONE
#if DEBUG
/**
Initialize cross signing with MatrixSDKCrypto user identity
*/
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/CrossSigning/Data/MXCrossSigningInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@implementation MXCrossSigningInfo

#if DEBUG && TARGET_OS_IPHONE
#if DEBUG
- (instancetype)initWithUserIdentity:(MXCryptoUserIdentityWrapper *)userIdentity
{
self = [self init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

/// Convenience struct which transforms `MatrixSDKCrypto` cross signing info formats
/// into `MatrixSDK` `MXCrossSigningInfo` formats.
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

/// A work-in-progress subclass of `MXCrossSigning` instantiated and used by `MXCryptoV2`.
///
Expand Down
4 changes: 2 additions & 2 deletions MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down Expand Up @@ -693,7 +693,7 @@ extension MXCryptoMachine: MXCryptoBackup {
guard let json = MXTools.serialiseJSONObject(jsonKeys) else {
throw Error.cannotSerialize
}
return try machine.importDecryptedKeys(keys: json, progressListener: progressListener)
return try machine.importDecryptedRoomKeys(keys: json, progressListener: progressListener)
}
}

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/CryptoMachine/MXCryptoProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/CryptoMachine/MXCryptoRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/Devices/Data/MXCryptoDeviceWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/Devices/Data/MXDeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern NSString *const MXDeviceInfoTrustLevelDidChangeNotification;

- (instancetype)initWithDeviceId:(NSString *)deviceId;

#if DEBUG && TARGET_OS_IPHONE
#if DEBUG
/**
Initialize device info with MatrixSDKCrypto device
*/
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/Devices/Data/MXDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (instancetype)initWithDeviceId:(NSString *)deviceId
return self;
}

#if DEBUG && TARGET_OS_IPHONE
#if DEBUG
- (instancetype)initWithDevice:(MXCryptoDeviceWrapper *)device
{
self = [super init];
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/Devices/MXDeviceInfoSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

/// Convenience struct which transforms `MatrixSDKCrypto` device formats
/// into `MatrixSDK` `MXDeviceInfo` formats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
44 changes: 20 additions & 24 deletions MatrixSDK/Crypto/MXCryptoV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,31 @@ public extension MXCrypto {
@objc static func createCryptoV2IfAvailable(session: MXSession!) -> MXCrypto? {
let log = MXNamedLog(name: "MXCryptoV2")

#if os(iOS)
guard MXSDKOptions.sharedInstance().enableCryptoV2 else {
return nil
}

guard
let session = session,
let restClient = session.matrixRestClient,
let userId = restClient.credentials?.userId,
let deviceId = restClient.credentials?.deviceId
else {
log.failure("Cannot create crypto V2, missing properties")
return nil
}

do {
return try MXCryptoV2(userId: userId, deviceId: deviceId, session: session, restClient: restClient)
} catch {
log.failure("Error creating crypto V2", context: error)
return nil
}
#else
guard MXSDKOptions.sharedInstance().enableCryptoV2 else {
return nil
#endif
}

guard
let session = session,
let restClient = session.matrixRestClient,
let userId = restClient.credentials?.userId,
let deviceId = restClient.credentials?.deviceId
else {
log.failure("Cannot create crypto V2, missing properties")
return nil
}

do {
return try MXCryptoV2(userId: userId, deviceId: deviceId, session: session, restClient: restClient)
} catch {
log.failure("Error creating crypto V2", context: error)
return nil
}
}
}
#endif

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/SecretStorage/MXCryptoSecretStoreV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

/// Secret store compatible with Rust-based Crypto V2, where
/// backup secrets are stored internally in the Crypto machine
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/Trust/MXTrustLevelSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

/// Convenience struct which transforms `MatrixSDKCrypto` trust levels
/// into `MatrixSDK` `MXUserTrustLevel`, `MXDeviceTrustLevel` and `MXUsersTrustLevelSummary` formats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import XCTest
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import XCTest
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import XCTest
@testable import MatrixSDK

#if os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDKTests/Crypto/CryptoMachine/Device+Stub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

@testable import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import XCTest
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import XCTest
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import XCTest
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import XCTest
@testable import MatrixSDK

#if DEBUG && os(iOS)
#if DEBUG

class MXKeyVerificationManagerV2UnitTests: XCTestCase {
class MockSession: MXSession {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
import XCTest

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto
@testable import MatrixSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
import XCTest

#if os(iOS)
#if DEBUG

import MatrixSDKCrypto
@testable import MatrixSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if DEBUG && os(iOS)
#if DEBUG

import MatrixSDKCrypto

Expand Down
Loading

0 comments on commit 296214d

Please sign in to comment.