Keep around skipped message keys until they're used

pull/290/head
nielsandriesse 5 years ago
parent 1a264595c8
commit 2b3e71cde6

@ -109,16 +109,19 @@ public final class SharedSenderKeysImplementation : NSObject {
return ratchet return ratchet
} else { } else {
var currentKeyIndex = ratchet.keyIndex var currentKeyIndex = ratchet.keyIndex
var result = ratchet var current = ratchet
var messageKeys: [String] = []
while currentKeyIndex < targetKeyIndex { while currentKeyIndex < targetKeyIndex {
do { do {
result = try step(result) current = try step(current)
currentKeyIndex = result.keyIndex messageKeys += current.messageKeys
currentKeyIndex = current.keyIndex
} catch { } catch {
print("[Loki] Couldn't step ratchet due to error: \(error).") print("[Loki] Couldn't step ratchet due to error: \(error).")
throw error throw error
} }
} }
let result = ClosedGroupRatchet(chainKey: current.chainKey, keyIndex: current.keyIndex, messageKeys: messageKeys) // Includes any skipped message keys
Storage.setClosedGroupRatchet(for: groupPublicKey, senderPublicKey: senderPublicKey, ratchet: result, using: transaction) Storage.setClosedGroupRatchet(for: groupPublicKey, senderPublicKey: senderPublicKey, ratchet: result, using: transaction)
return result return result
} }

Loading…
Cancel
Save