diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-05-03 15:27:03 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-05-12 10:13:33 +0200 |
| commit | fa9ba06b0922ed4b966672f514711e6becc3433d (patch) | |
| tree | 0e461bf8e4ffea2a19cd9487020a70014100c2ae | |
| parent | 48d3908729dac97dc5c39549eb1dce97b8192006 (diff) | |
| download | mullvadvpn-fa9ba06b0922ed4b966672f514711e6becc3433d.tar.xz mullvadvpn-fa9ba06b0922ed4b966672f514711e6becc3433d.zip | |
TunnelSettingsManager: add method to verify the existence of configuration in Keychain
| -rw-r--r-- | ios/MullvadVPN/TunnelSettingsManager.swift | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ios/MullvadVPN/TunnelSettingsManager.swift b/ios/MullvadVPN/TunnelSettingsManager.swift index c30440324a..aaf5453f1b 100644 --- a/ios/MullvadVPN/TunnelSettingsManager.swift +++ b/ios/MullvadVPN/TunnelSettingsManager.swift @@ -245,6 +245,24 @@ extension TunnelSettingsManager { } } + /// Verify that the keychain entry exists. + /// Returns an error in case of failure to access Keychain. + static func exists(searchTerm: KeychainSearchTerm) -> Result<Bool> { + let query = searchTerm.makeKeychainAttributes() + + return Keychain.findFirst(query: query) + .map({ (attributes) -> Bool in + return true + }) + .flatMapError({ (error) -> Result<Bool> in + if case .itemNotFound = error { + return .success(false) + } else { + return .failure(.lookupEntry(error)) + } + }) + } + private static func encode(tunnelConfig: TunnelSettings) -> Result<Data> { return Swift.Result { try JSONEncoder().encode(tunnelConfig) } .mapError { .encode($0) } |
