@@ -193,6 +193,12 @@ pub struct Builder {
193
193
#[ serde( flatten) ]
194
194
pub definition : ManifestDefinition ,
195
195
196
+ /// Optional remote URL for the manifest
197
+ pub remote_url : Option < String > ,
198
+
199
+ // If true, the manifest store will not be embedded in the asset on sign
200
+ pub no_embed : bool ,
201
+
196
202
/// container for binary assets (like thumbnails)
197
203
#[ serde( skip) ]
198
204
resources : ResourceStore ,
@@ -481,14 +487,15 @@ impl Builder {
481
487
claim. add_claim_generator_info ( claim_info) ;
482
488
}
483
489
484
- // if let Some(remote_op) = &self.remote_manifest {
485
- // match remote_op {
486
- // RemoteManifest::NoRemote => (),
487
- // RemoteManifest::SideCar => claim.set_external_manifest(),
488
- // RemoteManifest::Remote(r) => claim.set_remote_manifest(r)?,
489
- // RemoteManifest::EmbedWithRemote(r) => claim.set_embed_remote_manifest(r)?,
490
- // };
491
- // }
490
+ if let Some ( remote_url) = & self . remote_url {
491
+ if self . no_embed {
492
+ claim. set_remote_manifest ( remote_url) ?;
493
+ } else {
494
+ claim. set_embed_remote_manifest ( remote_url) ?;
495
+ }
496
+ } else if self . no_embed {
497
+ claim. set_external_manifest ( )
498
+ }
492
499
493
500
if let Some ( title) = definition. title . as_ref ( ) {
494
501
claim. set_title ( Some ( title. to_owned ( ) ) ) ;
@@ -657,7 +664,9 @@ impl Builder {
657
664
where
658
665
R : Read + Seek + ?Sized ,
659
666
{
660
- if self . definition . thumbnail . is_none ( ) {
667
+ // check settings to see if we should auto generate a thumbnail
668
+ let auto_thumbnail = crate :: settings:: get_settings_value :: < bool > ( "builder.auto_thumbnail" ) ?;
669
+ if self . definition . thumbnail . is_none ( ) && auto_thumbnail {
661
670
stream. rewind ( ) ?;
662
671
if let Ok ( ( format, image) ) =
663
672
crate :: utils:: thumbnail:: make_thumbnail_from_stream ( format, stream)
@@ -778,7 +787,7 @@ mod tests {
778
787
use wasm_bindgen_test:: * ;
779
788
780
789
use super :: * ;
781
- use crate :: { manifest_store :: ManifestStore , utils:: test:: temp_signer} ;
790
+ use crate :: { utils:: test:: temp_signer, Reader } ;
782
791
#[ cfg( target_arch = "wasm32" ) ]
783
792
wasm_bindgen_test:: wasm_bindgen_test_configure!( run_in_browser) ;
784
793
@@ -826,6 +835,8 @@ mod tests {
826
835
. to_string ( )
827
836
}
828
837
838
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
839
+ const TEST_IMAGE_CLEAN : & [ u8 ] = include_bytes ! ( "../tests/fixtures/IMG_0003.jpg" ) ;
829
840
const TEST_IMAGE : & [ u8 ] = include_bytes ! ( "../tests/fixtures/CA.jpg" ) ;
830
841
831
842
#[ test]
@@ -951,21 +962,20 @@ mod tests {
951
962
zipped. rewind ( ) . unwrap ( ) ;
952
963
let mut _builder = Builder :: from_archive ( & mut zipped) . unwrap ( ) ;
953
964
954
- // sign the ManifestStoreBuilder and write it to the output stream
965
+ // sign and write to the output stream
955
966
let signer = temp_signer ( ) ;
956
967
builder
957
968
. sign ( format, & mut source, & mut dest, signer. as_ref ( ) )
958
969
. unwrap ( ) ;
959
970
960
971
// read and validate the signed manifest store
961
972
dest. rewind ( ) . unwrap ( ) ;
962
- let manifest_store =
963
- ManifestStore :: from_stream ( format, & mut dest, true ) . expect ( "from_bytes" ) ;
973
+ let manifest_store = Reader :: from_stream ( format, & mut dest) . expect ( "from_bytes" ) ;
964
974
965
975
println ! ( "{}" , manifest_store) ;
966
976
assert ! ( manifest_store. validation_status( ) . is_none( ) ) ;
967
- assert ! ( manifest_store. get_active ( ) . is_some( ) ) ;
968
- let manifest = manifest_store. get_active ( ) . unwrap ( ) ;
977
+ assert ! ( manifest_store. active_manifest ( ) . is_some( ) ) ;
978
+ let manifest = manifest_store. active_manifest ( ) . unwrap ( ) ;
969
979
assert_eq ! ( manifest. title( ) . unwrap( ) , "Test_Manifest" ) ;
970
980
let test_assertion: TestAssertion = manifest. find_assertion ( "org.life.meaning" ) . unwrap ( ) ;
971
981
assert_eq ! ( test_assertion. answer, 42 ) ;
@@ -984,17 +994,17 @@ mod tests {
984
994
. add_resource ( "thumbnail1.jpg" , Cursor :: new ( TEST_IMAGE ) )
985
995
. unwrap ( ) ;
986
996
987
- // sign the ManifestStoreBuilder and write it to the output stream
997
+ // sign and write to the output stream
988
998
let signer = temp_signer ( ) ;
989
999
builder. sign_file ( source, & dest, signer. as_ref ( ) ) . unwrap ( ) ;
990
1000
991
1001
// read and validate the signed manifest store
992
- let manifest_store = ManifestStore :: from_file ( & dest) . expect ( "from_bytes" ) ;
1002
+ let manifest_store = Reader :: from_file ( & dest) . expect ( "from_bytes" ) ;
993
1003
994
1004
println ! ( "{}" , manifest_store) ;
995
1005
assert ! ( manifest_store. validation_status( ) . is_none( ) ) ;
996
1006
assert_eq ! (
997
- manifest_store. get_active ( ) . unwrap( ) . title( ) . unwrap( ) ,
1007
+ manifest_store. active_manifest ( ) . unwrap( ) . title( ) . unwrap( ) ,
998
1008
"Test_Manifest"
999
1009
) ;
1000
1010
}
@@ -1008,15 +1018,14 @@ mod tests {
1008
1018
"sample1.webp" ,
1009
1019
"TUSCANY.TIF" ,
1010
1020
"sample1.svg" ,
1011
- //"APC_0808.dng",
1012
1021
"sample1.wav" ,
1013
1022
"test.avi" ,
1014
- // "sample1.mp3",
1015
- // "sample1.avif",
1016
- // "sample1.heic",
1017
- // "sample1.heif",
1018
- // "video1.mp4",
1019
- // "cloud_manifest.c2pa",
1023
+ "sample1.mp3" ,
1024
+ "sample1.avif" ,
1025
+ "sample1.heic" ,
1026
+ "sample1.heif" ,
1027
+ "video1.mp4" ,
1028
+ "cloud_manifest.c2pa" ,
1020
1029
] ;
1021
1030
for file_name in TESTFILES {
1022
1031
let extension = file_name. split ( '.' ) . last ( ) . unwrap ( ) ;
@@ -1036,21 +1045,23 @@ mod tests {
1036
1045
. add_resource ( "thumbnail1.jpg" , Cursor :: new ( TEST_IMAGE ) )
1037
1046
. unwrap ( ) ;
1038
1047
1039
- // sign the ManifestStoreBuilder and write it to the output stream
1048
+ // sign and write to the output stream
1040
1049
let signer = temp_signer ( ) ;
1041
1050
builder
1042
1051
. sign ( format, & mut source, & mut dest, signer. as_ref ( ) )
1043
1052
. unwrap ( ) ;
1044
1053
1045
1054
// read and validate the signed manifest store
1046
1055
dest. rewind ( ) . unwrap ( ) ;
1047
- let manifest_store =
1048
- ManifestStore :: from_stream ( format, & mut dest, true ) . expect ( "from_bytes" ) ;
1056
+ let manifest_store = Reader :: from_stream ( format, & mut dest) . expect ( "from_bytes" ) ;
1049
1057
1050
1058
println ! ( "{}" , manifest_store) ;
1051
- assert ! ( manifest_store. validation_status( ) . is_none( ) ) ;
1059
+ if format != "c2pa" {
1060
+ // c2pa files will not validate since they have no associated asset
1061
+ assert ! ( manifest_store. validation_status( ) . is_none( ) ) ;
1062
+ }
1052
1063
assert_eq ! (
1053
- manifest_store. get_active ( ) . unwrap( ) . title( ) . unwrap( ) ,
1064
+ manifest_store. active_manifest ( ) . unwrap( ) . title( ) . unwrap( ) ,
1054
1065
"Test_Manifest"
1055
1066
) ;
1056
1067
@@ -1091,15 +1102,48 @@ mod tests {
1091
1102
1092
1103
// read and validate the signed manifest store
1093
1104
dest. rewind ( ) . unwrap ( ) ;
1094
- let manifest_store =
1095
- ManifestStore :: from_stream ( format, & mut dest, true ) . expect ( "from_bytes" ) ;
1105
+ let manifest_store = Reader :: from_stream ( format, & mut dest) . expect ( "from_bytes" ) ;
1096
1106
1097
1107
println ! ( "{}" , manifest_store) ;
1098
1108
#[ cfg( not( target_arch = "wasm32" ) ) ] // skip this until we get wasm async signing working
1099
1109
assert ! ( manifest_store. validation_status( ) . is_none( ) ) ;
1100
1110
assert_eq ! (
1101
- manifest_store. get_active ( ) . unwrap( ) . title( ) . unwrap( ) ,
1111
+ manifest_store. active_manifest ( ) . unwrap( ) . title( ) . unwrap( ) ,
1102
1112
"Test_Manifest"
1103
1113
) ;
1104
1114
}
1115
+
1116
+ #[ test]
1117
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
1118
+ fn test_builder_remote_url ( ) {
1119
+ let mut source = Cursor :: new ( TEST_IMAGE_CLEAN ) ;
1120
+ let mut dest = Cursor :: new ( Vec :: new ( ) ) ;
1121
+
1122
+ let mut builder = Builder :: from_json ( & manifest_json ( ) ) . unwrap ( ) ;
1123
+ builder. remote_url = Some ( "http://my_remote_url" . to_string ( ) ) ;
1124
+ builder. no_embed = true ;
1125
+
1126
+ builder
1127
+ . add_resource ( "thumbnail1.jpg" , Cursor :: new ( TEST_IMAGE ) )
1128
+ . unwrap ( ) ;
1129
+
1130
+ // sign the ManifestStoreBuilder and write it to the output stream
1131
+ let signer = temp_signer ( ) ;
1132
+ let manifest_data = builder
1133
+ . sign ( "image/jpeg" , & mut source, & mut dest, signer. as_ref ( ) )
1134
+ . unwrap ( ) ;
1135
+
1136
+ // check to make sure we have a remote url and no manifest data
1137
+ dest. set_position ( 0 ) ;
1138
+ let _err = c2pa:: Reader :: from_stream ( "image/jpeg" , & mut dest) . expect_err ( "from_bytes" ) ;
1139
+
1140
+ // now validate the manifest against the written asset
1141
+ dest. set_position ( 0 ) ;
1142
+ let reader =
1143
+ c2pa:: Reader :: from_manifest_data_and_stream ( & manifest_data, "image/jpeg" , & mut dest)
1144
+ . expect ( "from_bytes" ) ;
1145
+
1146
+ println ! ( "{}" , reader. json( ) ) ;
1147
+ assert ! ( reader. validation_status( ) . is_none( ) ) ;
1148
+ }
1105
1149
}
0 commit comments