Export: fix up export format
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
3611f8cf5a
commit
c5e35fee1e
|
@ -7,40 +7,38 @@ class WgQuickConfigFileWriter {
|
|||
static func writeConfigFile(from tc: TunnelConfiguration) -> Data? {
|
||||
let interface = tc.interface
|
||||
var output = "[Interface]\n"
|
||||
output.append("PrivateKey=\(interface.privateKey.base64EncodedString())\n")
|
||||
output.append("PrivateKey = \(interface.privateKey.base64EncodedString())\n")
|
||||
if let listenPort = interface.listenPort {
|
||||
output.append("ListenPort=\(listenPort)\n")
|
||||
output.append("ListenPort = \(listenPort)\n")
|
||||
}
|
||||
if (!interface.addresses.isEmpty) {
|
||||
let addressString = interface.addresses.map { $0.stringRepresentation() }.joined(separator: ", ")
|
||||
output.append("Address=\(addressString)\n")
|
||||
output.append("Address = \(addressString)\n")
|
||||
}
|
||||
if (!interface.dns.isEmpty) {
|
||||
let dnsString = interface.dns.map { $0.stringRepresentation() }.joined(separator: ", ")
|
||||
output.append("DNS=\(dnsString)\n")
|
||||
output.append("DNS = \(dnsString)\n")
|
||||
}
|
||||
if let mtu = interface.mtu {
|
||||
output.append("MTU=\(mtu)\n")
|
||||
output.append("MTU = \(mtu)\n")
|
||||
}
|
||||
output.append("\n")
|
||||
|
||||
for peer in tc.peers {
|
||||
output.append("[Peer]\n")
|
||||
output.append("PublicKey=\(peer.publicKey.base64EncodedString())\n")
|
||||
output.append("\n[Peer]\n")
|
||||
output.append("PublicKey = \(peer.publicKey.base64EncodedString())\n")
|
||||
if let preSharedKey = peer.preSharedKey {
|
||||
output.append("PresharedKey=\(preSharedKey.base64EncodedString())\n")
|
||||
output.append("PresharedKey = \(preSharedKey.base64EncodedString())\n")
|
||||
}
|
||||
if (!peer.allowedIPs.isEmpty) {
|
||||
let allowedIPsString = peer.allowedIPs.map { $0.stringRepresentation() }.joined(separator: ", ")
|
||||
output.append("AllowedIPs=\(allowedIPsString)\n")
|
||||
output.append("AllowedIPs = \(allowedIPsString)\n")
|
||||
}
|
||||
if let endpoint = peer.endpoint {
|
||||
output.append("Endpoint=\(endpoint.stringRepresentation())\n")
|
||||
output.append("Endpoint = \(endpoint.stringRepresentation())\n")
|
||||
}
|
||||
if let persistentKeepAlive = peer.persistentKeepAlive {
|
||||
output.append("PersistentKeepalive=\(persistentKeepAlive)\n")
|
||||
output.append("PersistentKeepalive = \(persistentKeepAlive)\n")
|
||||
}
|
||||
output.append("\n")
|
||||
}
|
||||
|
||||
return output.data(using: .utf8)
|
||||
|
|
Loading…
Reference in New Issue