2022-08-14 13:27:41 -07:00
|
|
|
use std::fmt::{Display, Formatter};
|
|
|
|
use std::convert::From;
|
|
|
|
use std::str::Utf8Error;
|
|
|
|
|
2022-12-03 21:47:09 -08:00
|
|
|
use sqlx::{
|
|
|
|
error::Error as SqlxError,
|
|
|
|
migrate::MigrateError,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// error during initial setup (primarily loading state from db)
|
|
|
|
pub enum SetupError {
|
|
|
|
InvalidRecord, // e.g. wrong size blob for nonce or salt
|
|
|
|
DbError(SqlxError),
|
|
|
|
}
|
|
|
|
impl From<SqlxError> for SetupError {
|
|
|
|
fn from(e: SqlxError) -> SetupError {
|
|
|
|
SetupError::DbError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl From<MigrateError> for SetupError {
|
|
|
|
fn from (e: MigrateError) -> SetupError {
|
|
|
|
SetupError::DbError(SqlxError::from(e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Display for SetupError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
|
|
|
match self {
|
|
|
|
SetupError::InvalidRecord => write!(f, "Malformed database record"),
|
|
|
|
SetupError::DbError(e) => write!(f, "Error from database: {e}"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 16:16:33 -08:00
|
|
|
|
|
|
|
// error when attempting to tell a request handler whether to release or deny crednetials
|
|
|
|
pub enum SendResponseError {
|
|
|
|
NotFound, // no request with the given id
|
|
|
|
Abandoned, // request has already been closed by client
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for SendResponseError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
|
|
|
use SendResponseError::*;
|
|
|
|
match self {
|
|
|
|
NotFound => write!(f, "The specified command was not found."),
|
|
|
|
Abandoned => write!(f, "The specified request was closed by the client."),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-14 13:27:41 -07:00
|
|
|
|
|
|
|
|
2022-11-28 16:16:33 -08:00
|
|
|
// errors encountered while handling an HTTP request
|
2022-08-14 13:27:41 -07:00
|
|
|
pub enum RequestError {
|
|
|
|
StreamIOError(std::io::Error),
|
|
|
|
InvalidUtf8,
|
|
|
|
MalformedHttpRequest,
|
|
|
|
RequestTooLarge,
|
2022-12-03 21:47:09 -08:00
|
|
|
NoCredentials(GetCredentialsError),
|
2022-12-13 16:50:44 -08:00
|
|
|
ClientInfo(ClientInfoError),
|
2022-12-19 15:26:44 -08:00
|
|
|
Tauri(tauri::Error),
|
|
|
|
NoMainWindow,
|
2022-08-14 13:27:41 -07:00
|
|
|
}
|
|
|
|
impl From<tokio::io::Error> for RequestError {
|
|
|
|
fn from(e: std::io::Error) -> RequestError {
|
|
|
|
RequestError::StreamIOError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl From<Utf8Error> for RequestError {
|
|
|
|
fn from(_e: Utf8Error) -> RequestError {
|
|
|
|
RequestError::InvalidUtf8
|
|
|
|
}
|
|
|
|
}
|
2022-12-03 21:47:09 -08:00
|
|
|
impl From<GetCredentialsError> for RequestError {
|
|
|
|
fn from (e: GetCredentialsError) -> RequestError {
|
|
|
|
RequestError::NoCredentials(e)
|
|
|
|
}
|
|
|
|
}
|
2022-12-13 16:50:44 -08:00
|
|
|
impl From<ClientInfoError> for RequestError {
|
|
|
|
fn from(e: ClientInfoError) -> RequestError {
|
|
|
|
RequestError::ClientInfo(e)
|
|
|
|
}
|
|
|
|
}
|
2022-12-19 15:26:44 -08:00
|
|
|
impl From<tauri::Error> for RequestError {
|
|
|
|
fn from(e: tauri::Error) -> RequestError {
|
|
|
|
RequestError::Tauri(e)
|
|
|
|
}
|
|
|
|
}
|
2022-08-14 13:27:41 -07:00
|
|
|
|
|
|
|
impl Display for RequestError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
|
|
|
use RequestError::*;
|
|
|
|
match self {
|
|
|
|
StreamIOError(e) => write!(f, "Stream IO error: {e}"),
|
|
|
|
InvalidUtf8 => write!(f, "Could not decode UTF-8 from bytestream"),
|
|
|
|
MalformedHttpRequest => write!(f, "Maformed HTTP request"),
|
|
|
|
RequestTooLarge => write!(f, "HTTP request too large"),
|
2022-12-03 21:47:09 -08:00
|
|
|
NoCredentials(GetCredentialsError::Locked) => write!(f, "Recieved go-ahead but app is locked"),
|
|
|
|
NoCredentials(GetCredentialsError::Empty) => write!(f, "Received go-ahead but no credentials are known"),
|
2022-12-13 16:50:44 -08:00
|
|
|
ClientInfo(ClientInfoError::PidNotFound) => write!(f, "Could not resolve PID of client process."),
|
|
|
|
ClientInfo(ClientInfoError::NetstatError(e)) => write!(f, "Error getting client socket details: {e}"),
|
2022-12-19 15:26:44 -08:00
|
|
|
Tauri(e) => write!(f, "Tauri error: {e}"),
|
|
|
|
NoMainWindow => write!(f, "No main application window found"),
|
2022-08-14 13:27:41 -07:00
|
|
|
}
|
|
|
|
}
|
2022-12-02 22:59:13 -08:00
|
|
|
}
|
2022-12-03 21:47:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
pub enum GetCredentialsError {
|
|
|
|
Locked,
|
|
|
|
Empty,
|
|
|
|
}
|
|
|
|
|
2022-12-19 15:26:44 -08:00
|
|
|
pub type AwsTokenError = aws_sdk_sts::types::SdkError<aws_sdk_sts::error::GetSessionTokenError>;
|
|
|
|
|
|
|
|
pub enum GetSessionError {
|
|
|
|
NoCredentials, // SDK returned successfully but credentials are None
|
|
|
|
SdkError(AwsTokenError),
|
|
|
|
}
|
|
|
|
impl From<AwsTokenError> for GetSessionError {
|
|
|
|
fn from(e: AwsTokenError) -> GetSessionError {
|
|
|
|
GetSessionError::SdkError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Display for GetSessionError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
|
|
|
match self {
|
|
|
|
GetSessionError::NoCredentials => write!(f, "Request completed successfully but no credentials were returned"),
|
|
|
|
GetSessionError::SdkError(e) => write!(f, "Error response from AWS: {e}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 21:47:09 -08:00
|
|
|
|
|
|
|
pub enum UnlockError {
|
|
|
|
NotLocked,
|
|
|
|
NoCredentials,
|
|
|
|
BadPassphrase,
|
|
|
|
InvalidUtf8, // Somehow we got invalid utf-8 even though decryption succeeded
|
|
|
|
DbError(SqlxError),
|
2022-12-19 15:26:44 -08:00
|
|
|
GetSession(GetSessionError),
|
2022-12-03 21:47:09 -08:00
|
|
|
}
|
|
|
|
impl From<SqlxError> for UnlockError {
|
|
|
|
fn from (e: SqlxError) -> UnlockError {
|
|
|
|
match e {
|
|
|
|
SqlxError::RowNotFound => UnlockError::NoCredentials,
|
|
|
|
_ => UnlockError::DbError(e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-19 15:26:44 -08:00
|
|
|
impl From<GetSessionError> for UnlockError {
|
|
|
|
fn from(e: GetSessionError) -> UnlockError {
|
|
|
|
UnlockError::GetSession(e)
|
|
|
|
}
|
|
|
|
}
|
2022-12-03 21:47:09 -08:00
|
|
|
impl Display for UnlockError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
|
|
|
use UnlockError::*;
|
|
|
|
match self {
|
|
|
|
NotLocked => write!(f, "App is not locked"),
|
|
|
|
NoCredentials => write!(f, "No saved credentials were found"),
|
|
|
|
BadPassphrase => write!(f, "Invalid passphrase"),
|
|
|
|
InvalidUtf8 => write!(f, "Decrypted data was corrupted"),
|
|
|
|
DbError(e) => write!(f, "Database error: {e}"),
|
2022-12-19 15:26:44 -08:00
|
|
|
GetSession(e) => write!(f, "Failed to create AWS session: {e}")
|
2022-12-03 21:47:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Errors encountered while trying to figure out who's on the other end of a request
|
|
|
|
pub enum ClientInfoError {
|
|
|
|
PidNotFound,
|
|
|
|
NetstatError(netstat2::error::Error),
|
|
|
|
}
|
|
|
|
impl From<netstat2::error::Error> for ClientInfoError {
|
|
|
|
fn from(e: netstat2::error::Error) -> ClientInfoError {
|
|
|
|
ClientInfoError::NetstatError(e)
|
|
|
|
}
|
|
|
|
}
|