use crate::security::hsm::error::HsmError;
use crate::security::hsm::types::*;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct OperationResponse {
pub status: OperationStatus,
pub data: Option<Vec<u8>>,
pub error: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum OperationStatus {
Success,
Failed,
Pending,
}
pub struct OperationProcessor {
supported_operations: HashMap<String, fn(Vec<u8>) -> Result<Vec<u8>, HsmError>>,
}
impl OperationProcessor {
pub fn new() -> Self {
Self {
supported_operations: HashMap::new(),
}
}
pub fn register_operation(
&mut self,
name: &str,
handler: fn(Vec<u8>) -> Result<Vec<u8>, HsmError>,
) {
self.supported_operations.insert(name.to_string(), handler);
}
pub fn process(&self, operation: &str, data: Vec<u8>) -> Result<Vec<u8>, HsmError> {
match self.supported_operations.get(operation) {
Some(handler) => handler(data),
None => Err(HsmError::UnsupportedOperation(operation.to_string())),
}
}
}
pub fn perform_key_generation(params: KeyGenParams) -> Result<KeyPair, HsmError> {
Ok(KeyPair {
id: uuid::Uuid::new_v4().to_string(),
key_type: params.key_type,
public_key: vec![], private_key_handle: format!("handle-{}", uuid::Uuid::new_v4()),
})
}
pub fn perform_signing(_key_id: &str, _data: &[u8]) -> Result<Vec<u8>, HsmError> {
Err(HsmError::NotImplemented(
"Signing not implemented yet".to_string(),
))
}