@@ -80,6 +80,13 @@ impl PreComputeAppTrait for PreComputeApp {
8080 Ok ( ( ) )
8181 }
8282
83+ /// Checks whether the output folder specified in `pre_compute_args` exists.
84+ ///
85+ /// # Returns
86+ ///
87+ /// - `Ok(())` if the output directory (`output_dir`) exists.
88+ /// - `Err(ReplicateStatusCause::PreComputeOutputFolderNotFound)` if the directory does not exist,
89+ /// or if `pre_compute_args` is missing.
8390 fn check_output_folder ( & self ) -> Result < ( ) , ReplicateStatusCause > {
8491 let output_dir: & str = & self . pre_compute_args . output_dir ;
8592 let chain_task_id: & str = & self . chain_task_id ;
@@ -95,6 +102,21 @@ impl PreComputeAppTrait for PreComputeApp {
95102 Err ( ReplicateStatusCause :: PreComputeOutputFolderNotFound )
96103 }
97104
105+ /// Downloads the input files listed in `pre_compute_args.input_files` to the specified `output_dir`.
106+ ///
107+ /// Each URL is hashed (SHA-256) to generate a unique local filename.
108+ /// If any download fails, the function returns an error.
109+ ///
110+ /// # Returns
111+ ///
112+ /// - `Ok(())` if all files are downloaded successfully.
113+ /// - `Err(ReplicateStatusCause::PreComputeInputFileDownloadFailed)` if any file fails to download.
114+ ///
115+ /// # Panics
116+ ///
117+ /// This function panics if:
118+ /// - `pre_compute_args` is `None`.
119+ /// - `chain_task_id` is `None`.
98120 fn download_input_files ( & self ) -> Result < ( ) , ReplicateStatusCause > {
99121 let args = & self . pre_compute_args ;
100122 let chain_task_id: & str = & self . chain_task_id ;
@@ -110,6 +132,13 @@ impl PreComputeAppTrait for PreComputeApp {
110132 Ok ( ( ) )
111133 }
112134
135+ /// Downloads the encrypted dataset file from a URL or IPFS multi-address, and verifies its checksum.
136+ ///
137+ /// # Returns
138+ ///
139+ /// * `Ok(Vec<u8>)` containing the dataset's encrypted content if download and verification succeed.
140+ /// * `Err(ReplicateStatusCause::PreComputeDatasetDownloadFailed)` if the download fails or inputs are missing.
141+ /// * `Err(ReplicateStatusCause::PreComputeInvalidDatasetChecksum)` if checksum validation fails.
113142 fn download_encrypted_dataset ( & self ) -> Result < Vec < u8 > , ReplicateStatusCause > {
114143 let args = & self . pre_compute_args ;
115144 let chain_task_id = & self . chain_task_id ;
@@ -152,6 +181,19 @@ impl PreComputeAppTrait for PreComputeApp {
152181 Ok ( encrypted_content)
153182 }
154183
184+ /// Decrypts the provided encrypted dataset bytes using AES-CBC.
185+ ///
186+ /// The first 16 bytes of `encrypted_content` are treated as the IV.
187+ /// The rest is the ciphertext. The decryption key is decoded from a Base64 string.
188+ ///
189+ /// # Arguments
190+ ///
191+ /// * `encrypted_content` - Full encrypted dataset, including the IV prefix.
192+ ///
193+ /// # Returns
194+ ///
195+ /// * `Ok(Vec<u8>)` containing the plaintext dataset if decryption succeeds.
196+ /// * `Err(ReplicateStatusCause::PreComputeDatasetDecryptionFailed)` if the key is missing, decoding fails, or decryption fails.
155197 fn decrypt_dataset ( & self , encrypted_content : & [ u8 ] ) -> Result < Vec < u8 > , ReplicateStatusCause > {
156198 let base64_key: & str = & self . pre_compute_args . encrypted_dataset_base64_key ;
157199
@@ -172,6 +214,18 @@ impl PreComputeAppTrait for PreComputeApp {
172214 . map_err ( |_| ReplicateStatusCause :: PreComputeDatasetDecryptionFailed )
173215 }
174216
217+ /// Saves the decrypted (plain) dataset to disk in the configured output directory.
218+ ///
219+ /// The output filename is taken from `pre_compute_args.plain_dataset_filename`.
220+ ///
221+ /// # Arguments
222+ ///
223+ /// * `plain_dataset` - The dataset content to write to a file.
224+ ///
225+ /// # Returns
226+ ///
227+ /// * `Ok(())` if the file is successfully saved.
228+ /// * `Err(ReplicateStatusCause::PreComputeSavingPlainDatasetFailed)` if the path is invalid or write fails.
175229 fn save_plain_dataset_file ( & self , plain_dataset : & [ u8 ] ) -> Result < ( ) , ReplicateStatusCause > {
176230 let chain_task_id: & str = & self . chain_task_id ;
177231 let args = & self . pre_compute_args ;
0 commit comments