From 99bdd7a9da8e66ee609ac1d862e25526322b5f9c Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:30:11 -0800 Subject: Fix login/password encoding --- Hotline/Hotline/HotlineProtocol.swift | 19 ++++++------------- 1 file 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) { -- cgit