aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift
blob: 6afbadb8bb60c45f98689a15e5e08deaff7d0aac (plain) (blame)
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
// SPDX-License-Identifier: MIT
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.

import Cocoa

// We have this in a separate file because we don't want the network extension
// code to see WireGuardAppError and tr(). Also, this extension is used only on macOS.

extension TunnelConfiguration.ParseError: WireGuardAppError {
    var alertText: AlertText {
        switch self {
        case .invalidLine(let line):
            return (tr(format: "macAlertInvalidLine (%@)", String(line)), "")
        case .noInterface:
            return (tr("macAlertNoInterface"), "")
        case .multipleInterfaces:
            return (tr("macAlertMultipleInterfaces"), "")
        case .interfaceHasNoPrivateKey:
            return (tr("alertInvalidInterfaceMessagePrivateKeyRequired"), tr("alertInvalidInterfaceMessagePrivateKeyInvalid"))
        case .interfaceHasInvalidPrivateKey:
            return (tr("macAlertPrivateKeyInvalid"), tr("alertInvalidInterfaceMessagePrivateKeyInvalid"))
        case .interfaceHasInvalidListenPort(let value):
            return (tr(format: "macAlertListenPortInvalid (%@)", value), tr("alertInvalidInterfaceMessageListenPortInvalid"))
        case .interfaceHasInvalidAddress(let value):
            return (tr(format: "macAlertAddressInvalid (%@)", value), tr("alertInvalidInterfaceMessageAddressInvalid"))
        case .interfaceHasInvalidDNS(let value):
            return (tr(format: "macAlertDNSInvalid (%@)", value), tr("alertInvalidInterfaceMessageDNSInvalid"))
        case .interfaceHasInvalidMTU(let value):
            return (tr(format: "macAlertMTUInvalid (%@)", value), tr("alertInvalidInterfaceMessageMTUInvalid"))
        case .interfaceHasUnrecognizedKey(let value):
            return (tr(format: "macAlertUnrecognizedInterfaceKey (%@)", value), tr("macAlertInfoUnrecognizedInterfaceKey"))
        case .peerHasNoPublicKey:
            return (tr("alertInvalidPeerMessagePublicKeyRequired"), tr("alertInvalidPeerMessagePublicKeyInvalid"))
        case .peerHasInvalidPublicKey:
            return (tr("macAlertPublicKeyInvalid"), tr("alertInvalidPeerMessagePublicKeyInvalid"))
        case .peerHasInvalidPreSharedKey:
            return (tr("macAlertPreSharedKeyInvalid"), tr("alertInvalidPeerMessagePreSharedKeyInvalid"))
        case .peerHasInvalidAllowedIP(let value):
            return (tr(format: "macAlertAllowedIPInvalid (%@)", value), tr("alertInvalidPeerMessageAllowedIPsInvalid"))
        case .peerHasInvalidEndpoint(let value):
            return (tr(format: "macAlertEndpointInvalid (%@)", value), tr("alertInvalidPeerMessageEndpointInvalid"))
        case .peerHasInvalidPersistentKeepAlive(let value):
            return (tr(format: "macAlertPersistentKeepliveInvalid (%@)", value), tr("alertInvalidPeerMessagePersistentKeepaliveInvalid"))
        case .peerHasUnrecognizedKey(let value):
            return (tr(format: "macAlertUnrecognizedPeerKey (%@)", value), tr("macAlertInfoUnrecognizedPeerKey"))
        case .peerHasInvalidTransferBytes(let line):
            return (tr(format: "macAlertInvalidLine (%@)", String(line)), "")
        case .peerHasInvalidLastHandshakeTime(let line):
            return (tr(format: "macAlertInvalidLine (%@)", String(line)), "")
        case .multiplePeersWithSamePublicKey:
            return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "")
        case .multipleEntriesForKey(let value):
            return (tr(format: "macAlertMultipleEntriesForKey (%@)", value), "")
        }
    }
}