From fdb5ac97d50654ed359a362aa2ccba016bd52840 Mon Sep 17 00:00:00 2001 From: dawen on M2 Date: Wed, 21 Feb 2024 16:58:36 +0800 Subject: [PATCH 1/2] fix: return wrong state --- Sources/Encryption/SenderKeyRecord.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Encryption/SenderKeyRecord.swift b/Sources/Encryption/SenderKeyRecord.swift index 175b64a..4813c44 100644 --- a/Sources/Encryption/SenderKeyRecord.swift +++ b/Sources/Encryption/SenderKeyRecord.swift @@ -44,7 +44,7 @@ final class SenderKeyRecord { func state(for id: UInt32) -> SenderKeyState? { for item in states { if item.keyId == id { - return state + return item } } return nil From c75b076d82a502239de2a23948cb18873fc44c66 Mon Sep 17 00:00:00 2001 From: dawen on M2 Date: Wed, 21 Feb 2024 18:12:35 +0800 Subject: [PATCH 2/2] add testcase --- Tests/SenderKeyRecordTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Tests/SenderKeyRecordTests.swift b/Tests/SenderKeyRecordTests.swift index ac09671..865f380 100644 --- a/Tests/SenderKeyRecordTests.swift +++ b/Tests/SenderKeyRecordTests.swift @@ -109,6 +109,18 @@ class SenderKeyRecordTests: XCTestCase { chainKey: senderKey2, signatureKeyPair: senderSigningKey2) + guard let state = record.state(for: stateId1) else { + XCTFail("\(stateId1) missed") + return + } + XCTAssertEqual(state.keyId, stateId1) + + guard let state = record.state(for: stateId2) else { + XCTFail("\(stateId2) missed") + return + } + XCTAssertEqual(state.keyId, stateId2) + guard let serialized = try? record.protoData() else { XCTFail("Could not serialize SenderKeyRecord") return