From ae925c57de1dd45e26d1a1bca4ba5bc68464e763 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 8 Oct 2020 14:50:57 +1100 Subject: [PATCH] Guarantee little endianness --- .../Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift index 8cb91c6cc..08d3deb44 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift @@ -7,9 +7,8 @@ extension OnionRequestAPI { // The encoding of V2 onion requests looks like: | 4 bytes: size N of ciphertext | N bytes: ciphertext | json as utf8 | guard JSONSerialization.isValidJSONObject(json) else { throw HTTP.Error.invalidJSON } let jsonAsData = try JSONSerialization.data(withJSONObject: json, options: [ .fragmentsAllowed ]) - let ciphertextSize = Int32(ciphertext.count) + let ciphertextSize = Int32(ciphertext.count).littleEndian let ciphertextSizeAsData = withUnsafePointer(to: ciphertextSize) { Data(bytes: $0, count: MemoryLayout.size) } - // TODO: Ensure this is all little endian return ciphertextSizeAsData + ciphertext + jsonAsData }