From 36424a78e0b020ca475214ff44f41f04bdd94ccc Mon Sep 17 00:00:00 2001 From: Edgar Story Date: Tue, 12 Nov 2024 09:08:26 +0000 Subject: [PATCH] Make fido2 property a lazy var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - This object was being kept around after being created and as we need it in some other functions it made sense to make it lazy and keep it around that way. - Arguably the FIDO2 instance could be removed after each time it’s been used, but as the FIDO2 class doesn’t have any state stored in it, it seems benign keeping it about for now. --- Xcodes/Backend/AppState.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Xcodes/Backend/AppState.swift b/Xcodes/Backend/AppState.swift index c216435..1d66305 100644 --- a/Xcodes/Backend/AppState.swift +++ b/Xcodes/Backend/AppState.swift @@ -355,8 +355,8 @@ class AppState: ObservableObject { .store(in: &cancellables) } - var fido2: FIDO2? - + private lazy var fido2 = FIDO2() + func createAndSubmitSecurityKeyAssertationWithPinCode(_ pinCode: String?, sessionData: AppleSessionData, authOptions: AuthOptionsResponse) { self.presentedSheet = .securityKeyTouchToConfirm @@ -379,8 +379,6 @@ class AppState: ObservableObject { Task { do { - let fido2 = FIDO2() - self.fido2 = fido2 let response = try fido2.respondToChallenge(args: ChallengeArgs(rpId: rpId, validCredentials: validCreds, devPin: pinCode, challenge: challenge, origin: origin)) Task { @MainActor in @@ -413,7 +411,7 @@ class AppState: ObservableObject { } func cancelSecurityKeyAssertationRequest() { - self.fido2?.cancel() + self.fido2.cancel() } private func handleAuthenticationFlowCompletion(_ completion: Subscribers.Completion) {