diff --git a/Cargo.toml b/Cargo.toml index 46e28e5..75649b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,8 @@ x509-parser = "0.15.0" version = "0.21.1" features = [ "dangerous_configuration" ] +[dependencies.serde] +version = "1.0" +features = ["derive"] +optional = true + diff --git a/src/fingerprint/error.rs b/src/fingerprint/error.rs index 1e31d82..2b08cd9 100644 --- a/src/fingerprint/error.rs +++ b/src/fingerprint/error.rs @@ -1,6 +1,6 @@ use {std::fmt, x509_parser::prelude::X509Error}; -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug)] /// Errors which can occur when fingerprinting a certificate pub enum Error { Fmt, diff --git a/src/host/error.rs b/src/host/error.rs index e1d8d9e..ad38fce 100644 --- a/src/host/error.rs +++ b/src/host/error.rs @@ -1,6 +1,6 @@ use std::fmt; -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug, PartialEq)] /// Errors which can occur when parsing a host from a string pub enum Error { MissingSeparator, diff --git a/src/host/mod.rs b/src/host/mod.rs index 3ac93d2..47bb75a 100644 --- a/src/host/mod.rs +++ b/src/host/mod.rs @@ -2,7 +2,11 @@ use std::{fmt, str::FromStr}; mod error; pub use error::Error; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + #[derive(Clone, Debug, Default, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// Represents the fully qualified domain name for this host pub struct Host { pub subdomain: Option, diff --git a/src/prelude.rs b/src/prelude.rs index b2c36a3..f772101 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,5 +5,8 @@ pub use super::{ request::{Error as ParseRequestError, Request}, response::{Error as ParseResponseError, Response}, sender::{CertificateStore, Error as SenderError, Sender, Verifier}, - status::{Error as ParseStatusError, Status, Redirect, TemporaryFailure, PermanentFailure, AuthenticationFailure}, + status::{ + AuthenticationFailure, Error as ParseStatusError, PermanentFailure, Redirect, Status, + TemporaryFailure, + }, }; diff --git a/src/request/error.rs b/src/request/error.rs index 63b807c..9620f09 100644 --- a/src/request/error.rs +++ b/src/request/error.rs @@ -1,6 +1,6 @@ use {crate::prelude::ParseHostError, std::fmt}; -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug, PartialEq)] /// Errors which can occur when parsing a request pub enum Error { MissingSeparator, diff --git a/src/request/mod.rs b/src/request/mod.rs index 9844a35..27e0a57 100644 --- a/src/request/mod.rs +++ b/src/request/mod.rs @@ -1,10 +1,14 @@ use crate::prelude::Host; use std::{fmt, str::FromStr}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + mod error; pub use error::Error; #[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// The full request as sent by the `Sender` and received by the `Receiver` pub struct Request { /// The username of the sender diff --git a/src/response/error.rs b/src/response/error.rs index 639dd4d..5783cfa 100644 --- a/src/response/error.rs +++ b/src/response/error.rs @@ -3,7 +3,7 @@ use { std::{fmt, num::ParseIntError}, }; -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug, PartialEq)] /// Errors which can occur when parsing the response sent by the receving server /// back to the sender pub enum Error { diff --git a/src/response/mod.rs b/src/response/mod.rs index b47b985..fc5cef7 100644 --- a/src/response/mod.rs +++ b/src/response/mod.rs @@ -4,7 +4,11 @@ use std::{fmt, str::FromStr}; mod error; pub use error::Error; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + #[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// Sent from the receiving server back to the sending server pub struct Response { pub status: Status, diff --git a/src/status/error.rs b/src/status/error.rs index 0ba7b82..ecb3e4c 100644 --- a/src/status/error.rs +++ b/src/status/error.rs @@ -1,6 +1,6 @@ use std::fmt; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug)] /// The receiving server sent an unrecognized or invalid status code pub struct Error; diff --git a/src/status/mod.rs b/src/status/mod.rs index 4508ea9..ca88b1d 100644 --- a/src/status/mod.rs +++ b/src/status/mod.rs @@ -1,7 +1,11 @@ mod error; pub use error::Error; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + #[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[repr(u8)] /// Status codes sent back to the sender representing how a receiving server has /// processed a message. @@ -54,6 +58,7 @@ impl TryFrom for Status { } #[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// Status codes representing that a redirect is required pub enum Redirect { /// The mailbox has moved to a different address, and this message @@ -79,6 +84,7 @@ impl TryFrom for Redirect { } #[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// Status codes representing that a temporary failure has occurred. The sending server should /// retry sending the message. pub enum TemporaryFailure { @@ -117,6 +123,7 @@ impl TryFrom for TemporaryFailure { } #[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// Status codes representing that a permanent failure has occurred and the sending /// server should not resend the message. pub enum PermanentFailure { @@ -152,6 +159,7 @@ impl TryFrom for PermanentFailure { } #[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// Status codes representing an authentication failure pub enum AuthenticationFailure { /// This mailserver doesn't accept anonymous mail, and you need to repeat your