diff --git a/keyfork-pinentry/Cargo.toml b/keyfork-pinentry/Cargo.toml index a3d9170..0beb7fe 100644 --- a/keyfork-pinentry/Cargo.toml +++ b/keyfork-pinentry/Cargo.toml @@ -11,7 +11,8 @@ authors = ["Ryan Heywood "] # categories = ["api-bindings", "command-line-interface"] # license = "MIT OR Apache-2.0" license = "MIT" -edition = "2018" +# edition = "2018" +edition = "2021" [dependencies] nom = { version = "7", default-features = false } diff --git a/keyfork-pinentry/src/lib.rs b/keyfork-pinentry/src/lib.rs index 44d1713..ce930ee 100644 --- a/keyfork-pinentry/src/lib.rs +++ b/keyfork-pinentry/src/lib.rs @@ -69,6 +69,24 @@ pub fn default_binary() -> Result { which::which("pinentry-curses").map_err(Into::into) } +fn convert_multiline(line: &str) -> String { + // convert into multiline + let mut converted_line = String::new(); + let mut last_end = 0; + for (start, part) in line.match_indices(&['\n', '\r', '%']) { + converted_line.push_str(line.get(last_end..start).unwrap()); + converted_line.push_str(match part { + "\n" => "%0A", + "\r" => "%0D", + "%" => "%25", + fb => panic!("expected index given to match_indices, got: {fb}"), + }); + last_end = start + part.len(); + } + converted_line.push_str(line.get(last_end..line.len()).unwrap()); + converted_line +} + /// A dialog for requesting a passphrase from the user. pub struct PassphraseInput<'a> { binary: PathBuf, @@ -211,7 +229,7 @@ impl<'a> PassphraseInput<'a> { pinentry.send_request("SETTITLE", Some(title))?; } if let Some(desc) = &self.description { - pinentry.send_request("SETDESC", Some(desc))?; + pinentry.send_request("SETDESC", Some(convert_multiline(desc).as_ref()))?; } if let Some(error) = &self.error { pinentry.send_request("SETERROR", Some(error))?;