-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor keychain errors (#3354)
* fix: refactor keychain errors * fix: debug dictionary not properly formatted. * making keychain store error as Auth convertible * Update AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/RefreshSessionState+Debug.swift Co-authored-by: Ian Saultz <[email protected]> * worked on review comment * worked on comments to narrow the keychain status list --------- Co-authored-by: Ian Saultz <[email protected]>
- Loading branch information
Showing
19 changed files
with
174 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...s/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/KeychainStoreError+AuthConvertible.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import AWSPluginsCore | ||
import Amplify | ||
|
||
extension KeychainStoreError: AuthErrorConvertible { | ||
|
||
var authError: AuthError { | ||
switch self { | ||
case .configuration(let message): | ||
return .configuration(message, self.recoverySuggestion) | ||
case .unknown(let errorDescription, let error): | ||
return .unknown(errorDescription, error) | ||
case .conversionError(let errorDescription, let error): | ||
return .configuration(errorDescription, self.recoverySuggestion, error) | ||
case .codingError(let errorDescription, let error): | ||
return .configuration(errorDescription, self.recoverySuggestion, error) | ||
case .itemNotFound: | ||
return .service(self.errorDescription, self.recoverySuggestion) | ||
case .securityError: | ||
return .service(self.errorDescription, self.recoverySuggestion) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStatus.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
enum KeychainStatus { | ||
case success | ||
case userCanceled | ||
case duplicateItem | ||
case itemNotFound | ||
case missingEntitlement | ||
case unexpectedError(OSStatus) | ||
} | ||
|
||
extension KeychainStatus: CustomStringConvertible { | ||
|
||
init(status: OSStatus) { | ||
switch status { | ||
case 0: | ||
self = .success | ||
case -128: | ||
self = .userCanceled | ||
case -25299: | ||
self = .duplicateItem | ||
case -25300: | ||
self = .itemNotFound | ||
case -34018: | ||
self = .missingEntitlement | ||
default: | ||
self = .unexpectedError(status) | ||
} | ||
} | ||
|
||
var description: String { | ||
switch self { | ||
case .success: | ||
return "No error." | ||
case .userCanceled: | ||
return "User canceled the operation." | ||
case .duplicateItem: | ||
return "The specified item already exists in the keychain." | ||
case .itemNotFound: | ||
return "The specified item could not be found in the keychain." | ||
case .missingEntitlement: | ||
return "Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements." | ||
case .unexpectedError(let status): | ||
return "Unexpected error has occurred with status: \(status)." | ||
} | ||
} | ||
} |
Oops, something went wrong.