#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum AgentSigningError {
#[error("agent unavailable: {0}")]
Unavailable(String),
#[error("agent connection failed: {0}")]
ConnectionFailed(String),
#[error("agent signing failed: {0}")]
SigningFailed(String),
#[error("agent startup failed: {0}")]
StartupFailed(String),
}
pub trait AgentSigningPort: Send + Sync + 'static {
fn try_sign(
&self,
namespace: &str,
pubkey: &auths_verifier::DevicePublicKey,
data: &[u8],
) -> Result<String, AgentSigningError>;
fn ensure_running(&self) -> Result<(), AgentSigningError>;
fn add_identity(&self, namespace: &str, pkcs8_der: &[u8]) -> Result<(), AgentSigningError>;
}
pub trait AgentTransport: Send + Sync + 'static {
fn serve(&self) -> Result<(), AgentTransportError>;
fn is_available(&self) -> bool;
fn socket_path(&self) -> Option<&std::path::Path>;
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum AgentTransportError {
#[error("bind failed: {0}")]
BindFailed(String),
#[error("transport I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("agent error: {0}")]
AgentError(String),
}
pub struct NoopAgentProvider;
impl AgentSigningPort for NoopAgentProvider {
fn try_sign(
&self,
_namespace: &str,
_pubkey: &auths_verifier::DevicePublicKey,
_data: &[u8],
) -> Result<String, AgentSigningError> {
Err(AgentSigningError::Unavailable(
"agent not supported on this platform".into(),
))
}
fn ensure_running(&self) -> Result<(), AgentSigningError> {
Err(AgentSigningError::Unavailable(
"agent not supported on this platform".into(),
))
}
fn add_identity(&self, _namespace: &str, _pkcs8_der: &[u8]) -> Result<(), AgentSigningError> {
Err(AgentSigningError::Unavailable(
"agent not supported on this platform".into(),
))
}
}