From 2130ca0dcf3c482a5735cd4ca213861e00d0103f Mon Sep 17 00:00:00 2001 From: core Date: Thu, 27 Nov 2025 20:47:13 -0500 Subject: [PATCH] feat(0.1.3): autodecrypt w/all local identities --- Cargo.toml | 2 +- README.md | 5 ++--- src/main.rs | 3 +-- src/wrapper.rs | 15 ++++++++++++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8c71130d756c646fe33a5f21ec29f99879a8b3e2..a3afcd241040a9e2d977f365245642d0bd03a7d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sage" -version = "0.1.2" +version = "0.1.3" edition = "2024" license = "AGPL-3.0-only" description = "A simple wrapper for `age` to add a named identity system." diff --git a/README.md b/README.md index 02e20bdbbdcc9f7c2c8c9cf07629a467a201d11a..423e391f66770928ef34a2419cda52c168242356 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ USAGE: OPTIONS: -h, --help Prints help information - -D, --database Set the database file (default /home/core/.config/sage.toml) + -D, --database Set the database file (default ($PLATFORM_CONFIG_DIR)/sage.toml) -v, --verbose Enable debug logging -e, --encrypt Encrypt the input to the output. Default if omitted. @@ -44,8 +44,7 @@ will be ignored. "-" may be used to read identities from standard input. When --encrypt is specified explicitly, -i can also be used to encrypt to an identity file symmetrically, instead or in addition to normal recipients. -If an identity is omitted and only one local identity exists in the database, -it will be chosen automatically. +If decrypting and an identity is omitted, all local identities will be used. SUBCOMMANDS: diff --git a/src/main.rs b/src/main.rs index 3f16aec838edb2d998f6e8bc2b43a55e7ef55fcb..b80f12cf31418d226bc706135919c051d101977b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,8 +120,7 @@ will be ignored. \"-\" may be used to read identities from standard input. When --encrypt is specified explicitly, -i can also be used to encrypt to an identity file symmetrically, instead or in addition to normal recipients. -If an identity is omitted and only one local identity exists in the database, -it will be chosen automatically. +If decrypting and an identity is omitted, all local identities will be used. SUBCOMMANDS: diff --git a/src/wrapper.rs b/src/wrapper.rs index d77584178e0ca0d2d38b09e9ee9a1de978740fca..f2b69330302b8e3ea042e6b259cc64fc85f77f44 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -109,7 +109,7 @@ pub fn wrapper(mut pargs: Arguments, db_path: &Path) -> anyhow::Result<()> { }) .collect::>(); // resolve identities - let resolved_identities = identities.iter() + let mut resolved_identities = identities.iter() .map(|u| { // is this already a valid key? if u.starts_with("AGE-SECRET-KEY") { @@ -142,6 +142,18 @@ pub fn wrapper(mut pargs: Arguments, db_path: &Path) -> anyhow::Result<()> { }) .collect::>(); + if matches!(mode, Mode::Decrypt) && resolved_identities.is_empty() { + // include all local identities instead + for key in &db.keys { + if let IdKeyData::Local(sk) = &key.keys { + resolved_identities.push(sk.into()); + if verbose { + eprintln!("including identity {:?}", key); + } + } + } + } + if verbose { eprintln!("resolved recipients: {:#?}", resolved_recipients); } @@ -179,6 +191,7 @@ pub fn wrapper(mut pargs: Arguments, db_path: &Path) -> anyhow::Result<()> { args.push("--identity".to_string()); args.push(i_tmpfile.path().display().to_string()); } + if let Some(i) = input { args.push(i.display().to_string()); }