Move Error extension to Core

This commit is contained in:
Davide De Rosa 2019-05-19 14:20:54 +02:00
parent c4a84a5ade
commit 313d076ddf
3 changed files with 48 additions and 16 deletions

View File

@ -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 = "<group>"; };
0EE2F973229163C900F56F49 /* Proxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Proxy.swift; sourceTree = "<group>"; };
0EE2F97622916A5D00F56F49 /* OpenVPN.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenVPN.swift; sourceTree = "<group>"; };
0EE2F9792291817300F56F49 /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
0EE3B3E321471C3A0027AB17 /* StaticKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticKey.swift; sourceTree = "<group>"; };
0EE7A79420F61EDC00B42E6A /* PacketMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PacketMacros.h; sourceTree = "<group>"; };
0EE7A79720F6296F00B42E6A /* PacketMacros.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PacketMacros.m; sourceTree = "<group>"; };
@ -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 */,

View File

@ -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 <http://www.gnu.org/licenses/>.
//
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)
}
}

View File

@ -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)
}
}