Commit
Author: mdecimus [mauro@stalw.art]
Hash: 04a19baf5d8de3d3d24103336f1035a194471202
Timestamp: Sun, 28 Jul 2024 13:14:03 +0000 (3 months ago)

+2 -2 +/-1 browse
Avoid toString panics when formating non-UTF8 DKIM signatures
1diff --git a/src/dkim/headers.rs b/src/dkim/headers.rs
2index aba5e91..83f1752 100644
3--- a/src/dkim/headers.rs
4+++ b/src/dkim/headers.rs
5 @@ -15,7 +15,7 @@ use crate::common::headers::{HeaderWriter, Writer};
6 use super::{Algorithm, Canonicalization, HashAlgorithm, Signature};
7
8 impl Signature {
9- pub(crate) fn write(&self, writer: &mut impl Writer, as_header: bool) {
10+ pub fn write(&self, writer: &mut impl Writer, as_header: bool) {
11 let (header, new_line) = match self.ch {
12 Canonicalization::Relaxed if !as_header => (&b"dkim-signature:"[..], &b" "[..]),
13 _ => (&b"DKIM-Signature: "[..], &b"\r\n\t"[..]),
14 @@ -141,6 +141,6 @@ impl Display for Signature {
15 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16 let mut buf = Vec::new();
17 self.write(&mut buf, false);
18- f.write_str(&String::from_utf8(buf).map_err(|_| std::fmt::Error)?)
19+ f.write_str(&String::from_utf8_lossy(&buf))
20 }
21 }