From 8df3b1bb1b644dca823b1ad1dd60cbb5a4eda3b7 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 23 Apr 2024 15:49:58 +0000 Subject: [PATCH] fix: use only CRLF in Autocrypt Setup Message --- src/imex.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/imex.rs b/src/imex.rs index 8e50996385..e672410926 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -193,7 +193,9 @@ pub async fn render_setup_file(context: &Context, passphrase: &str) -> Result Some(("Autocrypt-Prefer-Encrypt", "mutual")), }; let private_key_asc = private_key.to_asc(ac_headers); - let encr = pgp::symm_encrypt(passphrase, private_key_asc.as_bytes()).await?; + let encr = pgp::symm_encrypt(passphrase, private_key_asc.as_bytes()) + .await? + .replace('\n', "\r\n"); let replacement = format!( concat!( @@ -832,15 +834,17 @@ mod tests { let msg = render_setup_file(&t, "hello").await.unwrap(); println!("{}", &msg); // Check some substrings, indicating things got substituted. - // In particular note the mixing of `\r\n` and `\n` depending - // on who generated the strings. assert!(msg.contains("Autocrypt Setup Message</title")); assert!(msg.contains("<h1>Autocrypt Setup Message</h1>")); assert!(msg.contains("<p>This is the Autocrypt Setup Message used to")); assert!(msg.contains("-----BEGIN PGP MESSAGE-----\r\n")); assert!(msg.contains("Passphrase-Format: numeric9x4\r\n")); - assert!(msg.contains("Passphrase-Begin: he\n")); - assert!(msg.contains("-----END PGP MESSAGE-----\n")); + assert!(msg.contains("Passphrase-Begin: he\r\n")); + assert!(msg.contains("-----END PGP MESSAGE-----\r\n")); + + for line in msg.rsplit_terminator('\n') { + assert!(line.ends_with('\r')); + } } #[tokio::test(flavor = "multi_thread", worker_threads = 2)]