summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadSettings/StoredDeviceData.swift
blob: abd16fa310829f822908d780556a16ffcd207057 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
//  StoredDeviceData.swift
//  MullvadVPN
//
//  Created by Marco Nikic on 2023-07-31.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadTypes
@preconcurrency import WireGuardKitTypes

public struct StoredDeviceData: Codable, Equatable, Sendable {
    /// Device creation date.
    public var creationDate: Date

    /// Device identifier.
    public var identifier: String

    /// Device name.
    public var name: String

    /// Whether relay hijacks DNS from this device.
    public var hijackDNS: Bool

    /// IPv4 address + mask assigned to device.
    public var ipv4Address: IPAddressRange

    /// IPv6 address + mask assigned to device.
    public var ipv6Address: IPAddressRange

    /// WireGuard key data.
    public var wgKeyData: StoredWgKeyData

    /// Returns capitalized device name.
    public var capitalizedName: String {
        name.capitalized
    }

    public init(
        creationDate: Date,
        identifier: String,
        name: String,
        hijackDNS: Bool,
        ipv4Address: IPAddressRange,
        ipv6Address: IPAddressRange,
        wgKeyData: StoredWgKeyData
    ) {
        self.creationDate = creationDate
        self.identifier = identifier
        self.name = name
        self.hijackDNS = hijackDNS
        self.ipv4Address = ipv4Address
        self.ipv6Address = ipv6Address
        self.wgKeyData = wgKeyData
    }

    /// Fill in part of the structure that contains device related properties from `Device` struct.
    public mutating func update(from device: Device) {
        identifier = device.id
        name = device.name
        creationDate = device.created
        hijackDNS = device.hijackDNS
        ipv4Address = device.ipv4Address
        ipv6Address = device.ipv6Address
    }
}