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.
This commit is contained in:
Justus Winter 2024-11-14 16:50:27 +01:00
parent b916a13426
commit 0a8ba2b3f7
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
3 changed files with 7 additions and 29 deletions

2
NEWS
View File

@ -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

View File

@ -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<String>,
#[command(flatten)]
pub signers: CertDesignators<CertUserIDEmailFileArgs,

View File

@ -2,7 +2,6 @@ use std::io;
use std::path::PathBuf;
use std::time::SystemTime;
use anyhow::anyhow;
use anyhow::Context;
use sequoia_openpgp as openpgp;
@ -87,7 +86,7 @@ pub fn encrypt<'a, 'b: 'a>(
compression: CompressionMode,
time: Option<SystemTime>,
use_expired_subkey: bool,
set_metadata_filename: bool,
set_metadata_filename: Option<String>,
)
-> 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()