0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-19 19:42:19 +02:00

swift: let message backup stream factory fn throw (#713)

This commit is contained in:
Alex Konradi 2024-04-30 15:24:23 -04:00 committed by GitHub
parent 53699f11db
commit 1fe47ce209
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -47,10 +47,10 @@ public enum MessageBackupPurpose: UInt8 {
/// - `SignalError.ioError`: If an IO error on the input occurs.
/// - `MessageBackupValidationError`: If validation fails
public func validateMessageBackup(
key: MessageBackupKey, purpose: MessageBackupPurpose, length: UInt64, makeStream: () -> SignalInputStream
key: MessageBackupKey, purpose: MessageBackupPurpose, length: UInt64, makeStream: () throws -> SignalInputStream
) throws -> MessageBackupUnknownFields {
let outcome: ValidationOutcome = try withInputStream(makeStream()) { firstInput in
try withInputStream(makeStream()) { secondInput in
let outcome: ValidationOutcome = try withInputStream(try makeStream()) { firstInput in
try withInputStream(try makeStream()) { secondInput in
try key.withNativeHandle { key in
try invokeFnReturningNativeHandle {
signal_message_backup_validator_validate($0, key, firstInput, secondInput, length, purpose.rawValue)

View File

@ -39,6 +39,20 @@ class MessageBackupTests: TestCaseBase {
}
}
func testInputFactoryThrows() {
struct TestFactoryError: Error {}
XCTAssertThrowsError(
try validateMessageBackup(
key: MessageBackupKey.testKey(),
purpose: .remoteBackup,
length: 4242
) { throw TestFactoryError() }
) { error in
if error is TestFactoryError {} else { XCTFail("\(error)") }
}
}
func testInputThrowsAfter() {
let bytes = readResource(forName: "new_account.binproto.encrypted")
let makeStream = { ThrowsAfterInputStream(inner: SignalInputStreamAdapter(bytes), readBeforeThrow: UInt64(bytes.count) - 1) }