Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/cc_attestation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ pub fn verify_launch_endorsement(host_platform: &str) -> Result<bool> {
.map_err(|e| Error::CCAttestationError(e.to_string()))?)
}
_ => Err(Error::CCAttestationError(format!(
"Launch endorsement verification not supported for platform {}",
host_platform
"Launch endorsement verification not supported for platform {host_platform}"
))),
}
}
2 changes: 1 addition & 1 deletion src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,4 @@ pub enum SoftwareCommands {
#[arg(long = "storage-url", default_value = "http://localhost:8080")]
storage_url: Box<String>,
},
}
}
9 changes: 3 additions & 6 deletions src/cli/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ pub fn handle_model_command(cmd: ModelCommands) -> Result<()> {
manifest::linking::link_dataset_to_model(&model_id, &dataset_id, storage.as_ref())?;

println!(
"Successfully linked dataset {} to model {}",
dataset_id, model_id
"Successfully linked dataset {dataset_id} to model {model_id}"
);
println!("Updated manifest ID: {}", updated_manifest.instance_id);

Expand Down Expand Up @@ -404,13 +403,11 @@ pub fn handle_cc_attestation_command(cmd: CCAttestationCommands) -> Result<()> {
let result = cc_attestation::verify_launch_endorsement(&host_platform).unwrap();
if result {
println!(
"Passed: launch endorsement verification for {} host platform",
host_platform
"Passed: launch endorsement verification for {host_platform} host platform"
);
} else {
println!(
"Failed: launch endorsement verification for {} host platform",
host_platform
"Failed: launch endorsement verification for {host_platform} host platform"
);
}
Ok(())
Expand Down
24 changes: 12 additions & 12 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ pub const CLI_NAME: &str = "c2pa-cli";

pub fn format_error(error: &Error) -> String {
match error {
Error::Io(err) => format!("IO error: {}", err),
Error::Storage(msg) => format!("Storage error: {}", msg),
Error::Validation(msg) => format!("Validation error: {}", msg),
Error::Manifest(msg) => format!("Manifest error: {}", msg),
Error::Signing(msg) => format!("Signing error: {}", msg),
Error::Serialization(msg) => format!("Serialization error: {}", msg),
Error::InitializationError(msg) => format!("Initialization error: {}", msg),
Error::HexDecode(err) => format!("Hex decode error: {}", err),
Error::CCAttestationError(msg) => format!("CC attestation error: {}", msg),
Error::Json(err) => format!("JSON error: {}", err),
Error::Io(err) => format!("IO error: {err}"),
Error::Storage(msg) => format!("Storage error: {msg}"),
Error::Validation(msg) => format!("Validation error: {msg}"),
Error::Manifest(msg) => format!("Manifest error: {msg}"),
Error::Signing(msg) => format!("Signing error: {msg}"),
Error::Serialization(msg) => format!("Serialization error: {msg}"),
Error::InitializationError(msg) => format!("Initialization error: {msg}"),
Error::HexDecode(err) => format!("Hex decode error: {err}"),
Error::CCAttestationError(msg) => format!("CC attestation error: {msg}"),
Error::Json(err) => format!("JSON error: {err}"),
}
}

/// Helper function to print validation warnings to the user
pub fn print_validation_warning(message: &str) {
eprintln!("Warning: {}", message);
eprintln!("Warning: {message}");
}

/// Helper function to confirm actions with the user
pub fn confirm_action(prompt: &str) -> bool {
use std::io::{self, Write};

print!("{} [y/N]: ", prompt);
print!("{prompt} [y/N]: ");
io::stdout().flush().unwrap();

let mut input = String::new();
Expand Down
5 changes: 2 additions & 3 deletions src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod tests {
];

for (input, expected) in &test_vectors {
let hash = calculate_hash(*input);
let hash = calculate_hash(input);
assert_eq!(&hash, expected);
}
}
Expand Down Expand Up @@ -210,8 +210,7 @@ mod tests {
e.to_string().contains("empty")
|| e.to_string().contains("no hashes")
|| e.to_string().contains("invalid input"),
"Expected error about empty input, got: {}",
e
"Expected error about empty input, got: {e}"
);
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/manifest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ pub fn create_manifest(config: ManifestCreationConfig, asset_kind: AssetKind) ->
// Add the cross-reference to the manifest
manifest.cross_references.push(cross_ref);

println!("Added link to manifest: {}", linked_id);
println!("Added link to manifest: {linked_id}");
}
Err(e) => {
println!("Warning: Could not link to manifest {}: {}", linked_id, e);
println!("Warning: Could not link to manifest {linked_id}: {e}");
}
}
}
Expand All @@ -270,7 +270,7 @@ pub fn create_manifest(config: ManifestCreationConfig, asset_kind: AssetKind) ->
"json" => {
let manifest_json =
to_string_pretty(&manifest).map_err(|e| Error::Serialization(e.to_string()))?;
println!("{}", manifest_json);
println!("{manifest_json}");
}
"cbor" => {
let manifest_cbor = serde_cbor::to_vec(&manifest)
Expand All @@ -290,7 +290,7 @@ pub fn create_manifest(config: ManifestCreationConfig, asset_kind: AssetKind) ->
if let Some(storage) = &config.storage {
if !config.print {
let id = storage.store_manifest(&manifest)?;
println!("Manifest stored successfully with ID: {}", id);
println!("Manifest stored successfully with ID: {id}");
}
}

Expand Down Expand Up @@ -345,7 +345,7 @@ pub fn verify_manifest(id: &str, storage: &dyn StorageBackend) -> Result<()> {
atlas_c2pa_lib::manifest::validate_manifest(&manifest)
.map_err(|e| crate::error::Error::Validation(e.to_string()))?;

println!("Verifying manifest with ID: {}", id);
println!("Verifying manifest with ID: {id}");

// Step 2: Verify each ingredient's hash
for ingredient in &manifest.ingredients {
Expand Down Expand Up @@ -701,8 +701,7 @@ fn get_cc_attestation_assertion() -> Result<CustomAssertion> {
Ok(r) => r,
Err(e) => {
return Err(Error::CCAttestationError(format!(
"Failed to get attestation: {}",
e
"Failed to get attestation: {e}"
)))
}
};
Expand All @@ -712,8 +711,7 @@ fn get_cc_attestation_assertion() -> Result<CustomAssertion> {
Ok(p) => p,
Err(e) => {
return Err(Error::CCAttestationError(format!(
"Error detecting attestation platform: {}",
e
"Error detecting attestation platform: {e}"
)))
}
};
Expand Down
9 changes: 3 additions & 6 deletions src/manifest/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ pub fn create_manifest(
metrics_map.insert(parts[0].to_string(), parts[1].to_string());
} else {
return Err(Error::Validation(format!(
"Invalid metric format: {}. Expected format: key=value",
metric
"Invalid metric format: {metric}. Expected format: key=value"
)));
}
}
Expand All @@ -37,12 +36,10 @@ pub fn create_manifest(
// Update the description to include evaluation info
let enhanced_description = match &config.description {
Some(desc) => Some(format!(
"{} (Model: {}, Dataset: {})",
desc, model_id, dataset_id
"{desc} (Model: {model_id}, Dataset: {dataset_id})"
)),
None => Some(format!(
"Evaluation of Model: {} on Dataset: {}",
model_id, dataset_id
"Evaluation of Model: {model_id} on Dataset: {dataset_id}"
)),
};
config.description = enhanced_description;
Expand Down
Loading