// // Data+HexCoding.swift // MullvadVPN // // Created by pronebird on 20/06/2019. // Copyright © 2019 Mullvad VPN AB. All rights reserved. // import Foundation extension Data { struct HexEncodingOptions: OptionSet { let rawValue: Int static let upperCase = HexEncodingOptions(rawValue: 1 << 0) } func hexEncodedString(options: HexEncodingOptions = []) -> String { let format = options.contains(.upperCase) ? "%02hhX" : "%02hhx" return map { String(format: format, $0) }.joined() } }