summaryrefslogtreecommitdiffhomepage
path: root/ios/PacketTunnel/DeviceCheck/DeviceCheck.swift
blob: aa6fe630021d936c43e89b58568eccda7142c112 (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
68
69
70
//
//  DeviceCheck.swift
//  PacketTunnel
//
//  Created by pronebird on 13/09/2023.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadTypes

/// The verdict of an account status check.
enum AccountVerdict: Equatable {
    /// Account is no longer valid.
    case invalid

    /// Account is expired.
    case expired(Account)

    /// Account exists and has enough time left.
    case active(Account)
}

/// The verdict of a device status check.
enum DeviceVerdict: Equatable {
    /// Device is revoked.
    case revoked

    /// Device exists but the public key registered on server does not match any longer.
    case keyMismatch

    /// Device is in good standing and should work as normal.
    case active
}

/// Type describing whether key rotation took place and the outcome of it.
enum KeyRotationStatus: Equatable {
    /// No rotation took place yet.
    case noAction

    /// Rotation attempt took place but without success.
    case attempted(Date)

    /// Rotation attempt took place and succeeded.
    case succeeded(Date)

    /// Returns `true` if the status is `.succeeded`.
    var isSucceeded: Bool {
        if case .succeeded = self {
            return true
        } else {
            return false
        }
    }
}

/**
 Struct holding data associated with account and device diagnostics and also device key recovery performed by packet
 tunnel process.
 */
struct DeviceCheck: Equatable {
    /// The verdict of account status check.
    var accountVerdict: AccountVerdict

    /// The verdict of device status check.
    var deviceVerdict: DeviceVerdict

    // The status of the last performed key rotation.
    var keyRotationStatus: KeyRotationStatus
}