store in client
This commit is contained in:
1 parent
64ee239d1d
commit
a520ddb557
10 files changed
+575
-347
No files matched your search
@@ -20,6 +20,10 @@ struct Cli {
|
||||
/// Password protecting the identity file.
|
||||
#[arg(short, long, env = "MEOW_PASSWORD", hide_env_values = true, global = true)]
|
||||
password: Option<String>,
|
||||
/// Hidden-space password(s) to try after opening (repeatable). A password that opens
|
||||
/// nothing is silently ignored.
|
||||
#[arg(short = 'u', long = "unlock", global = true)]
|
||||
unlock: Vec<String>,
|
||||
/// Use very weak key derivation (tests only!).
|
||||
#[arg(long, env = "MEOW_INSECURE_FAST_KDF", hide = true, global = true)]
|
||||
insecure_fast_kdf: bool,
|
||||
@@ -87,6 +91,11 @@ enum IdentityCmd {
|
||||
},
|
||||
/// Show the identity summary.
|
||||
Show,
|
||||
/// Change the main password.
|
||||
Password {
|
||||
#[arg(long)]
|
||||
new_password: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -104,8 +113,23 @@ enum ServerCmd {
|
||||
#[derive(Subcommand)]
|
||||
enum ContactCmd {
|
||||
List,
|
||||
Show { name: String },
|
||||
Remove { name: String },
|
||||
Show {
|
||||
name: String,
|
||||
},
|
||||
Remove {
|
||||
name: String,
|
||||
},
|
||||
/// Move a contact (with its history) into the hidden space opened by a password
|
||||
/// (created if needed). Several contacts may share one.
|
||||
Hide {
|
||||
name: String,
|
||||
#[arg(long)]
|
||||
space_password: String,
|
||||
},
|
||||
/// Move a hidden contact (unlock its space with -u) back to the main space.
|
||||
Reveal {
|
||||
name: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@@ -186,15 +210,20 @@ fn default_identity() -> PathBuf {
|
||||
struct Ctx {
|
||||
identity: PathBuf,
|
||||
password: String,
|
||||
unlock: Vec<String>,
|
||||
kdf: KdfParams,
|
||||
downloads: PathBuf,
|
||||
}
|
||||
|
||||
impl Ctx {
|
||||
async fn open(&self) -> Result<MeowClient> {
|
||||
MeowClient::open(&self.identity, &self.password, self.kdf)
|
||||
let mut c = MeowClient::open(&self.identity, &self.password)
|
||||
.await
|
||||
.with_context(|| format!("cannot open identity {}", self.identity.display()))
|
||||
.with_context(|| format!("cannot open identity {}", self.identity.display()))?;
|
||||
for pw in &self.unlock {
|
||||
c.unlock(pw).await?;
|
||||
}
|
||||
Ok(c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,6 +252,7 @@ async fn run() -> Result<()> {
|
||||
let ctx = Ctx {
|
||||
identity: cli.identity.unwrap_or_else(default_identity),
|
||||
password,
|
||||
unlock: cli.unlock,
|
||||
kdf: if cli.insecure_fast_kdf {
|
||||
KdfParams::INSECURE_TEST
|
||||
} else {
|
||||
@@ -245,6 +275,10 @@ async fn run() -> Result<()> {
|
||||
println!("servers: {}", c.servers().len());
|
||||
println!("contacts: {}", c.contacts().len());
|
||||
}
|
||||
Cmd::Identity(IdentityCmd::Password { new_password }) => {
|
||||
ctx.open().await?.change_password(&new_password).await?;
|
||||
println!("password changed");
|
||||
}
|
||||
Cmd::Server(ServerCmd::Add { url }) => {
|
||||
let mut c = ctx.open().await?;
|
||||
let s = c.add_server(&url).await?;
|
||||
@@ -263,7 +297,8 @@ async fn run() -> Result<()> {
|
||||
Cmd::Contact(ContactCmd::List) => {
|
||||
let c = ctx.open().await?;
|
||||
for k in c.contacts() {
|
||||
println!("{}\t{:?}", k.name, k.state);
|
||||
let hidden = if c.is_hidden(&k.name)? { "\t[hidden]" } else { "" };
|
||||
println!("{}\t{:?}{hidden}", k.name, k.state);
|
||||
}
|
||||
}
|
||||
Cmd::Contact(ContactCmd::Show { name }) => {
|
||||
@@ -300,6 +335,14 @@ async fn run() -> Result<()> {
|
||||
ctx.open().await?.remove_contact(&name).await?;
|
||||
println!("removed {name}");
|
||||
}
|
||||
Cmd::Contact(ContactCmd::Hide { name, space_password }) => {
|
||||
ctx.open().await?.hide_contact(&name, &space_password).await?;
|
||||
println!("{name} is now hidden");
|
||||
}
|
||||
Cmd::Contact(ContactCmd::Reveal { name }) => {
|
||||
ctx.open().await?.reveal_contact(&name).await?;
|
||||
println!("{name} is now visible");
|
||||
}
|
||||
Cmd::Invitation(cmd) => invitation(&ctx, cmd).await?,
|
||||
Cmd::ServerInvitation(ServerInvitationCmd::Create {
|
||||
contact,
|
||||
@@ -455,7 +498,9 @@ fn print_events(ctx: &Ctx, events: &[Event]) -> Result<()> {
|
||||
for e in events {
|
||||
match e {
|
||||
Event::Message { contact, text, .. } => println!("[{contact}] {text}"),
|
||||
Event::File { contact, name, data } => {
|
||||
Event::File {
|
||||
contact, name, data, ..
|
||||
} => {
|
||||
std::fs::create_dir_all(&ctx.downloads)?;
|
||||
let path = ctx.downloads.join(safe_name(name));
|
||||
std::fs::write(&path, data)?;
|
||||
|
||||
Reference in new issue
Block a user