keyfork/keyfork-seed/src/main.rs

54 lines
1.5 KiB
Rust
Raw Normal View History

use keyfork_derive_util::{request::*, DerivationPath};
use keyfork_frame::*;
use std::path::PathBuf;
mod cli;
mod socket;
2023-09-12 04:00:30 +00:00
mod client;
#[cfg(test)]
mod tests;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("The first argument to the command should be a derivation path")]
Args,
#[error("The given path was incorrectly formatted: {0}")]
ArgsFormat(#[from] keyfork_derive_util::path::Error),
#[error("Neither KEYFORK_SOCKET_PATH nor XDG_RUNTIME_DIR were set")]
EnvVarsNotFound,
#[error("Socket was unable to connect to {1}: {0}")]
Connect(std::io::Error, PathBuf),
#[error("Could not write to or from the socket: {0}")]
Io(#[from] std::io::Error),
#[error("Could not perform bincode transformation: {0}")]
Bincode(#[from] Box<bincode::ErrorKind>),
#[error("Could not perform frame transformation: {0}")]
FrameEnc(#[from] EncodeError),
#[error("Could not perform frame transformation: {0}")]
FrameDec(#[from] DecodeError),
}
2023-09-12 04:00:30 +00:00
pub type Result<T, E = Error> = std::result::Result<T, E>;
fn main() -> Result<()> {
let args = cli::get_args();
2023-09-12 04:00:30 +00:00
let socket = socket::get_socket()?;
let mut client = client::Client::new(socket);
let path = args.get_one::<DerivationPath>("path").expect("required");
let algo = args
.get_one::<DerivationAlgorithm>("algorithm")
.expect("required");
2023-09-12 04:00:30 +00:00
let request = DerivationRequest::new(algo.clone(), path.clone());
let response = client.request(&request)?;
dbg!(&response);
Ok(())
}