use crate::DriverCallback;
use crate::DriverContext;
use crate::types::{Driver, DriverParameter};
use crate::{DriverError, DriverResult};
use serde_json::{Value, json};
use std::collections::HashMap;
use tracing::{debug, info, warn};
#[derive(Debug)]
pub struct HashMd5TextDriver;
#[async_trait::async_trait]
impl Driver for HashMd5TextDriver {
fn name(&self) -> &str {
"hash_md5_text"
}
fn description(&self) -> &str {
"Calculate MD5 hash of a text string"
}
fn usage_hint(&self) -> &str {
"Use this skill when you need to compute MD5 hash for a text string. For file hashing, use file/hash_md5."
}
fn parameters(&self) -> Vec<DriverParameter> {
return vec![DriverParameter {
name: "input".to_string(),
param_type: "string".to_string(),
description: "Input string to hash".to_string(),
required: true,
default: None,
example: Some(Value::String("Hello World".to_string())),
enum_values: None,
}];
}
fn example_call(&self) -> DriverResult<Value> {
return Ok(json!({
"action": "hash_md5_text",
"parameters": {
"input": "Hello World"
}
}));
}
fn example_output(&self) -> String {
return "MD5: b10a8db164e0754105b7a99be72e3fe5".to_string();
}
fn category(&self) -> crate::DriverCategory {
return crate::DriverCategory::Cryptography;
}
async fn execute(
&self,
parameters: &HashMap<String, Value>,
callback: Option<&dyn DriverCallback>,
context: Option<&DriverContext>,
) -> DriverResult<String> {
debug!("Executing hash_md5_text driver");
let input = parameters.get("input").and_then(|v| v.as_str()).ok_or_else(|| {
debug!("Missing 'input' parameter");
DriverError::missing_parameter("input")
})?;
debug!("Input length: {} characters", input.len());
let digest = md5::compute(input.as_bytes());
info!("MD5 hash computed successfully");
return Ok(format!("MD5: {:x}", digest));
}
fn validate(&self, parameters: &HashMap<String, Value>) -> DriverResult<()> {
debug!("Validating hash_md5_text parameters");
if parameters.get("input").is_none() {
return Err(DriverError::missing_parameter("input"));
}
debug!("Parameter validation passed");
return Ok(());
}
}