From 0a8ba2b3f7c28252c873eb90ced63d50cba731a4 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 14 Nov 2024 16:50:27 +0100 Subject: [PATCH] Make `sq encrypt --set-metadata-filename` take a simple string. - Previously, the file name was constructed from the path of the input file, using some transformations that may be considered surprising (notably, the file name of unspecified encoding was transformed into UTF-8 using a lossy mechanism). - Avoid this opaque transformation by taking an explicit string argument. - Fixes #351. --- NEWS | 2 ++ src/cli/encrypt.rs | 4 ++-- src/commands/encrypt.rs | 30 +++--------------------------- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/NEWS b/NEWS index 5c7bbd5d..4ee14b56 100644 --- a/NEWS +++ b/NEWS @@ -66,6 +66,8 @@ - Add `sq pki path --email` and `sq pki path --name` as additional ways to specify the user ID to authenticate. - The argument `sq encrypt --set-metadata-time` has been removed. + - The argument `sq encrypt --set-metadata-filename` now takes a + string that specifies the file name to be set. * Changes in 0.39.0 ** Notable changes diff --git a/src/cli/encrypt.rs b/src/cli/encrypt.rs index 8ee597ed..e3745e68 100644 --- a/src/cli/encrypt.rs +++ b/src/cli/encrypt.rs @@ -88,14 +88,14 @@ pub struct Command { #[clap( help = "Set the filename of the encrypted file as metadata", - long, + long = "set-metadata-filename", long_help = "Set the filename of the encrypted file as metadata. \ Do note, that this metadata is not signed and as such relying on \ it - on sender or receiver side - is generally considered \ dangerous.", )] - pub set_metadata_filename: bool, + pub set_metadata_filename: Option, #[command(flatten)] pub signers: CertDesignators( compression: CompressionMode, time: Option, use_expired_subkey: bool, - set_metadata_filename: bool, + set_metadata_filename: Option, ) -> Result<()> { @@ -199,31 +198,8 @@ pub fn encrypt<'a, 'b: 'a>( sink = signer.build()?; } - let mut literal_writer = LiteralWriter::new(sink); - - if set_metadata_filename { - literal_writer = literal_writer - .filename( - input - .inner() - .ok_or_else(|| { - anyhow!( - "Can not embed filename when reading from stdin." - ) - })? - .as_path() - .file_name() - .ok_or_else(|| { - anyhow!("Failed to get filename from input.") - })? - .to_str() - .ok_or_else(|| { - anyhow!("Failed to convert filename to string.") - })? - .to_string(), - ) - .context("Setting filename")? - } + let literal_writer = LiteralWriter::new(sink) + .filename(set_metadata_filename.unwrap_or_default())?; let mut writer_stack = literal_writer .build()