~core/sage

2130ca0dcf3c482a5735cd4ca213861e00d0103f — core 20 days ago 921334b
feat(0.1.3): autodecrypt w/all local identities
4 files changed, 18 insertions(+), 7 deletions(-)

M Cargo.toml
M README.md
M src/main.rs
M src/wrapper.rs
M Cargo.toml => Cargo.toml +1 -1
@@ 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."

M README.md => README.md +2 -3
@@ 9,7 9,7 @@ USAGE:

OPTIONS:
    -h, --help                  Prints help information
    -D, --database <FILE>       Set the database file (default /home/core/.config/sage.toml)
    -D, --database <FILE>       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:


M src/main.rs => src/main.rs +1 -2
@@ 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:


M src/wrapper.rs => src/wrapper.rs +14 -1
@@ 109,7 109,7 @@ pub fn wrapper(mut pargs: Arguments, db_path: &Path) -> anyhow::Result<()> {
        })
        .collect::<Vec<_>>();
    // 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::<Vec<_>>();

    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());
    }