@@ -27,23 +27,15 @@ const AES_IV_LENGTH: usize = 16;
2727#[ cfg_attr( test, derive( Debug ) ) ]
2828#[ derive( Clone , Default ) ]
2929pub struct Dataset {
30- pub address : String ,
3130 pub url : String ,
3231 pub checksum : String ,
3332 pub filename : String ,
3433 pub key : String ,
3534}
3635
3736impl Dataset {
38- pub fn new (
39- address : String ,
40- url : String ,
41- checksum : String ,
42- filename : String ,
43- key : String ,
44- ) -> Self {
37+ pub fn new ( url : String , checksum : String , filename : String , key : String ) -> Self {
4538 Dataset {
46- address,
4739 url,
4840 checksum,
4941 filename,
@@ -88,7 +80,7 @@ impl Dataset {
8880 download_from_url ( & self . url )
8981 }
9082 . ok_or ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed (
91- self . address . clone ( ) ,
83+ self . filename . clone ( ) ,
9284 ) ) ?;
9385
9486 info ! ( "Checking encrypted dataset checksum [chainTaskId:{chain_task_id}]" ) ;
@@ -100,7 +92,7 @@ impl Dataset {
10092 self . checksum
10193 ) ;
10294 return Err ( ReplicateStatusCause :: PreComputeInvalidDatasetChecksum (
103- self . address . clone ( ) ,
95+ self . filename . clone ( ) ,
10496 ) ) ;
10597 }
10698
@@ -126,12 +118,12 @@ impl Dataset {
126118 encrypted_content : & [ u8 ] ,
127119 ) -> Result < Vec < u8 > , ReplicateStatusCause > {
128120 let key = general_purpose:: STANDARD . decode ( & self . key ) . map_err ( |_| {
129- ReplicateStatusCause :: PreComputeDatasetDecryptionFailed ( self . address . clone ( ) )
121+ ReplicateStatusCause :: PreComputeDatasetDecryptionFailed ( self . filename . clone ( ) )
130122 } ) ?;
131123
132124 if encrypted_content. len ( ) < AES_IV_LENGTH || key. len ( ) != AES_KEY_LENGTH {
133125 return Err ( ReplicateStatusCause :: PreComputeDatasetDecryptionFailed (
134- self . address . clone ( ) ,
126+ self . filename . clone ( ) ,
135127 ) ) ;
136128 }
137129
@@ -142,7 +134,7 @@ impl Dataset {
142134 Aes256CbcDec :: new ( key_slice. into ( ) , iv_slice. into ( ) )
143135 . decrypt_padded_vec_mut :: < Pkcs7 > ( ciphertext)
144136 . map_err ( |_| {
145- ReplicateStatusCause :: PreComputeDatasetDecryptionFailed ( self . address . clone ( ) )
137+ ReplicateStatusCause :: PreComputeDatasetDecryptionFailed ( self . filename . clone ( ) )
146138 } )
147139 }
148140}
@@ -160,12 +152,11 @@ mod tests {
160152 "0x02a12ef127dcfbdb294a090c8f0b69a0ca30b7940fc36cabf971f488efd374d7" ;
161153 const ENCRYPTED_DATASET_KEY : & str = "ubA6H9emVPJT91/flYAmnKHC0phSV3cfuqsLxQfgow0=" ;
162154 const HTTP_DATASET_URL : & str = "https://raw.githubusercontent.com/iExecBlockchainComputing/tee-worker-pre-compute-rust/main/src/tests_resources/encrypted-data.bin" ;
163- const PLAIN_DATA_FILE : & str = "plain-data.txt " ;
155+ const PLAIN_DATA_FILE : & str = "0xDatasetAddress " ;
164156 const IPFS_DATASET_URL : & str = "/ipfs/QmUVhChbLFiuzNK1g2GsWyWEiad7SXPqARnWzGumgziwEp" ;
165157
166158 fn get_test_dataset ( ) -> Dataset {
167159 Dataset :: new (
168- "0xDatasetAddress" . to_string ( ) ,
169160 HTTP_DATASET_URL . to_string ( ) ,
170161 DATASET_CHECKSUM . to_string ( ) ,
171162 PLAIN_DATA_FILE . to_string ( ) ,
@@ -185,12 +176,11 @@ mod tests {
185176 fn download_encrypted_dataset_failure_with_invalid_dataset_url ( ) {
186177 let mut dataset = get_test_dataset ( ) ;
187178 dataset. url = "http://bad-url" . to_string ( ) ;
188- dataset. address = "0xbaddataset" . to_string ( ) ;
189179 let actual_content = dataset. download_encrypted_dataset ( CHAIN_TASK_ID ) ;
190180 assert_eq ! (
191181 actual_content,
192182 Err ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed (
193- "0xbaddataset" . to_string( )
183+ PLAIN_DATA_FILE . to_string( )
194184 ) )
195185 ) ;
196186 }
@@ -210,10 +200,9 @@ mod tests {
210200 fn download_encrypted_dataset_failure_with_invalid_gateway ( ) {
211201 let mut dataset = get_test_dataset ( ) ;
212202 dataset. url = "/ipfs/INVALID_IPFS_DATASET_URL" . to_string ( ) ;
213- dataset. address = "0xinvalidgateway" . to_string ( ) ;
214203 let actual_content = dataset. download_encrypted_dataset ( CHAIN_TASK_ID ) ;
215204 let expected_content = Err ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed (
216- "0xinvalidgateway" . to_string ( ) ,
205+ PLAIN_DATA_FILE . to_string ( ) ,
217206 ) ) ;
218207 assert_eq ! ( actual_content, expected_content) ;
219208 }
@@ -222,10 +211,9 @@ mod tests {
222211 fn download_encrypted_dataset_failure_with_invalid_dataset_checksum ( ) {
223212 let mut dataset = get_test_dataset ( ) ;
224213 dataset. checksum = "invalid_dataset_checksum" . to_string ( ) ;
225- dataset. address = "0xinvalidchecksum" . to_string ( ) ;
226214 let actual_content = dataset. download_encrypted_dataset ( CHAIN_TASK_ID ) ;
227215 let expected_content = Err ( ReplicateStatusCause :: PreComputeInvalidDatasetChecksum (
228- "0xinvalidchecksum" . to_string ( ) ,
216+ PLAIN_DATA_FILE . to_string ( ) ,
229217 ) ) ;
230218 assert_eq ! ( actual_content, expected_content) ;
231219 }
@@ -247,14 +235,13 @@ mod tests {
247235 fn decrypt_dataset_failure_with_bad_key ( ) {
248236 let mut dataset = get_test_dataset ( ) ;
249237 dataset. key = "bad_key" . to_string ( ) ;
250- dataset. address = "0xbadkey" . to_string ( ) ;
251238 let encrypted_data = dataset. download_encrypted_dataset ( CHAIN_TASK_ID ) . unwrap ( ) ;
252239 let actual_plain_data = dataset. decrypt_dataset ( & encrypted_data) ;
253240
254241 assert_eq ! (
255242 actual_plain_data,
256243 Err ( ReplicateStatusCause :: PreComputeDatasetDecryptionFailed (
257- "0xbadkey" . to_string( )
244+ PLAIN_DATA_FILE . to_string( )
258245 ) )
259246 ) ;
260247 }
0 commit comments