From 6ac7b020fc8a8997a02e11476c04bfcb7b115348 Mon Sep 17 00:00:00 2001 From: Michelle Linington Date: Thu, 20 May 2021 17:08:36 -0700 Subject: [PATCH] PR Feedback and minor test change Originally I used the `throwswrapped` prefix to match existing naming convention. Jordan said this is a legacy convention. --- SignalMetadataKit/src/SMKSecretSessionCipher.swift | 14 +++++++------- .../src/SMKSecretSessionCipherTest.swift | 9 +++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/SignalMetadataKit/src/SMKSecretSessionCipher.swift b/SignalMetadataKit/src/SMKSecretSessionCipher.swift index 60309dd..8266d2c 100644 --- a/SignalMetadataKit/src/SMKSecretSessionCipher.swift +++ b/SignalMetadataKit/src/SMKSecretSessionCipher.swift @@ -214,13 +214,13 @@ fileprivate extension SMKMessageType { context: protocolContext ?? NullContext())) } - public func throwswrapped_groupEncryptMessage(recipients: [ProtocolAddress], - paddedPlaintext: Data, - senderCertificate: SenderCertificate, - groupId: Data, - distributionId: UUID, - contentHint: UnidentifiedSenderMessageContent.ContentHint = .default, - protocolContext: StoreContext?) throws -> Data { + public func groupEncryptMessage(recipients: [ProtocolAddress], + paddedPlaintext: Data, + senderCertificate: SenderCertificate, + groupId: Data, + distributionId: UUID, + contentHint: UnidentifiedSenderMessageContent.ContentHint = .default, + protocolContext: StoreContext?) throws -> Data { let senderAddress = try ProtocolAddress(from: senderCertificate.sender) let ciphertext = try groupEncrypt( diff --git a/SignalMetadataKitTests/src/SMKSecretSessionCipherTest.swift b/SignalMetadataKitTests/src/SMKSecretSessionCipherTest.swift index 80037a7..ffca698 100644 --- a/SignalMetadataKitTests/src/SMKSecretSessionCipherTest.swift +++ b/SignalMetadataKitTests/src/SMKSecretSessionCipherTest.swift @@ -283,7 +283,7 @@ class SMKSecretSessionCipherTest: XCTestCase { // Test: Alice encrypt's a message using `groupEncryptMessage` let aliceCipher = try! aliceMockClient.createSecretSessionCipher() let alicePlaintext = "beltalowda".data(using: String.Encoding.utf8)! - let aliceCiphertext = try! aliceCipher.throwswrapped_groupEncryptMessage( + let aliceCiphertext = try! aliceCipher.groupEncryptMessage( recipients: [bobMockClient.protocolAddress], paddedPlaintext: alicePlaintext, senderCertificate: senderCertificate, @@ -341,7 +341,7 @@ class SMKSecretSessionCipherTest: XCTestCase { // Test: Alice encrypt's a message using `groupEncryptMessage` let aliceCipher = try! aliceMockClient.createSecretSessionCipher() let alicePlaintext = "beltalowda".data(using: String.Encoding.utf8)! - let aliceCiphertext = try! aliceCipher.throwswrapped_groupEncryptMessage( + let aliceCiphertext = try! aliceCipher.groupEncryptMessage( recipients: [bobMockClient.protocolAddress], paddedPlaintext: alicePlaintext, senderCertificate: senderCertificate, @@ -368,9 +368,14 @@ class SMKSecretSessionCipherTest: XCTestCase { protocolContext: nil) XCTFail("Decryption should have failed.") } catch let knownSenderError as SecretSessionKnownSenderError { + // Verify: We need to make sure that the sender, group, and contentHint are preserved + // through decryption failures because of missing a missing sender key. This will + // help with recovery. XCTAssertEqual(knownSenderError.senderAddress, aliceMockClient.address) XCTAssertEqual(knownSenderError.senderDeviceId, UInt32(aliceMockClient.deviceId)) XCTAssertEqual(Data(knownSenderError.groupId!), "inyalowda".data(using: String.Encoding.utf8)!) + XCTAssertEqual(knownSenderError.contentHint, .retry) + if case SignalError.invalidState(_) = knownSenderError.underlyingError { // Expected } else {