summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadRustRuntime/MullvadAddressCacheKeychainStore.swift
blob: 755b62cc0612a1bbe28987e48f27eb12a6b79e2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
//  MullvadAddressCacheKeychainStore.swift
//  MullvadVPN
//
//  Created by Andrew Bulhak on 2025-11-20.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import MullvadSettings

/// 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) {
    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 {
    let data = (try? SettingsManager.readAddressCache()) ?? Data()
    return SwiftData(data: data as NSData)
}