mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 03:52:17 +02:00
swift: let message backup stream factory fn throw (#713)
This commit is contained in:
parent
53699f11db
commit
1fe47ce209
@ -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)
|
||||
|
@ -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) }
|
||||
|
Loading…
Reference in New Issue
Block a user