diff --git a/Sources/Orders/OrdersServiceCustom.swift b/Sources/Orders/OrdersServiceCustom.swift index eb49ca0..057ee44 100644 --- a/Sources/Orders/OrdersServiceCustom.swift +++ b/Sources/Orders/OrdersServiceCustom.swift @@ -391,18 +391,16 @@ extension OrdersServiceCustom { // MARK: - order file generation extension OrdersServiceCustom { - private static func generateManifestFile( - using encoder: JSONEncoder, in root: URL - ) throws -> Data { + private static func generateManifestFile(using encoder: JSONEncoder, in root: URL) throws -> Data { var manifest: [String: String] = [:] let paths = try FileManager.default.subpathsOfDirectory(atPath: root.path) for relativePath in paths { let file = URL(fileURLWithPath: relativePath, relativeTo: root) guard !file.hasDirectoryPath else { continue } - let data = try Data(contentsOf: file) - let hash = SHA256.hash(data: data) - manifest[relativePath] = hash.map { "0\(String($0, radix: 16))".suffix(2) }.joined() + manifest[relativePath] = try SHA256.hash(data: Data(contentsOf: file)).hex } + // Write the manifest file to the root directory + // and return the data for using it in signing. let data = try encoder.encode(manifest) try data.write(to: root.appendingPathComponent("manifest.json")) return data diff --git a/Sources/Passes/PassesServiceCustom.swift b/Sources/Passes/PassesServiceCustom.swift index e1d83b0..b3893bf 100644 --- a/Sources/Passes/PassesServiceCustom.swift +++ b/Sources/Passes/PassesServiceCustom.swift @@ -502,10 +502,10 @@ extension PassesServiceCustom { for relativePath in paths { let file = URL(fileURLWithPath: relativePath, relativeTo: root) guard !file.hasDirectoryPath else { continue } - let data = try Data(contentsOf: file) - let hash = Insecure.SHA1.hash(data: data) - manifest[relativePath] = hash.map { "0\(String($0, radix: 16))".suffix(2) }.joined() + manifest[relativePath] = try Insecure.SHA1.hash(data: Data(contentsOf: file)).hex } + // Write the manifest file to the root directory + // and return the data for using it in signing. let data = try encoder.encode(manifest) try data.write(to: root.appendingPathComponent("manifest.json")) return data diff --git a/Tests/OrdersTests/OrdersTests.swift b/Tests/OrdersTests/OrdersTests.swift index e653da4..247e4de 100644 --- a/Tests/OrdersTests/OrdersTests.swift +++ b/Tests/OrdersTests/OrdersTests.swift @@ -34,7 +34,7 @@ struct OrdersTests { let manifestJSONData = try String(contentsOfFile: orderFolder.path.appending("/manifest.json")).data(using: .utf8) let manifestJSON = try decoder.decode([String: String].self, from: manifestJSONData!) let iconData = try Data(contentsOf: orderFolder.appendingPathComponent("/icon.png")) - let iconHash = Array(SHA256.hash(data: iconData)).hex + let iconHash = SHA256.hash(data: iconData).hex #expect(manifestJSON["icon.png"] == iconHash) #expect(manifestJSON["pet_store_logo.png"] != nil) } diff --git a/Tests/PassesTests/PassesTests.swift b/Tests/PassesTests/PassesTests.swift index 60d8f0c..7f87345 100644 --- a/Tests/PassesTests/PassesTests.swift +++ b/Tests/PassesTests/PassesTests.swift @@ -35,7 +35,7 @@ struct PassesTests { let manifestJSONData = try String(contentsOfFile: passFolder.path.appending("/manifest.json")).data(using: .utf8) let manifestJSON = try decoder.decode([String: String].self, from: manifestJSONData!) let iconData = try Data(contentsOf: passFolder.appendingPathComponent("/icon.png")) - let iconHash = Array(Insecure.SHA1.hash(data: iconData)).hex + let iconHash = Insecure.SHA1.hash(data: iconData).hex #expect(manifestJSON["icon.png"] == iconHash) #expect(manifestJSON["logo.png"] != nil) #expect(manifestJSON["personalizationLogo.png"] != nil) @@ -93,7 +93,7 @@ struct PassesTests { let manifestJSONData = try String(contentsOfFile: passFolder.path.appending("/manifest.json")).data(using: .utf8) let manifestJSON = try decoder.decode([String: String].self, from: manifestJSONData!) let iconData = try Data(contentsOf: passFolder.appendingPathComponent("/personalizationLogo.png")) - let iconHash = Array(Insecure.SHA1.hash(data: iconData)).hex + let iconHash = Insecure.SHA1.hash(data: iconData).hex #expect(manifestJSON["personalizationLogo.png"] == iconHash) } }