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

Fix secure coding error #2604

Merged
merged 4 commits into from
Apr 12, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ 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
and confrom to NSSecureCoding for the IPC layer.
*/

private enum NSSecureCodingKeys {
static let oneTimeError = "oneTimeError"
static let operationErrors = "operationErrors"
}

public let oneTimeError: Error?
public let operationErrors: [Error]?

Expand All @@ -42,6 +47,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: NSSecureCodingKeys.oneTimeError)
coder.encode(operationErrors, forKey: NSSecureCodingKeys.operationErrors)
}

public required init?(coder: NSCoder) {
oneTimeError = coder.decodeObject(of: NSError.self, forKey: NSSecureCodingKeys.oneTimeError)
operationErrors = coder.decodeArrayOfObjects(ofClass: NSError.self, forKey: NSSecureCodingKeys.operationErrors)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me.

}
}

public protocol DataBrokerProtectionScheduler {
Expand Down
Loading