diff --git a/Cargo.toml b/Cargo.toml index aafb1533..bff4600a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "web-push" description = "Web push notification client with support for http-ece encryption and VAPID authentication." -version = "0.9.0" +version = "0.9.1" authors = ["Julius de Bruijn ", "Andrew Ealovega "] license = "Apache-2.0" homepage = "https://github.com/pimeys/rust-web-push" diff --git a/src/clients/hyper_client.rs b/src/clients/hyper_client.rs index 11277f2d..5490b001 100644 --- a/src/clients/hyper_client.rs +++ b/src/clients/hyper_client.rs @@ -1,3 +1,5 @@ +use std::convert::Infallible; + use http::header::{CONTENT_LENGTH, RETRY_AFTER}; use hyper::{body::HttpBody, client::HttpConnector, Body, Client, Request as HttpRequest}; use hyper_tls::HttpsConnector; @@ -5,7 +7,6 @@ use hyper_tls::HttpsConnector; use crate::clients::request_builder; use crate::error::{RetryAfter, WebPushError}; use crate::message::WebPushMessage; -use std::convert::Infallible; /// An async client for sending the notification payload. /// diff --git a/src/clients/isahc_client.rs b/src/clients/isahc_client.rs index b087d3d5..cf494fad 100644 --- a/src/clients/isahc_client.rs +++ b/src/clients/isahc_client.rs @@ -1,10 +1,10 @@ +use futures_lite::AsyncReadExt; use http::header::{CONTENT_LENGTH, RETRY_AFTER}; use isahc::HttpClient; use crate::clients::request_builder; use crate::error::{RetryAfter, WebPushError}; use crate::message::WebPushMessage; -use futures_lite::AsyncReadExt; /// An async client for sending the notification payload. This client is expensive to create, and /// should be reused. diff --git a/src/clients/request_builder.rs b/src/clients/request_builder.rs index 92caa18f..5e567188 100644 --- a/src/clients/request_builder.rs +++ b/src/clients/request_builder.rs @@ -1,10 +1,11 @@ //! Functions used to send and consume push http messages. //! This module can be used to build custom clients. -use crate::{error::WebPushError, message::WebPushMessage}; use http::header::{CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE}; use http::{Request, StatusCode}; +use crate::{error::WebPushError, message::WebPushMessage}; + #[derive(Deserialize, Serialize, Debug, PartialEq)] struct ErrorInfo { code: u16, @@ -87,11 +88,12 @@ pub fn parse_response(response_status: StatusCode, body: Vec) -> Result<(), #[cfg(test)] mod tests { + use http::Uri; + use crate::clients::request_builder::*; use crate::error::WebPushError; use crate::http_ece::ContentEncoding; use crate::message::WebPushMessageBuilder; - use http::Uri; #[test] fn builds_a_correct_request_with_empty_payload() { diff --git a/src/error.rs b/src/error.rs index 2b2c68be..921461d4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,11 +1,12 @@ -use base64::DecodeError; -use http::uri::InvalidUri; -use serde_json::error::Error as JsonError; use std::string::FromUtf8Error; use std::time::{Duration, SystemTime}; use std::{convert::From, error::Error, fmt, io::Error as IoError}; -#[derive(PartialEq, Debug)] +use base64::DecodeError; +use http::uri::InvalidUri; +use serde_json::error::Error as JsonError; + +#[derive(PartialEq, Debug, Clone, Ord, PartialOrd, Eq, Deserialize, Serialize, Hash)] pub enum WebPushError { /// An unknown error happened encrypting the message, Unspecified, diff --git a/src/http_ece.rs b/src/http_ece.rs index ac1bdd7e..54c2fe4b 100644 --- a/src/http_ece.rs +++ b/src/http_ece.rs @@ -1,7 +1,8 @@ +use ece::encrypt; + use crate::error::WebPushError; use crate::message::WebPushPayload; use crate::vapid::VapidSignature; -use ece::encrypt; /// Content encoding profiles. pub enum ContentEncoding { @@ -78,12 +79,13 @@ impl<'a> HttpEce<'a> { #[cfg(test)] mod tests { + use base64::{self, URL_SAFE}; + use regex::Regex; + use crate::error::WebPushError; use crate::http_ece::{ContentEncoding, HttpEce}; use crate::VapidSignature; use crate::WebPushPayload; - use base64::{self, URL_SAFE}; - use regex::Regex; #[test] fn test_payload_too_big() { diff --git a/src/lib.rs b/src/lib.rs index c3903afa..ee438746 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,29 +42,24 @@ //! # } //! ``` -#[macro_use] -extern crate serde_derive; #[macro_use] extern crate log; - -mod clients; -mod error; -mod http_ece; -mod message; -mod vapid; +#[macro_use] +extern crate serde_derive; #[cfg(feature = "hyper-client")] pub use crate::clients::hyper_client::WebPushClient; - #[cfg(not(feature = "hyper-client"))] pub use crate::clients::isahc_client::WebPushClient; - +pub use crate::clients::request_builder; pub use crate::error::WebPushError; - -pub use crate::message::{SubscriptionInfo, SubscriptionKeys, WebPushMessage, WebPushMessageBuilder, WebPushPayload}; - pub use crate::http_ece::ContentEncoding; +pub use crate::message::{SubscriptionInfo, SubscriptionKeys, WebPushMessage, WebPushMessageBuilder, WebPushPayload}; pub use crate::vapid::builder::PartialVapidSignatureBuilder; pub use crate::vapid::{VapidSignature, VapidSignatureBuilder}; -pub use crate::clients::request_builder; +mod clients; +mod error; +mod http_ece; +mod message; +mod vapid; diff --git a/src/message.rs b/src/message.rs index 9b9fb042..23240d35 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,10 +1,11 @@ +use http::uri::Uri; + use crate::error::WebPushError; use crate::http_ece::{ContentEncoding, HttpEce}; use crate::vapid::VapidSignature; -use http::uri::Uri; /// Encryption keys from the client. -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq, Ord, PartialOrd, Default, Hash)] pub struct SubscriptionKeys { /// The public key. Base64 encoded. pub p256dh: String, @@ -16,7 +17,7 @@ pub struct SubscriptionKeys { /// subscription info JSON data (AKA pushSubscription object). /// /// Client pushSubscription objects can be directly deserialized into this struct using serde. -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq, Ord, PartialOrd, Default, Hash)] pub struct SubscriptionInfo { /// The endpoint URI for sending the notification. pub endpoint: String, diff --git a/src/vapid/builder.rs b/src/vapid/builder.rs index 8b4c9b66..85c9d0ac 100644 --- a/src/vapid/builder.rs +++ b/src/vapid/builder.rs @@ -1,12 +1,14 @@ +use std::collections::BTreeMap; +use std::io::Read; + +use http::uri::Uri; +use jwt_simple::prelude::*; +use serde_json::Value; + use crate::error::WebPushError; use crate::message::SubscriptionInfo; use crate::vapid::signer::Claims; use crate::vapid::{VapidKey, VapidSignature, VapidSigner}; -use http::uri::Uri; -use jwt_simple::prelude::*; -use serde_json::Value; -use std::collections::BTreeMap; -use std::io::Read; /// A VAPID signature builder for generating an optional signature to the /// request. This encryption is required for payloads in all current and future browsers. @@ -241,10 +243,12 @@ impl<'a> PartialVapidSignatureBuilder { #[cfg(test)] mod tests { + use std::fs::File; + + use ::lazy_static::lazy_static; + use crate::message::SubscriptionInfo; use crate::vapid::VapidSignatureBuilder; - use ::lazy_static::lazy_static; - use std::fs::File; lazy_static! { static ref PRIVATE_PEM: File = File::open("resources/vapid_test_key.pem").unwrap(); diff --git a/src/vapid/key.rs b/src/vapid/key.rs index 54c21b6f..0f458541 100644 --- a/src/vapid/key.rs +++ b/src/vapid/key.rs @@ -22,9 +22,10 @@ impl VapidKey { #[cfg(test)] mod tests { - use crate::vapid::key::VapidKey; use std::fs::File; + use crate::vapid::key::VapidKey; + #[test] /// Tests that VapidKey derives the correct public key. fn test_public_key_derivation() { diff --git a/src/vapid/mod.rs b/src/vapid/mod.rs index b451404a..b8366d59 100644 --- a/src/vapid/mod.rs +++ b/src/vapid/mod.rs @@ -1,11 +1,11 @@ //! Contains tooling for signing with VAPID. -pub mod builder; -mod key; -mod signer; - pub use self::builder::VapidSignatureBuilder; use self::key::VapidKey; pub use self::signer::Claims; pub use self::signer::VapidSignature; use self::signer::VapidSigner; + +pub mod builder; +mod key; +mod signer; diff --git a/src/vapid/signer.rs b/src/vapid/signer.rs index 8d8a07c4..ea2171a9 100644 --- a/src/vapid/signer.rs +++ b/src/vapid/signer.rs @@ -1,12 +1,14 @@ -use crate::{error::WebPushError, vapid::VapidKey}; +use std::collections::BTreeMap; + use http::uri::Uri; use jwt_simple::prelude::*; use serde_json::Value; -use std::collections::BTreeMap; + +use crate::{error::WebPushError, vapid::VapidKey}; /// A struct representing a VAPID signature. Should be generated using the /// [VapidSignatureBuilder](struct.VapidSignatureBuilder.html). -#[derive(Debug)] +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct VapidSignature { /// The signed JWT, base64 encoded pub auth_t: String,