#![warn(missing_docs)]
#![warn(rust_2018_idioms)]
#![forbid(unsafe_code)]
use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
pub mod commands;
pub mod keystore;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Keystore(#[from] keystore::Error),
#[error("{0}")]
Cyphr(#[from] cyphr::Error),
#[error("{0}")]
Json(#[from] serde_json::Error),
#[error("invalid base64url: {0}")]
Base64(#[from] base64ct::Error),
#[error("missing field: {0}")]
MissingField(&'static str),
#[error("{0}")]
InvalidArgument(String),
#[error("{0}")]
Signing(String),
#[error("{0}")]
Storage(String),
#[error("{0}")]
FileStore(#[from] cyphr_storage::FileStoreError),
#[error("{0}")]
Load(#[from] cyphr_storage::LoadError),
#[error("{0}")]
Export(#[from] cyphr_storage::ExportError),
}
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Parser)]
#[command(name = "cyphr", version, about, long_about = None)]
pub struct Cli {
#[arg(long, default_value = "file:./cyphr-data")]
pub store: String,
#[arg(long, default_value = "./cyphr-keys.json")]
pub keystore: PathBuf,
#[arg(long, default_value = "cyphr.me")]
pub authority: String,
#[arg(long, value_enum, default_value_t = OutputFormat::Table)]
pub output: OutputFormat,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum OutputFormat {
Table,
Json,
}
#[derive(Subcommand)]
pub enum Commands {
Init {
#[arg(long, default_value = "ES256")]
algo: String,
#[arg(long)]
key: Option<String>,
#[arg(long, value_delimiter = ',')]
keys: Option<Vec<String>>,
},
Key {
#[command(subcommand)]
command: KeyCommands,
},
Tx {
#[command(subcommand)]
command: TxCommands,
},
Inspect {
#[arg(long)]
identity: String,
},
Export {
#[arg(long)]
identity: String,
#[arg(long)]
output: PathBuf,
},
Import {
#[arg(long)]
input: PathBuf,
},
}
#[derive(Subcommand)]
pub enum KeyCommands {
Generate {
#[arg(long, default_value = "ES256")]
algo: String,
#[arg(long)]
tag: Option<String>,
},
Add {
#[arg(long)]
identity: String,
#[arg(long)]
key: Option<String>,
#[arg(long)]
signer: String,
},
Revoke {
#[arg(long)]
identity: String,
#[arg(long)]
key: String,
#[arg(long)]
signer: String,
},
List {
#[arg(long)]
identity: Option<String>,
},
}
#[derive(Subcommand)]
pub enum TxCommands {
List {
#[arg(long)]
identity: String,
},
Verify {
#[arg(long)]
identity: String,
},
}