Reuse native WireGuard error as ConfigurationError (#316)
There was a duplicate ConfigurationError.
This commit is contained in:
parent
ac362f90ef
commit
422f3163d3
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- WireGuard: Return native parsing errors from WireGuardKit. [#316](https://github.com/passepartoutvpn/tunnelkit/pull/316)
|
||||||
|
|
||||||
## 6.0.0 (2023-04-01)
|
## 6.0.0 (2023-04-01)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -26,17 +26,9 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import WireGuardKit
|
import WireGuardKit
|
||||||
|
|
||||||
public struct ConfigurationError: Error {
|
|
||||||
let parseError: TunnelConfiguration.ParseError
|
|
||||||
}
|
|
||||||
|
|
||||||
extension WireGuard.Configuration {
|
extension WireGuard.Configuration {
|
||||||
public init(wgQuickConfig: String) throws {
|
public init(wgQuickConfig: String) throws {
|
||||||
do {
|
tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: wgQuickConfig)
|
||||||
tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: wgQuickConfig)
|
|
||||||
} catch let parseError as TunnelConfiguration.ParseError {
|
|
||||||
throw ConfigurationError(parseError: parseError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func asWgQuickConfig() -> String {
|
public func asWgQuickConfig() -> String {
|
||||||
|
|
|
@ -77,7 +77,7 @@ extension WireGuard {
|
||||||
|
|
||||||
public init(_ base64PrivateKey: String) throws {
|
public init(_ base64PrivateKey: String) throws {
|
||||||
guard let privateKey = PrivateKey(base64Key: base64PrivateKey) else {
|
guard let privateKey = PrivateKey(base64Key: base64PrivateKey) else {
|
||||||
throw WireGuard.ConfigurationError.invalidKey
|
throw WireGuard.ConfigurationError.interfaceHasInvalidPrivateKey(base64PrivateKey)
|
||||||
}
|
}
|
||||||
self.init(privateKey)
|
self.init(privateKey)
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ extension WireGuard {
|
||||||
|
|
||||||
public mutating func addPeer(_ base64PublicKey: String, endpoint: String, allowedIPs: [String] = []) throws {
|
public mutating func addPeer(_ base64PublicKey: String, endpoint: String, allowedIPs: [String] = []) throws {
|
||||||
guard let publicKey = PublicKey(base64Key: base64PublicKey) else {
|
guard let publicKey = PublicKey(base64Key: base64PublicKey) else {
|
||||||
throw WireGuard.ConfigurationError.invalidKey
|
throw WireGuard.ConfigurationError.peerHasInvalidPublicKey(base64PublicKey)
|
||||||
}
|
}
|
||||||
var peer = PeerConfiguration(publicKey: publicKey)
|
var peer = PeerConfiguration(publicKey: publicKey)
|
||||||
peer.endpoint = Endpoint(from: endpoint)
|
peer.endpoint = Endpoint(from: endpoint)
|
||||||
|
@ -174,7 +174,7 @@ extension WireGuard {
|
||||||
|
|
||||||
public mutating func setPreSharedKey(_ base64Key: String, ofPeer peerIndex: Int) throws {
|
public mutating func setPreSharedKey(_ base64Key: String, ofPeer peerIndex: Int) throws {
|
||||||
guard let preSharedKey = PreSharedKey(base64Key: base64Key) else {
|
guard let preSharedKey = PreSharedKey(base64Key: base64Key) else {
|
||||||
throw WireGuard.ConfigurationError.invalidKey
|
throw WireGuard.ConfigurationError.peerHasInvalidPreSharedKey(base64Key)
|
||||||
}
|
}
|
||||||
peers[peerIndex].preSharedKey = preSharedKey
|
peers[peerIndex].preSharedKey = preSharedKey
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,8 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import WireGuardKit
|
||||||
|
|
||||||
extension WireGuard {
|
extension WireGuard {
|
||||||
public enum ConfigurationError: Error {
|
public typealias ConfigurationError = TunnelConfiguration.ParseError
|
||||||
case invalidKey
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ extension TunnelConfiguration {
|
||||||
case notInASection
|
case notInASection
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ParseError: Error {
|
public enum ParseError: Error {
|
||||||
case invalidLine(String.SubSequence)
|
case invalidLine(String.SubSequence)
|
||||||
case noInterface
|
case noInterface
|
||||||
case multipleInterfaces
|
case multipleInterfaces
|
||||||
|
|
Loading…
Reference in New Issue