Add string conversion for tunnel config.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
cd6cb37163
commit
b1aadaf82c
|
@ -57,6 +57,20 @@ extension Interface {
|
|||
}
|
||||
}
|
||||
|
||||
func export() -> String {
|
||||
var exportString = "[Interface]\n"
|
||||
if let privateKey = privateKey {
|
||||
exportString.append("PrivateKey=\(privateKey)")
|
||||
}
|
||||
if listenPort > 0 {
|
||||
exportString.append("ListenPort=\(listenPort)")
|
||||
}
|
||||
|
||||
exportString.append("\n")
|
||||
|
||||
return exportString
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum InterfaceValidationError: Error {
|
||||
|
|
|
@ -63,6 +63,29 @@ extension Peer {
|
|||
}
|
||||
}
|
||||
|
||||
func export() -> String {
|
||||
var exportString = "[Peer]\n"
|
||||
if let publicKey = publicKey {
|
||||
exportString.append("PublicKey=\(publicKey)\n")
|
||||
}
|
||||
if let presharedKey = presharedKey {
|
||||
exportString.append("PresharedKey=\(presharedKey)\n")
|
||||
}
|
||||
if let allowedIPs = allowedIPs {
|
||||
exportString.append("AllowedIPs=\(allowedIPs)\n")
|
||||
}
|
||||
if let endpoint = endpoint {
|
||||
exportString.append("Endpoint=\(endpoint)\n")
|
||||
}
|
||||
if persistentKeepalive > 0 {
|
||||
exportString.append("PersistentKeepalive=\(persistentKeepalive)\n")
|
||||
}
|
||||
|
||||
exportString.append("\n")
|
||||
|
||||
return exportString
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum PeerValidationError: Error {
|
||||
|
|
|
@ -159,6 +159,21 @@ extension Tunnel {
|
|||
return tunnel
|
||||
}
|
||||
|
||||
func export() -> String {
|
||||
var exportString = ""
|
||||
if let interfaceExport = self.interface?.export() {
|
||||
exportString.append(interfaceExport)
|
||||
}
|
||||
|
||||
if let peers = peers?.array as? [Peer] {
|
||||
peers.forEach {
|
||||
exportString.append($0.export())
|
||||
}
|
||||
}
|
||||
|
||||
return exportString
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func base64KeyToHex(_ base64: String?) -> String? {
|
||||
|
|
Loading…
Reference in New Issue