From 38a6ba7091bb41e26cb3fcfa9e4bb7cb3e7d6a1d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 8 Feb 2019 16:15:10 +0100 Subject: KeyEncoding: rename file to match extension filename style Signed-off-by: Jason A. Donenfeld --- WireGuard/Shared/Model/Data+KeyEncoding.swift | 54 +++++++++++++++++++++++++++ WireGuard/Shared/Model/Key.swift | 54 --------------------------- 2 files changed, 54 insertions(+), 54 deletions(-) create mode 100644 WireGuard/Shared/Model/Data+KeyEncoding.swift delete mode 100644 WireGuard/Shared/Model/Key.swift (limited to 'WireGuard/Shared') diff --git a/WireGuard/Shared/Model/Data+KeyEncoding.swift b/WireGuard/Shared/Model/Data+KeyEncoding.swift new file mode 100644 index 0000000..a1abdd7 --- /dev/null +++ b/WireGuard/Shared/Model/Data+KeyEncoding.swift @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved. + +import Foundation + +extension Data { + func isKey() -> Bool { + return self.count == WG_KEY_LEN + } + + func hexKey() -> String? { + if self.count != WG_KEY_LEN { + return nil + } + var out = Data(repeating: 0, count: Int(WG_KEY_LEN_HEX)) + out.withUnsafeMutableBytes { outBytes in + self.withUnsafeBytes { inBytes in + key_to_hex(outBytes, inBytes) + } + } + out.removeLast() + return String(data: out, encoding: .ascii) + } + + init?(hexKey hexString: String) { + self.init(repeating: 0, count: Int(WG_KEY_LEN)) + + if !self.withUnsafeMutableBytes { key_from_hex($0, hexString) } { + return nil + } + } + + func base64Key() -> String? { + if self.count != WG_KEY_LEN { + return nil + } + var out = Data(repeating: 0, count: Int(WG_KEY_LEN_BASE64)) + out.withUnsafeMutableBytes { outBytes in + self.withUnsafeBytes { inBytes in + key_to_base64(outBytes, inBytes) + } + } + out.removeLast() + return String(data: out, encoding: .ascii) + } + + init?(base64Key base64String: String) { + self.init(repeating: 0, count: Int(WG_KEY_LEN)) + + if !self.withUnsafeMutableBytes { key_from_base64($0, base64String) } { + return nil + } + } +} diff --git a/WireGuard/Shared/Model/Key.swift b/WireGuard/Shared/Model/Key.swift deleted file mode 100644 index a1abdd7..0000000 --- a/WireGuard/Shared/Model/Key.swift +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved. - -import Foundation - -extension Data { - func isKey() -> Bool { - return self.count == WG_KEY_LEN - } - - func hexKey() -> String? { - if self.count != WG_KEY_LEN { - return nil - } - var out = Data(repeating: 0, count: Int(WG_KEY_LEN_HEX)) - out.withUnsafeMutableBytes { outBytes in - self.withUnsafeBytes { inBytes in - key_to_hex(outBytes, inBytes) - } - } - out.removeLast() - return String(data: out, encoding: .ascii) - } - - init?(hexKey hexString: String) { - self.init(repeating: 0, count: Int(WG_KEY_LEN)) - - if !self.withUnsafeMutableBytes { key_from_hex($0, hexString) } { - return nil - } - } - - func base64Key() -> String? { - if self.count != WG_KEY_LEN { - return nil - } - var out = Data(repeating: 0, count: Int(WG_KEY_LEN_BASE64)) - out.withUnsafeMutableBytes { outBytes in - self.withUnsafeBytes { inBytes in - key_to_base64(outBytes, inBytes) - } - } - out.removeLast() - return String(data: out, encoding: .ascii) - } - - init?(base64Key base64String: String) { - self.init(repeating: 0, count: Int(WG_KEY_LEN)) - - if !self.withUnsafeMutableBytes { key_from_base64($0, base64String) } { - return nil - } - } -} -- cgit v1.2.3-59-g8ed1b