Fix crash

pull/80/head
Niels Andriesse 6 years ago
parent 71fe68278d
commit f1a82fde2a

@ -79,7 +79,7 @@ internal class LokiSnodeProxy : LokiHTTPClient {
task.resume() task.resume()
return promise return promise
}.map { rawResponse in }.map { rawResponse in
guard let data = rawResponse as? Data, let cipherText = Data(base64Encoded: data) else { guard let data = rawResponse as? Data, !data.isEmpty, let cipherText = Data(base64Encoded: data) else {
print("[Loki] Received a non-string encoded response.") print("[Loki] Received a non-string encoded response.")
return rawResponse return rawResponse
} }

@ -24,6 +24,7 @@ public enum DiffieHellman {
public static func decrypt(_ encryptedData: Data, using symmetricKey: Data) throws -> Data { public static func decrypt(_ encryptedData: Data, using symmetricKey: Data) throws -> Data {
let symmetricKeyBytes = [UInt8](symmetricKey) let symmetricKeyBytes = [UInt8](symmetricKey)
guard encryptedData.count >= ivLength else { throw "Couldn't decrypt data." }
let ivBytes = [UInt8](encryptedData[..<ivLength]) let ivBytes = [UInt8](encryptedData[..<ivLength])
let cipherBytes = [UInt8](encryptedData[ivLength...]) let cipherBytes = [UInt8](encryptedData[ivLength...])
let blockMode = CBC(iv: ivBytes) let blockMode = CBC(iv: ivBytes)

Loading…
Cancel
Save