diff options
| -rw-r--r-- | Hotline/Hotline/HotlineProtocol.swift | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/Hotline/Hotline/HotlineProtocol.swift b/Hotline/Hotline/HotlineProtocol.swift index 3be58ac..f98e07b 100644 --- a/Hotline/Hotline/HotlineProtocol.swift +++ b/Hotline/Hotline/HotlineProtocol.swift @@ -474,21 +474,14 @@ struct HotlineTransactionField { } init(type: HotlineTransactionFieldType, string: String, encoding: String.Encoding = .ascii, encrypt: Bool = false) { - var stringInput = string - + var bytes = [UInt8](string.utf8) if encrypt { - stringInput = String(string.utf8.map { char in - Character(UnicodeScalar(0xFF - char)) - }) - } - - var stringData: Data? - stringData = stringInput.data(using: encoding, allowLossyConversion: true) - if stringData == nil { - stringData = Data() + bytes = string.utf8.map { char in + return 0xFF - char + } } - - self.init(type: type, dataSize: UInt16(stringData!.count), data: [UInt8](stringData!)) + + self.init(type: type, dataSize: UInt16(bytes.count), data: [UInt8](bytes)) } init(type: HotlineTransactionFieldType, string: String, encrypt: Bool) { |