From 2b3e71cde6cc45072fcd928926ca8fd8ac0ca2ff Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Sat, 3 Oct 2020 12:14:24 +1000 Subject: [PATCH] Keep around skipped message keys until they're used --- .../Closed Groups/SharedSenderKeysImplementation.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Loki/Protocol/Closed Groups/SharedSenderKeysImplementation.swift b/SignalServiceKit/src/Loki/Protocol/Closed Groups/SharedSenderKeysImplementation.swift index 59e9d8cb5..b53b4725e 100644 --- a/SignalServiceKit/src/Loki/Protocol/Closed Groups/SharedSenderKeysImplementation.swift +++ b/SignalServiceKit/src/Loki/Protocol/Closed Groups/SharedSenderKeysImplementation.swift @@ -109,16 +109,19 @@ public final class SharedSenderKeysImplementation : NSObject { return ratchet } else { var currentKeyIndex = ratchet.keyIndex - var result = ratchet + var current = ratchet + var messageKeys: [String] = [] while currentKeyIndex < targetKeyIndex { do { - result = try step(result) - currentKeyIndex = result.keyIndex + current = try step(current) + messageKeys += current.messageKeys + currentKeyIndex = current.keyIndex } catch { print("[Loki] Couldn't step ratchet due to error: \(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) return result }