Skip to content

Commit

Permalink
element-hq/element-ios/issues/4406 - Fixes following code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Aug 30, 2021
1 parent bd1c541 commit 247fbfa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion MatrixSDK/Crypto/Dehydration/MXDehydrationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ - (void)uploadDeviceInfo:(MXDeviceInfo*)deviceInfo
}

MXWeakify(self);
[restClient uploadKeys:deviceInfo.JSONDictionary oneTimeKeys:oneTimeJson forDeviceWithId:deviceInfo.deviceId success:^(MXKeysUploadResponse *keysUploadResponse) {
[restClient uploadKeys:deviceInfo.JSONDictionary oneTimeKeys:oneTimeJson fallbackKeys:nil forDeviceWithId:deviceInfo.deviceId success:^(MXKeysUploadResponse *keysUploadResponse) {
[account markOneTimeKeysAsPublished];
MXLogDebug(@"[MXDehydrationManager] dehydration done succesfully:\n device ID = %@\n ed25519 = %@\n curve25519 = %@", deviceInfo.deviceId, account.identityKeys[@"ed25519"], account.identityKeys[@"curve25519"]);
MXStrongifyAndReturnIfNil(self);
Expand Down
8 changes: 6 additions & 2 deletions MatrixSDK/Crypto/MXCrypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -2930,10 +2930,14 @@ - (MXHTTPOperation *)generateAndUploadFallbackKey

MXWeakify(self);
return [_matrixRestClient uploadKeys:nil oneTimeKeys:nil fallbackKeys:fallbackKeyJson success:^(MXKeysUploadResponse *keysUploadResponse) {
weakself.uploadFallbackKeyOperation = nil;
MXStrongifyAndReturnIfNil(self);

self.uploadFallbackKeyOperation = nil;
MXLogDebug(@"[MXCrypto] generateAndUploadFallbackKey: Finished uploading fallback key.");
} failure:^(NSError *error) {
weakself.uploadFallbackKeyOperation = nil;
MXStrongifyAndReturnIfNil(self);

self.uploadFallbackKeyOperation = nil;
MXLogError(@"[MXCrypto] generateAndUploadFallbackKey: Failed uploading fallback key.");
}];
}
Expand Down
5 changes: 4 additions & 1 deletion MatrixSDK/MXRestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -2155,14 +2155,17 @@ Get the maximum size a media upload can be in bytes.
@param deviceKeys the device keys to send.
@param oneTimeKeys the one-time keys to send.
@param fallbackKeys the fallback keys to send.
@param deviceId ID of the device the keys belong to. Nil to upload keys to the device of the current session.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)uploadKeys:(NSDictionary*)deviceKeys oneTimeKeys:(NSDictionary*)oneTimeKeys
- (MXHTTPOperation*)uploadKeys:(NSDictionary*)deviceKeys
oneTimeKeys:(NSDictionary*)oneTimeKeys
fallbackKeys:(NSDictionary *)fallbackKeys
forDeviceWithId:(NSString*)deviceId
success:(void (^)(MXKeysUploadResponse *keysUploadResponse))success
failure:(void (^)(NSError *error))failure;
Expand Down
13 changes: 1 addition & 12 deletions MatrixSDKTests/MXRestClientTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1581,21 +1581,10 @@ - (void)testOneTimeKeys
// Upload the device keys
[bobRestClient uploadKeys:nil oneTimeKeys:otks fallbackKeys:nil success:^(MXKeysUploadResponse *keysUploadResponse) {
XCTAssert(keysUploadResponse.oneTimeKeyCounts);

XCTAssertEqual(keysUploadResponse.oneTimeKeyCounts[@"curve25519"].unsignedIntValue, 2, @"Key count must be 2 for 'curve25519'");
XCTAssertEqual([keysUploadResponse oneTimeKeyCountsForAlgorithm:@"curve25519"], 2, @"Key count must be 2 for 'curve25519'");

[keysUploadResponse.oneTimeKeyCounts enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSNumber *obj, BOOL *stop) {
if ([key isEqualToString:@"curve25519"]) {
return;
}

XCTAssertEqual(obj.unsignedIntValue, 0, @"Key count must be 0 for any other algorithm.");
XCTAssertEqual([keysUploadResponse oneTimeKeyCountsForAlgorithm:key], 0, @"Key count must be 0 for any other algorithm.");
}];

XCTAssertEqual([keysUploadResponse oneTimeKeyCountsForAlgorithm:@"deded"], 0, @"It must response 0 for any other algo");
[expectation fulfill];

} failure:^(NSError *error) {
XCTFail(@"The request should not fail - NSError: %@", error);
[expectation fulfill];
Expand Down

0 comments on commit 247fbfa

Please sign in to comment.