Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: SenderKeyRecord state method always return first state #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Encryption/SenderKeyRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Tests/SenderKeyRecordTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down