mod commands;
mod controller;
mod responses;
pub use controller::prompt;
use tokio::sync::mpsc;
pub struct DialogParams {
pub dialog_type: DialogType,
pub title: String,
pub description: String,
pub prompt: String,
pub label_yes: String,
pub label_cancel: String,
pub label_no: Option<String>,
}
pub enum DialogType {
Password,
Confirmation,
Notification,
}
#[derive(Debug)]
pub enum Command {
Title(String),
Description(String),
Prompt(String),
OKButton(String),
CancelButton(String),
NotOKButton(String),
TimeOut(i64),
Data(Vec<u8>),
End,
Cancel,
Password,
Confirm,
Notify,
Exit,
}
#[derive(Debug)]
pub enum Response {
Status(String, String),
Enquiry(String, String),
Comment(String),
Success(String),
Failure(i64, String),
DataOK(Vec<u8>, String),
DataFail(Vec<u8>, i64, String),
DataBuffered,
}
#[derive(Debug, thiserror::Error)]
pub enum ErrorKind {
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
SendResponse(#[from] mpsc::error::SendError<Response>),
#[error(transparent)]
SendCommand(#[from] mpsc::error::SendError<Command>),
#[error(transparent)]
ParserError(#[from] pest::error::Error<responses::Rule>),
#[error("Encountered empty response from pinentry")]
EmptyResponse,
#[error("Encountered unexpected response from pinentry: {0}")]
UnexpectedResponse(String),
#[error("Attempted command failed")]
CommandFail,
#[error("User cancelled operation")]
UserCancel,
#[error("User did not confirm")]
UserNo,
}
pub type Result<T> = std::result::Result<T, ErrorKind>;