summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadRustRuntimeTests/MullvadPostQuantum+Stubs.swift
blob: d498f2fca4a32ee0f5c7fa5fdc86c6e772f01f7d (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
71
72
73
74
75
76
77
78
//
//  MullvadPostQuantum+Stubs.swift
//  MullvadRustRuntimeTests
//
//  Created by Marco Nikic on 2024-06-12.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import NetworkExtension

@testable import MullvadRustRuntime
@testable import MullvadTypes
@testable import PacketTunnelCore
@testable import WireGuardKitTypes

class TunnelProviderStub: TunnelProvider {
    func tunnelHandle() throws -> Int32 {
        0
    }

    func wgFunctions() -> MullvadTypes.WgFunctionPointers {
        return MullvadTypes.WgFunctionPointers(
            open: { _, _, _ in return 0 },
            close: { _, _ in return 0 },
            receive: { _, _, _, _ in return 0 },
            send: { _, _, _, _ in return 0 }
        )
    }
}

class FailedNegotiatorStub: EphemeralPeerNegotiating {
    var onCancelKeyNegotiation: (() -> Void)?

    required init() {
        onCancelKeyNegotiation = nil
    }

    init(onCancelKeyNegotiation: (() -> Void)? = nil) {
        self.onCancelKeyNegotiation = onCancelKeyNegotiation
    }

    func startNegotiation(
        devicePublicKey: WireGuardKitTypes.PublicKey,
        presharedKey: WireGuardKitTypes.PrivateKey,
        peerReceiver: any MullvadTypes.TunnelProvider,
        ephemeralPeerParams: EphemeralPeerParameters
    ) -> Bool {
        false
    }

    func cancelKeyNegotiation() {
        onCancelKeyNegotiation?()
    }
}

class SuccessfulNegotiatorStub: EphemeralPeerNegotiating {
    var onCancelKeyNegotiation: (() -> Void)?
    required init() {
        onCancelKeyNegotiation = nil
    }

    init(onCancelKeyNegotiation: (() -> Void)? = nil) {
        self.onCancelKeyNegotiation = onCancelKeyNegotiation
    }

    func startNegotiation(
        devicePublicKey: WireGuardKitTypes.PublicKey,
        presharedKey: WireGuardKitTypes.PrivateKey,
        peerReceiver: any MullvadTypes.TunnelProvider,
        ephemeralPeerParams: EphemeralPeerParameters
    ) -> Bool {
        true
    }

    func cancelKeyNegotiation() {
        onCancelKeyNegotiation?()
    }
}