From 313d076ddf98c065151ae1792ad19c1bc9c3515e Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 19 May 2019 14:20:54 +0200 Subject: [PATCH] Move Error extension to Core --- TunnelKit.xcodeproj/project.pbxproj | 6 +++ TunnelKit/Sources/Core/Errors.swift | 42 ++++++++++++++++++++ TunnelKit/Sources/OpenVPN/OpenVPNError.swift | 16 -------- 3 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 TunnelKit/Sources/Core/Errors.swift diff --git a/TunnelKit.xcodeproj/project.pbxproj b/TunnelKit.xcodeproj/project.pbxproj index 394ffd4..b7428e8 100644 --- a/TunnelKit.xcodeproj/project.pbxproj +++ b/TunnelKit.xcodeproj/project.pbxproj @@ -124,6 +124,8 @@ 0EE2F975229163C900F56F49 /* Proxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F973229163C900F56F49 /* Proxy.swift */; }; 0EE2F97722916A5D00F56F49 /* OpenVPN.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F97622916A5D00F56F49 /* OpenVPN.swift */; }; 0EE2F97822916A5D00F56F49 /* OpenVPN.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F97622916A5D00F56F49 /* OpenVPN.swift */; }; + 0EE2F97A2291817300F56F49 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F9792291817300F56F49 /* Errors.swift */; }; + 0EE2F97B2291817300F56F49 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F9792291817300F56F49 /* Errors.swift */; }; 0EE3B3E421471C3A0027AB17 /* StaticKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE3B3E321471C3A0027AB17 /* StaticKey.swift */; }; 0EE3B3E521471C3A0027AB17 /* StaticKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE3B3E321471C3A0027AB17 /* StaticKey.swift */; }; 0EE7A79820F6296F00B42E6A /* PacketMacros.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EE7A79720F6296F00B42E6A /* PacketMacros.m */; }; @@ -305,6 +307,7 @@ 0EE2F9702291638600F56F49 /* IPv6Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPv6Settings.swift; sourceTree = ""; }; 0EE2F973229163C900F56F49 /* Proxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Proxy.swift; sourceTree = ""; }; 0EE2F97622916A5D00F56F49 /* OpenVPN.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenVPN.swift; sourceTree = ""; }; + 0EE2F9792291817300F56F49 /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = ""; }; 0EE3B3E321471C3A0027AB17 /* StaticKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticKey.swift; sourceTree = ""; }; 0EE7A79420F61EDC00B42E6A /* PacketMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PacketMacros.h; sourceTree = ""; }; 0EE7A79720F6296F00B42E6A /* PacketMacros.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PacketMacros.m; sourceTree = ""; }; @@ -599,6 +602,7 @@ 0E011F7C2196D97200BA59EE /* EndpointProtocol.swift */, 0EFEB4362006D3C800F81029 /* Errors.h */, 0EFEB44B2006D3C800F81029 /* Errors.m */, + 0EE2F9792291817300F56F49 /* Errors.swift */, 0EFEB4452006D3C800F81029 /* IOInterface.swift */, 0EE2F96D2291636B00F56F49 /* IPv4Settings.swift */, 0EE2F9702291638600F56F49 /* IPv6Settings.swift */, @@ -1115,6 +1119,7 @@ 0EFEB4552006D3C800F81029 /* EncryptionBridge.swift in Sources */, 0EFEB45C2006D3C800F81029 /* ZeroingData.m in Sources */, 0EE2F9712291638600F56F49 /* IPv6Settings.swift in Sources */, + 0EE2F97A2291817300F56F49 /* Errors.swift in Sources */, 0EFEB4632006D3C800F81029 /* ProtocolMacros.swift in Sources */, 0EFB902B22788512006405E4 /* RoutingTable.m in Sources */, 0EFEB46D2006D3C800F81029 /* Data+Manipulation.swift in Sources */, @@ -1177,6 +1182,7 @@ 0EFEB4A32006D7F300F81029 /* Errors.m in Sources */, 0EFEB4A22006D7F300F81029 /* CoreConfiguration.swift in Sources */, 0EE2F9722291638600F56F49 /* IPv6Settings.swift in Sources */, + 0EE2F97B2291817300F56F49 /* Errors.swift in Sources */, 0EFB902C22788512006405E4 /* RoutingTable.m in Sources */, 0EFEB4952006D7F300F81029 /* SecureRandom.swift in Sources */, 0EFEB49A2006D7F300F81029 /* MSS.m in Sources */, diff --git a/TunnelKit/Sources/Core/Errors.swift b/TunnelKit/Sources/Core/Errors.swift new file mode 100644 index 0000000..d10548f --- /dev/null +++ b/TunnelKit/Sources/Core/Errors.swift @@ -0,0 +1,42 @@ +// +// Errors.swift +// TunnelKit +// +// Created by Davide De Rosa on 05/19/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/passepartoutvpn +// +// This file is part of TunnelKit. +// +// TunnelKit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TunnelKit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TunnelKit. If not, see . +// + +import Foundation +import __TunnelKitCore + +extension Error { + func isTunnelKitError() -> Bool { + let te = self as NSError + return te.domain == TunnelKitErrorDomain + } + + func tunnelKitErrorCode() -> TunnelKitErrorCode? { + let te = self as NSError + guard te.domain == TunnelKitErrorDomain else { + return nil + } + return TunnelKitErrorCode(rawValue: te.code) + } +} diff --git a/TunnelKit/Sources/OpenVPN/OpenVPNError.swift b/TunnelKit/Sources/OpenVPN/OpenVPNError.swift index 6e87d27..24a5265 100644 --- a/TunnelKit/Sources/OpenVPN/OpenVPNError.swift +++ b/TunnelKit/Sources/OpenVPN/OpenVPNError.swift @@ -35,7 +35,6 @@ // import Foundation -import __TunnelKitCore /// The possible errors raised/thrown during `OpenVPNSession` operation. public enum OpenVPNError: String, Error { @@ -79,18 +78,3 @@ public enum OpenVPNError: String, Error { /// Missing routing information. case noRouting } - -extension Error { - func isTunnelKitError() -> Bool { - let te = self as NSError - return te.domain == TunnelKitErrorDomain - } - - func tunnelKitErrorCode() -> TunnelKitErrorCode? { - let te = self as NSError - guard te.domain == TunnelKitErrorDomain else { - return nil - } - return TunnelKitErrorCode(rawValue: te.code) - } -}