From c3fccec0c2283c936c9cc0ef1e80a3a4805c72d0 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 17 Aug 2022 20:02:30 +0800 Subject: [PATCH] Only check the file hash if the x-goog-hash header is present --- .../Sources/Services/AudioSession/AudioSession.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift index 8ff2d93db..d9a262e25 100644 --- a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift +++ b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift @@ -219,10 +219,13 @@ public class AudioSession: ObservableObject { .appendingPathComponent(UUID().uuidString + ".mp3") do { - let hash = Data(Insecure.MD5.hash(data: data)).base64EncodedString() -// if let googleHash = httpResponse.value(forHTTPHeaderField: "x-goog-hash"), googleHash.contains("md5=\(hash)") { -// throw BasicError.message(messageText: "Downloaded mp3 file hashes do not match: returned: \(googleHash) v computed: \(hash)") -// } + if let googleHash = httpResponse.value(forHTTPHeaderField: "x-goog-hash") { + let hash = Data(Insecure.MD5.hash(data: data)).base64EncodedString() + if !googleHash.contains("md5=\(hash)") { + print("Downloaded mp3 file hashes do not match: returned: \(googleHash) v computed: \(hash)") + throw BasicError.message(messageText: "Downloaded mp3 file hashes do not match: returned: \(googleHash) v computed: \(hash)") + } + } try data.write(to: tempPath) try FileManager.default.moveItem(at: tempPath, to: audioUrl)