From 101809195508b9a98ac5bf4cd0871512f652cd10 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 3 Dec 2026 10:11:41 +0800 Subject: [PATCH] refactor(image4): share DER entry projection (#16185) --- src/domain/apple/image4.ts | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/domain/apple/image4.ts b/src/domain/apple/image4.ts index 4c4b70b76cf..fe26980e0cb 100644 --- a/src/domain/apple/image4.ts +++ b/src/domain/apple/image4.ts @@ -1681,26 +1681,14 @@ const parseRestore = async ( return { properties_present: names, values: "redacted" }; }; -const manifestEntry = (range: { - offset: number; - length: number; -}): Image4EntryFact => ({ - role: "manifest", - path: "manifest.der", - offset: range.offset, - length: range.length, - encrypted: false, - compression: "none", -}); - -const restoreEntry = (range: { - offset: number; - length: number; -}): Image4EntryFact => ({ - role: "restore-info", - path: "restore-info.der", - offset: range.offset, - length: range.length, +const derEntry = ( + role: "manifest" | "restore-info", + { offset, length }: ByteRange, +): Image4EntryFact => ({ + role, + path: `${role}.der`, + offset, + length, encrypted: false, compression: "none", }); @@ -1906,7 +1894,7 @@ export const inspectImage4 = async ( manifest = (await parseManifestKids(kids, walk, 0, notes, counter)) ?? null; const range = encodedRange(root); if (manifest !== null && range !== undefined) - entries.push(manifestEntry(range)); + entries.push(derEntry("manifest", range)); } else { // IMG4 is SEQUENCE { "IMG4", IM4P, [0] IM4M, [1] IM4R } (img4tool, // img4lib). Each slot is read from its position; a value that does not @@ -1916,9 +1904,9 @@ export const inspectImage4 = async ( manifest = slots.manifest?.facts ?? null; restore = slots.restore?.facts ?? null; if (slots.manifest !== undefined) - entries.push(manifestEntry(slots.manifest.range)); + entries.push(derEntry("manifest", slots.manifest.range)); if (slots.restore !== undefined) - entries.push(restoreEntry(slots.restore.range)); + entries.push(derEntry("restore-info", slots.restore.range)); if (payloadKids === undefined) notes.add("Image4 container has no IM4P payload."); else {