diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..577b6acf --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.2.0] - 2022-07-20 + +### Changed + +- This library no longer performs the decoding of the SMTP transparency encoding before generating a signature. + +## [0.1.5] - 2022-06-28 + +### Added + +- Exposed method in order to be able to provide an existing resolver. diff --git a/Cargo.lock b/Cargo.lock index ea068d98..d4c99c7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,7 +69,7 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cfdkim" -version = "0.1.5" +version = "0.2.0" dependencies = [ "base64", "chrono", diff --git a/Cargo.toml b/Cargo.toml index ad6f9308..42f9304f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cfdkim" -version = "0.1.5" +version = "0.2.0" authors = ["Sven Sauleau "] edition = "2021" description = "DKIM (RFC6376) implementation" diff --git a/src/hash.rs b/src/hash.rs index aaabe222..71056ab6 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -1,8 +1,6 @@ use indexmap::set::IndexSet; use mailparse::MailHeaderMap; use slog::debug; -use std::io::BufRead; -use std::io::BufReader; use crate::canonicalization::{ self, canonicalize_body_relaxed, canonicalize_body_simple, canonicalize_header_relaxed, @@ -17,31 +15,8 @@ pub enum HashAlgo { } /// Get the body part of an email -/// De-transparency according to RFC 5321, Section 4.5.2 fn get_body<'a>(email: &'a mailparse::ParsedMail<'a>) -> Result, DKIMError> { - let body = bytes::get_all_after(email.raw_bytes, b"\r\n\r\n"); - let mut reader = BufReader::new(body); - - let mut buffer = Vec::new(); - - loop { - let mut line = Vec::new(); - let byte_read = reader - .read_until(b'\n', &mut line) - .map_err(|_err| DKIMError::MalformedBody)?; - if byte_read == 0 { - break; - } - - // Remove leading period - if line[0] == b'.' { - line.remove(0); - } - - buffer.append(&mut line); - } - - Ok(buffer) + Ok(bytes::get_all_after(email.raw_bytes, b"\r\n\r\n").to_vec()) } fn hash_sha1>(data: T) -> Vec { @@ -404,7 +379,7 @@ Hello Alice #[test] fn test_get_body() { let email = - mailparse::parse_mail("Subject: A\r\n\r\nContent\n..hi\n..hello..".as_bytes()).unwrap(); + mailparse::parse_mail("Subject: A\r\n\r\nContent\n.hi\n.hello..".as_bytes()).unwrap(); assert_eq!( String::from_utf8_lossy(&get_body(&email).unwrap()), "Content\n.hi\n.hello..".to_owned()