Skip to content

Commit 91314cb

Browse files
committed
Change binary diff crate
1 parent 6170567 commit 91314cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+42
-52
lines changed

c2pa-compat/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ serde = { version = "1.0.197", features = ["derive"] }
1515
serde_json = "1.0.117"
1616
ed25519-dalek = "2.1.1"
1717
pem = "3.0.2"
18-
bsdiff = "0.2.0"
18+
diffy = "0.4.0"
1919
lz4_flex = "0.11.3"

c2pa-compat/src/main.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,11 @@ fn main() -> Result<()> {
148148
&mut signed_remote_asset,
149149
)?;
150150

151-
let mut signed_remote_asset_patch = Vec::new();
152-
bsdiff::diff(
153-
&original_asset,
154-
&signed_remote_asset.into_inner(),
155-
&mut signed_remote_asset_patch,
156-
)?;
151+
let signed_remote_asset_patch =
152+
diffy::create_patch_bytes(&original_asset, &signed_remote_asset.into_inner())
153+
.to_bytes();
157154
asset_details.uncompressed_remote_size = Some(signed_remote_asset_patch.len());
158-
// let signed_remote_asset_patch = lz4_flex::compress(&signed_remote_asset_patch);
155+
let signed_remote_asset_patch = lz4_flex::compress(&signed_remote_asset_patch);
159156

160157
fs::write(dir_path.join("remote.patch"), signed_remote_asset_patch)?;
161158
fs::write(dir_path.join("remote.c2pa"), remote_c2pa_manifest)?;
@@ -166,16 +163,11 @@ fn main() -> Result<()> {
166163
Err(err) => return Err(err),
167164
}
168165

169-
// TODO: we don't need to store the entire asset, only the binary diff from the original asset
170-
171-
let mut signed_embedded_asset_patch = Vec::new();
172-
bsdiff::diff(
173-
&original_asset,
174-
&signed_embedded_asset.into_inner(),
175-
&mut signed_embedded_asset_patch,
176-
)?;
166+
let signed_embedded_asset_patch =
167+
diffy::create_patch_bytes(&original_asset, &signed_embedded_asset.into_inner())
168+
.to_bytes();
177169
asset_details.uncompressed_embedded_size = Some(signed_embedded_asset_patch.len());
178-
// let signed_embedded_asset_patch = lz4_flex::compress(&signed_embedded_asset_patch);
170+
let signed_embedded_asset_patch = lz4_flex::compress(&signed_embedded_asset_patch);
179171

180172
fs::write(dir_path.join("embedded.patch"), signed_embedded_asset_patch)?;
181173
fs::write(dir_path.join("embedded.c2pa"), embedded_c2pa_manifest)?;

sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ c2pa = { path = ".", features = [
168168
jumbf = "0.4.0"
169169
insta = { version = "1.39.0", features = ["json", "redactions", "filters"] }
170170
tiny_http = "0.12.0"
171-
bsdiff = "0.2.0"
171+
diffy = "0.4.0"
172172
lz4_flex = "0.11.3"
173173

174174
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]

sdk/tests/compat.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,16 @@ fn test_compat() -> Result<()> {
164164
let remote_asset_path = asset_dir.join("remote.patch");
165165
if remote_asset_path.exists() {
166166
let expected_remote_asset_patch = fs::read(remote_asset_path)?;
167-
// let expected_remote_asset_patch = lz4_flex::decompress(
168-
// &expected_remote_asset_patch,
169-
// asset_details.uncompressed_remote_size.unwrap(),
170-
// )
171-
// .unwrap(); // TODO: err msg
172-
let mut expected_remote_asset = Vec::new();
173-
bsdiff::patch(
167+
let expected_remote_asset_patch = lz4_flex::decompress(
168+
&expected_remote_asset_patch,
169+
asset_details.uncompressed_remote_size.unwrap(),
170+
)
171+
.expect("TODO"); // TODO: err msg
172+
let expected_remote_asset = diffy::apply_bytes(
174173
&original_asset,
175-
&mut Cursor::new(expected_remote_asset_patch),
176-
&mut expected_remote_asset,
177-
)?;
174+
&diffy::Patch::from_bytes(&expected_remote_asset_patch).expect("TODO"),
175+
)
176+
.expect("TODO");
178177

179178
let expected_remote_reader: Reader =
180179
serde_json::from_reader(File::open(asset_dir.join("remote.json"))?)?;
@@ -194,17 +193,16 @@ fn test_compat() -> Result<()> {
194193
}
195194

196195
let expected_embedded_asset_patch = fs::read(asset_dir.join("embedded.patch"))?;
197-
// let expected_embedded_asset_patch = lz4_flex::decompress(
198-
// &expected_embedded_asset_patch,
199-
// asset_details.uncompressed_embedded_size,
200-
// )
201-
// .unwrap(); // TODO: err msg
202-
let mut expected_embedded_asset = Vec::new();
203-
bsdiff::patch(
196+
let expected_embedded_asset_patch = lz4_flex::decompress(
197+
&expected_embedded_asset_patch,
198+
asset_details.uncompressed_embedded_size,
199+
)
200+
.expect("TODO"); // TODO: err msg
201+
let expected_embedded_asset = diffy::apply_bytes(
204202
&original_asset,
205-
&mut Cursor::new(expected_embedded_asset_patch),
206-
&mut expected_embedded_asset,
207-
)?;
203+
&diffy::Patch::from_bytes(&expected_embedded_asset_patch).expect("TODO"),
204+
)
205+
.expect("TODO");
208206

209207
let expected_embedded_reader: Reader =
210208
serde_json::from_reader(File::open(asset_dir.join("embedded.json"))?)?;
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"manifest_store":{"active_manifest":"urn:uuid:c0d2e873-82f4-4354-a7d6-6a60b7b89816","manifests":{"urn:uuid:c0d2e873-82f4-4354-a7d6-6a60b7b89816":{"claim_generator":"test/1.0 c2pa-rs/0.33.0","claim_generator_info":[{"name":"test","version":"1.0"},{"name":"c2pa-rs","version":"0.33.0"}],"format":"video/mp4","instance_id":"xmp:iid:58b9d7fd-d89b-4752-8f78-9f188104b400","ingredients":[],"assertions":[{"label":"c2pa.actions.v2","data":{"actions":[{"action":"c2pa.opened","softwareAgent":{"name":"TestApp","version":"1.0","something":"else"},"parameters":{"description":"import"},"digitalSourceType":"http://cv.iptc.org/newscodes/digitalsourcetype/algorithmicMedia"}]}},{"label":"c2pa.hash.bmff.v2","data":{"exclusions":[{"xpath":"/uuid","length":null,"data":[{"offset":8,"value":[216,254,195,214,27,14,72,60,146,151,88,40,135,126,196,129]}],"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/ftyp","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/meta/iloc","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/mfra/tfra","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/stco","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/co64","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moof/traf/tfhd","length":null,"data":null,"subset":[{"offset":16,"length":8}],"version":null,"flags":[1,0,0],"exact":null},{"xpath":"/moof/traf/trun","length":null,"data":null,"subset":[{"offset":16,"length":4}],"version":null,"flags":[1,0,0],"exact":null}],"alg":"sha256","hash":[200,32,148,169,15,166,231,86,102,210,152,227,69,66,172,110,226,206,198,129,95,47,38,164,140,189,109,46,157,228,177,15],"name":"jumbf manifest"}}],"signature_info":{"alg":"Ed25519","issuer":"C2PA Test Signing Cert","cert_serial_number":"638838410810235485828984295321338730070538954823"},"label":"urn:uuid:c0d2e873-82f4-4354-a7d6-6a60b7b89816"}}}}
1+
{"manifest_store":{"active_manifest":"urn:uuid:22eb8f61-61a9-40a3-a9df-5f694f93340b","manifests":{"urn:uuid:22eb8f61-61a9-40a3-a9df-5f694f93340b":{"claim_generator":"test/1.0 c2pa-rs/0.33.0","claim_generator_info":[{"name":"test","version":"1.0"},{"name":"c2pa-rs","version":"0.33.0"}],"format":"video/mp4","instance_id":"xmp:iid:a1a80ffc-d6e4-40bd-856d-b41b020b1651","ingredients":[],"assertions":[{"label":"c2pa.actions.v2","data":{"actions":[{"action":"c2pa.opened","softwareAgent":{"name":"TestApp","version":"1.0","something":"else"},"parameters":{"description":"import"},"digitalSourceType":"http://cv.iptc.org/newscodes/digitalsourcetype/algorithmicMedia"}]}},{"label":"c2pa.hash.bmff.v2","data":{"exclusions":[{"xpath":"/uuid","length":null,"data":[{"offset":8,"value":[216,254,195,214,27,14,72,60,146,151,88,40,135,126,196,129]}],"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/ftyp","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/meta/iloc","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/mfra/tfra","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/stco","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/co64","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moof/traf/tfhd","length":null,"data":null,"subset":[{"offset":16,"length":8}],"version":null,"flags":[1,0,0],"exact":null},{"xpath":"/moof/traf/trun","length":null,"data":null,"subset":[{"offset":16,"length":4}],"version":null,"flags":[1,0,0],"exact":null}],"alg":"sha256","hash":[200,32,148,169,15,166,231,86,102,210,152,227,69,66,172,110,226,206,198,129,95,47,38,164,140,189,109,46,157,228,177,15],"name":"jumbf manifest"}}],"signature_info":{"alg":"Ed25519","issuer":"C2PA Test Signing Cert","cert_serial_number":"638838410810235485828984295321338730070538954823"},"label":"urn:uuid:22eb8f61-61a9-40a3-a9df-5f694f93340b"}}}}
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"manifest_store":{"active_manifest":"urn:uuid:97f5048a-5544-43d9-b446-30cc1da5792c","manifests":{"urn:uuid:97f5048a-5544-43d9-b446-30cc1da5792c":{"claim_generator":"test/1.0 c2pa-rs/0.33.0","claim_generator_info":[{"name":"test","version":"1.0"},{"name":"c2pa-rs","version":"0.33.0"}],"format":"video/mp4","instance_id":"xmp:iid:a8f09be4-7154-4dc5-ac6f-42ce15b1e262","ingredients":[],"assertions":[{"label":"c2pa.actions.v2","data":{"actions":[{"action":"c2pa.opened","softwareAgent":{"name":"TestApp","version":"1.0","something":"else"},"parameters":{"description":"import"},"digitalSourceType":"http://cv.iptc.org/newscodes/digitalsourcetype/algorithmicMedia"}]}},{"label":"c2pa.hash.bmff.v2","data":{"exclusions":[{"xpath":"/uuid","length":null,"data":[{"offset":8,"value":[216,254,195,214,27,14,72,60,146,151,88,40,135,126,196,129]}],"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/ftyp","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/meta/iloc","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/mfra/tfra","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/stco","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/co64","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moof/traf/tfhd","length":null,"data":null,"subset":[{"offset":16,"length":8}],"version":null,"flags":[1,0,0],"exact":null},{"xpath":"/moof/traf/trun","length":null,"data":null,"subset":[{"offset":16,"length":4}],"version":null,"flags":[1,0,0],"exact":null}],"alg":"sha256","hash":[184,150,116,156,174,50,81,9,210,20,52,43,49,218,250,178,241,170,78,24,130,120,178,139,133,227,229,58,224,106,28,178],"name":"jumbf manifest"}}],"signature_info":{"alg":"Ed25519","issuer":"C2PA Test Signing Cert","cert_serial_number":"638838410810235485828984295321338730070538954823"},"label":"urn:uuid:97f5048a-5544-43d9-b446-30cc1da5792c"}}}}
1+
{"manifest_store":{"active_manifest":"urn:uuid:305b5b3d-2db6-4fb1-9d41-bcfd21bca7d1","manifests":{"urn:uuid:305b5b3d-2db6-4fb1-9d41-bcfd21bca7d1":{"claim_generator":"test/1.0 c2pa-rs/0.33.0","claim_generator_info":[{"name":"test","version":"1.0"},{"name":"c2pa-rs","version":"0.33.0"}],"format":"video/mp4","instance_id":"xmp:iid:3f80e941-cd18-4130-8aae-6d8ca0c33fcd","ingredients":[],"assertions":[{"label":"c2pa.actions.v2","data":{"actions":[{"action":"c2pa.opened","softwareAgent":{"name":"TestApp","version":"1.0","something":"else"},"parameters":{"description":"import"},"digitalSourceType":"http://cv.iptc.org/newscodes/digitalsourcetype/algorithmicMedia"}]}},{"label":"c2pa.hash.bmff.v2","data":{"exclusions":[{"xpath":"/uuid","length":null,"data":[{"offset":8,"value":[216,254,195,214,27,14,72,60,146,151,88,40,135,126,196,129]}],"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/ftyp","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/meta/iloc","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/mfra/tfra","length":null,"data":null,"subset":null,"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/stco","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moov/trak/mdia/minf/stbl/co64","length":null,"data":null,"subset":[{"offset":16,"length":0}],"version":null,"flags":null,"exact":null},{"xpath":"/moof/traf/tfhd","length":null,"data":null,"subset":[{"offset":16,"length":8}],"version":null,"flags":[1,0,0],"exact":null},{"xpath":"/moof/traf/trun","length":null,"data":null,"subset":[{"offset":16,"length":4}],"version":null,"flags":[1,0,0],"exact":null}],"alg":"sha256","hash":[184,150,116,156,174,50,81,9,210,20,52,43,49,218,250,178,241,170,78,24,130,120,178,139,133,227,229,58,224,106,28,178],"name":"jumbf manifest"}}],"signature_info":{"alg":"Ed25519","issuer":"C2PA Test Signing Cert","cert_serial_number":"638838410810235485828984295321338730070538954823"},"label":"urn:uuid:305b5b3d-2db6-4fb1-9d41-bcfd21bca7d1"}}}}
Binary file not shown.

0 commit comments

Comments
 (0)