diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-08 16:15:10 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-08 16:15:10 +0100 |
commit | 38a6ba7091bb41e26cb3fcfa9e4bb7cb3e7d6a1d (patch) | |
tree | 59f7173d9c0b5ea7baa6b480402825d284885236 /WireGuard/Shared/Model/Key.swift | |
parent | Key: we already do len checking in C (diff) | |
download | wireguard-apple-38a6ba7091bb41e26cb3fcfa9e4bb7cb3e7d6a1d.tar.xz wireguard-apple-38a6ba7091bb41e26cb3fcfa9e4bb7cb3e7d6a1d.zip |
KeyEncoding: rename file to match extension filename style
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard/Shared/Model/Key.swift')
-rw-r--r-- | WireGuard/Shared/Model/Key.swift | 54 |
1 files changed, 0 insertions, 54 deletions
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 - } - } -} |