From c09a2b3aa4864966929a356da3c257e943409805 Mon Sep 17 00:00:00 2001 From: Fernando Bunn Date: Thu, 11 Apr 2024 18:20:32 +0100 Subject: [PATCH 1/4] WIP: Fix secure coding error https://app.asana.com/0/1203581873609357/1207056719863102/f --- .../DataBrokerProtectionScheduler.swift | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift index a6e5f15362..e45e746fa2 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift @@ -28,7 +28,7 @@ public enum DataBrokerProtectionSchedulerStatus: Codable { } @objc -public class DataBrokerProtectionSchedulerErrorCollection: NSObject { +public class DataBrokerProtectionSchedulerErrorCollection: NSObject, NSSecureCoding { /* This needs to be an NSObject (rather than a struct) so it can be represented in Objective C for the IPC layer @@ -42,6 +42,22 @@ public class DataBrokerProtectionSchedulerErrorCollection: NSObject { self.operationErrors = operationErrors super.init() } + + // MARK: - NSSecureCoding + + public static var supportsSecureCoding: Bool { + return true + } + + public func encode(with coder: NSCoder) { + coder.encode(oneTimeError, forKey: "oneTimeError") + coder.encode(operationErrors, forKey: "operationErrors") + } + + public required init?(coder: NSCoder) { + oneTimeError = coder.decodeObject(forKey: "oneTimeError") as? Error + operationErrors = coder.decodeObject(forKey: "operationErrors") as? [Error] + } } public protocol DataBrokerProtectionScheduler { From 8703d5ac7179454ed48aa1953cd9f4a3078ae28c Mon Sep 17 00:00:00 2001 From: Fernando Bunn Date: Thu, 11 Apr 2024 19:00:17 +0100 Subject: [PATCH 2/4] Use enum for keys --- .../Scheduler/DataBrokerProtectionScheduler.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift index e45e746fa2..5539e01daf 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift @@ -34,6 +34,11 @@ public class DataBrokerProtectionSchedulerErrorCollection: NSObject, NSSecureCod for the IPC layer */ + private enum NSSecureCodingKeys { + static let oneTimeError = "oneTimeError" + static let operationErrors = "operationErrors" + } + public let oneTimeError: Error? public let operationErrors: [Error]? @@ -50,13 +55,13 @@ public class DataBrokerProtectionSchedulerErrorCollection: NSObject, NSSecureCod } public func encode(with coder: NSCoder) { - coder.encode(oneTimeError, forKey: "oneTimeError") - coder.encode(operationErrors, forKey: "operationErrors") + coder.encode(oneTimeError, forKey: NSSecureCodingKeys.oneTimeError) + coder.encode(operationErrors, forKey: NSSecureCodingKeys.operationErrors) } public required init?(coder: NSCoder) { - oneTimeError = coder.decodeObject(forKey: "oneTimeError") as? Error - operationErrors = coder.decodeObject(forKey: "operationErrors") as? [Error] + oneTimeError = coder.decodeObject(forKey: NSSecureCodingKeys.oneTimeError) as? Error + operationErrors = coder.decodeObject(forKey: NSSecureCodingKeys.operationErrors) as? [Error] } } From a2d4fc75745d8efd4828de18e4390db2dea9e57f Mon Sep 17 00:00:00 2001 From: Elle Sullivan Date: Thu, 11 Apr 2024 20:04:15 +0100 Subject: [PATCH 3/4] Update DataBrokerProtectionSchedulerErrorCollection comment --- .../Scheduler/DataBrokerProtectionScheduler.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift index 5539e01daf..ac962de5ee 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift @@ -31,7 +31,7 @@ public enum DataBrokerProtectionSchedulerStatus: Codable { public class DataBrokerProtectionSchedulerErrorCollection: NSObject, NSSecureCoding { /* This needs to be an NSObject (rather than a struct) so it can be represented in Objective C - for the IPC layer + and confrom to NSSecureCoding for the IPC layer. */ private enum NSSecureCodingKeys { From 3291441276fc2b021d44353d66e85307304f64c0 Mon Sep 17 00:00:00 2001 From: Elle Sullivan Date: Thu, 11 Apr 2024 20:44:39 +0100 Subject: [PATCH 4/4] Change to using decodingObjectOf --- .../Scheduler/DataBrokerProtectionScheduler.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift index ac962de5ee..1c2cebe3eb 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionScheduler.swift @@ -60,8 +60,8 @@ public class DataBrokerProtectionSchedulerErrorCollection: NSObject, NSSecureCod } public required init?(coder: NSCoder) { - oneTimeError = coder.decodeObject(forKey: NSSecureCodingKeys.oneTimeError) as? Error - operationErrors = coder.decodeObject(forKey: NSSecureCodingKeys.operationErrors) as? [Error] + oneTimeError = coder.decodeObject(of: NSError.self, forKey: NSSecureCodingKeys.oneTimeError) + operationErrors = coder.decodeArrayOfObjects(ofClass: NSError.self, forKey: NSSecureCodingKeys.operationErrors) } }