From f9ae3412a5ccf94c6004ff08da4db2fddbfaf861 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 3 Apr 2019 12:10:58 +0200 Subject: [PATCH] Move malformed error out of unrelated SessionError Also give more detail about the reason. --- TunnelKit/Sources/Core/OptionsBundle.swift | 11 +++++------ TunnelKit/Sources/Core/OptionsError.swift | 3 +++ TunnelKit/Sources/Core/SessionError.swift | 3 --- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/TunnelKit/Sources/Core/OptionsBundle.swift b/TunnelKit/Sources/Core/OptionsBundle.swift index 15a773e..84e3126 100644 --- a/TunnelKit/Sources/Core/OptionsBundle.swift +++ b/TunnelKit/Sources/Core/OptionsBundle.swift @@ -190,7 +190,6 @@ public struct OptionsBundle { var optIfconfig4Arguments: [String]? var optIfconfig6Arguments: [String]? var optGateway4Arguments: [String]? - var optGateway6Arguments: [String]? var optRoutes4: [(String, String, String?)] = [] // address, netmask, gateway var optRoutes6: [(String, UInt8, String?)] = [] // destination, prefix, gateway var optDNSServers: [String] = [] @@ -560,7 +559,7 @@ public struct OptionsBundle { // if let ifconfig4Arguments = optIfconfig4Arguments { guard ifconfig4Arguments.count == 2 else { - throw SessionError.malformedPushReply + throw OptionsError.malformed(option: "ifconfig takes 2 arguments") } let address4: String @@ -573,7 +572,7 @@ public struct OptionsBundle { // default gateway required when topology is subnet guard let gateway4Arguments = optGateway4Arguments, gateway4Arguments.count == 1 else { - throw SessionError.malformedPushReply + throw OptionsError.malformed(option: "route-gateway takes 1 argument") } address4 = ifconfig4Arguments[0] addressMask4 = ifconfig4Arguments[1] @@ -598,14 +597,14 @@ public struct OptionsBundle { if let ifconfig6Arguments = optIfconfig6Arguments { guard ifconfig6Arguments.count == 2 else { - throw SessionError.malformedPushReply + throw OptionsError.malformed(option: "ifconfig-ipv6 takes 2 arguments") } let address6Components = ifconfig6Arguments[0].components(separatedBy: "/") guard address6Components.count == 2 else { - throw SessionError.malformedPushReply + throw OptionsError.malformed(option: "ifconfig-ipv6 address must have a /prefix") } guard let addressPrefix6 = UInt8(address6Components[1]) else { - throw SessionError.malformedPushReply + throw OptionsError.malformed(option: "ifconfig-ipv6 address prefix must be a 8-bit number") } let address6 = address6Components[0] diff --git a/TunnelKit/Sources/Core/OptionsError.swift b/TunnelKit/Sources/Core/OptionsError.swift index 779d2c4..fff2ed1 100644 --- a/TunnelKit/Sources/Core/OptionsError.swift +++ b/TunnelKit/Sources/Core/OptionsError.swift @@ -28,6 +28,9 @@ import Foundation /// Error raised by the options parser, with details about the line that triggered it. public enum OptionsError: Error { + /// Option syntax is incorrect. + case malformed(option: String) + /// The file misses a required option. case missingConfiguration(option: String) diff --git a/TunnelKit/Sources/Core/SessionError.swift b/TunnelKit/Sources/Core/SessionError.swift index db43075..b76b715 100644 --- a/TunnelKit/Sources/Core/SessionError.swift +++ b/TunnelKit/Sources/Core/SessionError.swift @@ -59,9 +59,6 @@ public enum SessionError: String, Error { /// The provided credentials failed authentication. case badCredentials - /// The reply to PUSH_REQUEST is malformed. - case malformedPushReply - /// A write operation failed at the link layer (e.g. network unreachable). case failedLinkWrite