-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathMullvadAddressCacheKeychainStore.swift
More file actions
30 lines (26 loc) · 1.17 KB
/
MullvadAddressCacheKeychainStore.swift
File metadata and controls
30 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
// MullvadAddressCacheKeychainStore.swift
// MullvadVPN
//
// Created by Andrew Bulhak on 2025-11-20.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import MullvadSettings
/// Whether the settings store is available. It requires `ApplicationSecurityGroupIdentifier`
/// to be present in the main bundle's Info.plist, which is not the case in e.g. UI test runners.
private let isSettingsStoreAvailable: Bool = Bundle.main
.object(forInfoDictionaryKey: "ApplicationSecurityGroupIdentifier") != nil
/// Store the address cache, given to us by the Rust code, to the keychain
@_cdecl("swift_store_address_cache")
func storeAddressCache(_ pointer: UnsafeRawPointer, dataSize: UInt64) {
guard isSettingsStoreAvailable else { return }
let data = Data(bytes: pointer, count: Int(dataSize))
// if writing to the Keychain fails, it will do so silently.
try? SettingsManager.writeAddressCache(data)
}
@_cdecl("swift_read_address_cache")
func readAddressCache() -> SwiftData {
guard isSettingsStoreAvailable else { return SwiftData(data: NSData()) }
let data = (try? SettingsManager.readAddressCache()) ?? Data()
return SwiftData(data: data as NSData)
}