aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/Tunnel
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-08 00:44:14 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-08 03:23:15 +0100
commit05547861b65100279027a64f58793caea1143a30 (patch)
treec69303b55e68e93efc71d2b199119019f1199ff6 /WireGuard/WireGuard/Tunnel
parentTunnelsManager: Ignore status changes on tunnel providers we don't have (diff)
downloadwireguard-apple-05547861b65100279027a64f58793caea1143a30.tar.xz
wireguard-apple-05547861b65100279027a64f58793caea1143a30.zip
Key: Constant time encoding
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard/WireGuard/Tunnel')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift27
1 files changed, 3 insertions, 24 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift b/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift
index 63a8570f..b72223d5 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift
@@ -88,7 +88,7 @@ extension TunnelConfiguration {
guard let privateKeyString = attributes["private_key"] else {
throw ParseError.interfaceHasNoPrivateKey
}
- guard let privateKey = Data(hexEncoded: privateKeyString), privateKey.count == TunnelConfiguration.keyLength else {
+ guard let privateKey = Data(hexKey: privateKeyString), privateKey.count == TunnelConfiguration.keyLength else {
throw ParseError.interfaceHasInvalidPrivateKey(privateKeyString)
}
var interface = InterfaceConfiguration(privateKey: privateKey)
@@ -108,12 +108,12 @@ extension TunnelConfiguration {
guard let publicKeyString = attributes["public_key"] else {
throw ParseError.peerHasNoPublicKey
}
- guard let publicKey = Data(hexEncoded: publicKeyString), publicKey.count == TunnelConfiguration.keyLength else {
+ guard let publicKey = Data(hexKey: publicKeyString), publicKey.count == TunnelConfiguration.keyLength else {
throw ParseError.peerHasInvalidPublicKey(publicKeyString)
}
var peer = PeerConfiguration(publicKey: publicKey)
if let preSharedKeyString = attributes["preshared_key"] {
- guard let preSharedKey = Data(hexEncoded: preSharedKeyString), preSharedKey.count == TunnelConfiguration.keyLength else {
+ guard let preSharedKey = Data(hexKey: preSharedKeyString), preSharedKey.count == TunnelConfiguration.keyLength else {
throw ParseError.peerHasInvalidPreSharedKey(preSharedKeyString)
}
// TODO(zx2c4): does the compiler optimize this away?
@@ -184,24 +184,3 @@ extension TunnelConfiguration {
return peer
}
}
-
-extension Data {
- //swiftlint:disable identifier_name
- init?(hexEncoded hexString: String) {
- if hexString.count % 2 != 0 {
- return nil
- }
- let len = hexString.count / 2
- self.init(capacity: len)
- for i in 0..<len {
- let j = hexString.index(hexString.startIndex, offsetBy: i * 2)
- let k = hexString.index(j, offsetBy: 2)
- let bytes = hexString[j..<k]
- if var num = UInt8(bytes, radix: 16) {
- append(&num, count: 1)
- } else {
- return nil
- }
- }
- }
-}