commit 5afad308c909e0fc14a3088579b5ff32e2bc84a4
parent d140959f11ef3479128cdb358f204cd51b1c150f
Author: Gavin Peacock <gpeacock@adobe.com>
Date: Tue, 1 Aug 2023 21:11:13 -0700
Adds a way to force no claim thumbnail generation (#288)
When add_thumbnails is enabled, setting the manifest thumbnail
format = "none" will force no claim thumbnail generation
Diffstat:
3 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
@@ -25,7 +25,7 @@ We welcome contributions to this project. For information on contributing, prov
## Requirements
-The SDK requires **Rust version 1.65.0** or newer.
+The SDK requires **Rust version 1.70.0** or newer.
### Supported platforms
diff --git a/sdk/src/assertions/thumbnail.rs b/sdk/src/assertions/thumbnail.rs
@@ -40,7 +40,7 @@ impl Thumbnail {
"tiff" => "image/tiff",
"ico" => "image/x-icon",
"webp" => "image/webp",
- _ => "octet-stream",
+ _ => "application/octet-stream",
}
.to_string();
@@ -116,7 +116,7 @@ pub mod tests {
thumbnail_test(labels::JPEG_INGREDIENT_THUMBNAIL, "image/jpeg");
thumbnail_test(labels::PNG_INGREDIENT_THUMBNAIL, "image/png");
// unrecognized labels will be formatted as octet_streams
- thumbnail_test("foo", "octet-stream");
+ thumbnail_test("foo", "application/octet-stream");
}
#[test]
diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs
@@ -239,7 +239,7 @@ impl Manifest {
/// Sets the thumbnail from a ResourceRef.
pub fn set_thumbnail_ref(&mut self, thumbnail: ResourceRef) -> Result<&mut Self> {
// verify the resource referenced exists
- if !self.resources.exists(&thumbnail.identifier) {
+ if thumbnail.format != "none" && !self.resources.exists(&thumbnail.identifier) {
return Err(Error::NotFound);
};
self.thumbnail = Some(thumbnail);
@@ -744,11 +744,14 @@ impl Manifest {
claim.instance_id = self.instance_id().to_owned();
if let Some(thumb_ref) = self.thumbnail_ref() {
- let data = self.resources.get(&thumb_ref.identifier)?;
- claim.add_assertion(&Thumbnail::new(
- &labels::add_thumbnail_format(labels::CLAIM_THUMBNAIL, &thumb_ref.format),
- data.into_owned(),
- ))?;
+ // Setting the format to "none" will ensure that no claim thumbnail is added
+ if thumb_ref.format != "none" {
+ let data = self.resources.get(&thumb_ref.identifier)?;
+ claim.add_assertion(&Thumbnail::new(
+ &labels::add_thumbnail_format(labels::CLAIM_THUMBNAIL, &thumb_ref.format),
+ data.into_owned(),
+ ))?;
+ }
}
// add any verified credentials - needs to happen early so we can reference them
@@ -2109,14 +2112,46 @@ pub(crate) mod tests {
assert!(manifest.thumbnail_ref().is_none());
// verify we can set a references that do exist
assert!(manifest
- .set_thumbnail_ref(ResourceRef::new("image/jpg", "C.jpg"))
+ .set_thumbnail_ref(ResourceRef::new("image/jpeg", "C.jpg"))
+ .is_ok());
+ assert!(manifest.thumbnail_ref().is_some());
+
+ let signer = temp_signer();
+ manifest
+ .embed(&output, &output, signer.as_ref())
+ .expect("embed");
+ }
+
+ #[test]
+ #[cfg(all(feature = "file_io", feature = "add_thumbnails"))]
+ fn test_create_no_claim_thumbnail() {
+ let mut fixtures = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+ fixtures.push("tests/fixtures");
+
+ let temp_dir = tempdir().expect("temp dir");
+ let output = temp_fixture_path(&temp_dir, TEST_SMALL_JPEG);
+
+ let mut manifest = Manifest::new("claim_generator");
+
+ // Set format to none to force no claim thumbnail generated
+ assert!(manifest
+ .set_thumbnail_ref(ResourceRef::new("none", "none"))
.is_ok());
+ // verify there is a thumbnail ref
assert!(manifest.thumbnail_ref().is_some());
+ // verify there is no thumbnail
+ assert!(manifest.thumbnail().is_none());
let signer = temp_signer();
manifest
.embed(&output, &output, signer.as_ref())
.expect("embed");
+
+ let manifest_store = crate::ManifestStore::from_file(&output).expect("from_file");
+ println!("{manifest_store}");
+ let active_manifest = manifest_store.get_active().unwrap();
+ assert!(active_manifest.thumbnail_ref().is_none());
+ assert!(active_manifest.thumbnail().is_none());
}
#[actix::test]