Skip to content

Commit 990c03d

Browse files
committed
Bump quick-xml dependency
1 parent 1bc2544 commit 990c03d

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ doctest = false
1919
default = ["ring", "rustls-pemfile", "report"]
2020
rust-crypto = ["ed25519-dalek", "rsa", "sha1", "sha2"]
2121
generate = ["rsa", "rand"]
22-
report = ["quick-xml", "zip"]
22+
report = ["quick-xml", "zip", "hashify"]
2323
test = []
2424
rkyv = ["dep:rkyv", "mail-parser/rkyv"]
2525

@@ -29,7 +29,8 @@ ed25519-dalek = { version = "2.0", optional = true }
2929
flate2 = "1.0.25"
3030
mail-parser = { version = "0.11", features = ["full_encoding"] }
3131
mail-builder = { version = "0.4" }
32-
quick-xml = { version = "0.37", optional = true }
32+
quick-xml = { version = "0.38", optional = true }
33+
hashify = { version = "0.2.6", optional = true }
3334
ring = { version = "0.17", optional = true }
3435
rsa = { version = "0.9.8", optional = true }
3536
rustls-pemfile = { version = "2", optional = true }

src/dkim/canonicalize.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,30 @@ mod test {
245245
),
246246
(
247247
concat!("from:John doe <[email protected]>\r\n", "subject:test\r\n"),
248-
concat!(" body\r\n"),
248+
" body\r\n",
249249
),
250250
(
251251
concat!(
252252
" From : John\tdoe <[email protected]>\t\r\n",
253253
"SUB JECT:\ttest \t \r\n"
254254
),
255-
concat!(" body \t \r\n"),
255+
" body \t \r\n",
256256
),
257257
),
258258
(
259-
concat!("H: value\t\r\n\r\n",),
260-
(concat!("h:value\r\n"), concat!("")),
261-
(concat!("H: value\t\r\n"), concat!("\r\n")),
259+
"H: value\t\r\n\r\n",
260+
("h:value\r\n", ""),
261+
("H: value\t\r\n", "\r\n"),
262262
),
263263
(
264-
concat!("\tx\t: \t\t\tz\r\n\r\nabc",),
265-
(concat!("x:z\r\n"), concat!("abc\r\n")),
266-
("\tx\t: \t\t\tz\r\n", concat!("abc\r\n")),
264+
"\tx\t: \t\t\tz\r\n\r\nabc",
265+
("x:z\r\n", "abc\r\n"),
266+
("\tx\t: \t\t\tz\r\n", "abc\r\n"),
267267
),
268268
(
269-
concat!("Subject: hello\r\n\r\n\r\n",),
270-
(concat!("subject:hello\r\n"), ""),
271-
("Subject: hello\r\n", concat!("\r\n")),
269+
"Subject: hello\r\n\r\n\r\n",
270+
("subject:hello\r\n", ""),
271+
("Subject: hello\r\n", "\r\n"),
272272
),
273273
] {
274274
let mut header_iterator = HeaderIterator::new(message.as_bytes());

src/dkim/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl ArcOutput<'_> {
241241
&self.result
242242
}
243243

244-
pub fn sets(&self) -> &[Set] {
244+
pub fn sets(&'_ self) -> &'_ [Set<'_>] {
245245
&self.set
246246
}
247247
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub trait ResolverCache<K, V>: Sized {
6969
fn insert(&self, key: K, value: V, valid_until: Instant);
7070
}
7171

72-
#[derive(Debug, Clone, Copy, Default)]
72+
#[derive(Debug, Clone, Copy, Default, Hash, PartialEq, Eq)]
7373
pub enum IpLookupStrategy {
7474
/// Only query for A (Ipv4) records
7575
Ipv4Only,

src/report/dmarc/parse.rs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
66

7-
use std::io::{BufRead, Cursor, Read};
8-
use std::net::IpAddr;
9-
use std::str::FromStr;
10-
11-
use flate2::read::GzDecoder;
12-
use mail_parser::{MessageParser, MimeHeaders, PartType};
13-
use quick_xml::events::{BytesStart, Event};
14-
use quick_xml::reader::Reader;
15-
167
use crate::report::{
178
ActionDisposition, Alignment, AuthResult, DKIMAuthResult, DateRange, Disposition, DkimResult,
189
DmarcResult, Error, Extension, Identifier, PolicyEvaluated, PolicyOverride,
1910
PolicyOverrideReason, PolicyPublished, Record, Report, ReportMetadata, Row, SPFAuthResult,
2011
SPFDomainScope, SpfResult,
2112
};
13+
use flate2::read::GzDecoder;
14+
use mail_parser::{MessageParser, MimeHeaders, PartType};
15+
use quick_xml::events::{BytesStart, Event};
16+
use quick_xml::reader::Reader;
17+
use std::borrow::Cow;
18+
use std::io::{BufRead, Cursor, Read};
19+
use std::net::IpAddr;
20+
use std::str::FromStr;
2221

2322
impl Report {
2423
pub fn parse_rfc5322(report: &[u8]) -> Result<Self, Error> {
@@ -707,11 +706,46 @@ impl<R: BufRead> ReaderHelper for Reader<R> {
707706
}
708707

709708
fn next_value<T: FromStr>(&mut self, buf: &mut Vec<u8>) -> Result<Option<T>, String> {
710-
let mut value = None;
709+
let mut value: Option<String> = None;
710+
711711
loop {
712712
match self.read_event_into(buf) {
713713
Ok(Event::Text(e)) => {
714-
value = e.unescape().ok().and_then(|v| T::from_str(v.as_ref()).ok());
714+
let v = e.xml_content().map_err(|e| {
715+
format!(
716+
"Failed to decode text value at position {}: {}",
717+
self.buffer_position(),
718+
e
719+
)
720+
})?;
721+
if let Some(value) = &mut value {
722+
value.push_str(&v);
723+
} else {
724+
value = Some(v.into_owned());
725+
}
726+
}
727+
Ok(Event::GeneralRef(e)) => {
728+
let v = hashify::tiny_map!(e.as_ref(),
729+
b"lt" => "<",
730+
b"gt" => ">",
731+
b"amp" => "&",
732+
b"apos" => "'",
733+
b"quot" => "\"",
734+
)
735+
.map(Cow::Borrowed)
736+
.or_else(|| {
737+
e.resolve_char_ref()
738+
.ok()
739+
.flatten()
740+
.map(|v| Cow::Owned(v.to_string()))
741+
})
742+
.unwrap_or_else(|| e.xml_content().unwrap_or_default());
743+
744+
if let Some(value) = &mut value {
745+
value.push_str(&v);
746+
} else {
747+
value = Some(v.into_owned());
748+
}
715749
}
716750
Ok(Event::End(_)) => {
717751
break;
@@ -733,7 +767,7 @@ impl<R: BufRead> ReaderHelper for Reader<R> {
733767
}
734768
}
735769

736-
Ok(value)
770+
Ok(value.and_then(|v| T::from_str(&v).ok()))
737771
}
738772

739773
fn skip_tag(&mut self, buf: &mut Vec<u8>) -> Result<(), String> {

src/spf/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ mod test {
14231423
},
14241424
),
14251425
(
1426-
concat!("v=spf1 mx:example.org -all ra=postmaster rp=15 rr=e:f:s:n"),
1426+
"v=spf1 mx:example.org -all ra=postmaster rp=15 rr=e:f:s:n",
14271427
Spf {
14281428
version: Version::V1,
14291429
ra: b"postmaster".to_vec().into(),
@@ -1445,7 +1445,7 @@ mod test {
14451445
},
14461446
),
14471447
(
1448-
concat!("v=spf1 ip6:fe80:0000:0000::0000:0000:0000:1 -all"),
1448+
"v=spf1 ip6:fe80:0000:0000::0000:0000:0000:1 -all",
14491449
Spf {
14501450
version: Version::V1,
14511451
ra: None,

0 commit comments

Comments
 (0)