From 5898fc923f0a4ceb1b69e05af4218ae1a73c4777 Mon Sep 17 00:00:00 2001 From: Markus Kohlhase Date: Tue, 19 Jul 2022 01:25:01 +0200 Subject: [PATCH 1/3] Remove unmentained chrono dependency --- CHANGES.md | 25 +++++++++++++++++++++++++ Cargo.toml | 1 - src/lib.rs | 1 - src/opencage.rs | 18 ++++++++++++++---- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 769c5f6..6058b77 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,30 @@ # Changes +## unreleased + +- Remove `chrono` dependency + +### Breaking Changes + +Due to previous security issues caused by the `chrono` crate +the `NaiveDateTime` was replaces by a `UnixTime` type: + +```diff +- use chrono::NaiveDateTime; +- use geocoding::opencage::Timestamp; ++ use geocoding::opencage::{Timestamp, UnixTime}; + + let created_http = "Mon, 16 May 2022 14:52:47 GMT".to_string(); + + let ts_in_seconds = 1_652_712_767_i64; +- let created_unix = NaiveDateTime::from_timestamp(ts_in_seconds, 0); ++ let created_unix = UnixTime::from_seconds(ts_in_seconds); + + let timestamp = Timestamp { created_http, created_unix }; + ++ assert_eq!(ts_in_seconds, created_unix.as_seconds()); +``` + ## 0.4.0 - Update CI to use same Rust versions as geo - Switch GeoAdmin API to WGS84 diff --git a/Cargo.toml b/Cargo.toml index 6f1a7b9..05ddd0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" reqwest = { version = "0.11", default-features = false, features = ["default-tls", "blocking", "json"] } hyper = "0.14.11" -chrono = { version = "0.4", features = ["serde"] } [features] default = ["reqwest/default"] diff --git a/src/lib.rs b/src/lib.rs index 1028844..0ee2fe0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,6 @@ static UA_STRING: &str = "Rust-Geocoding"; -use chrono; #[allow(deprecated)] pub use geo_types::{Coordinate, Point}; use num_traits::Float; diff --git a/src/opencage.rs b/src/opencage.rs index 917027b..561be22 100644 --- a/src/opencage.rs +++ b/src/opencage.rs @@ -24,8 +24,6 @@ //! // "Carrer de Calatrava, 68, 08017 Barcelone, Espagne" //! println!("{:?}", res.unwrap()); //! ``` -use crate::chrono::naive::serde::ts_seconds::deserialize as from_ts; -use crate::chrono::NaiveDateTime; use crate::DeserializeOwned; use crate::GeocodingError; use crate::InputBounds; @@ -608,8 +606,20 @@ pub struct Status { #[derive(Debug, Serialize, Deserialize)] pub struct Timestamp { pub created_http: String, - #[serde(deserialize_with = "from_ts")] - pub created_unix: NaiveDateTime, + pub created_unix: UnixTime, +} + +/// Primitive unix timestamp +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +pub struct UnixTime(i64); + +impl UnixTime { + pub const fn as_seconds(self) -> i64 { + self.0 + } + pub const fn from_seconds(seconds: i64) -> Self { + Self(seconds) + } } /// Bounding-box metadata From 73ac911b568077517ca39e7c54f24676d78b2f2d Mon Sep 17 00:00:00 2001 From: Markus Kohlhase Date: Tue, 18 Apr 2023 11:49:31 +0200 Subject: [PATCH 2/3] Fix clippy lints --- src/lib.rs | 7 +++---- src/opencage.rs | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0ee2fe0..7e63d9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,8 +27,7 @@ static UA_STRING: &str = "Rust-Geocoding"; -#[allow(deprecated)] -pub use geo_types::{Coordinate, Point}; +pub use geo_types::{Coord, Point}; use num_traits::Float; use reqwest::blocking::Client; use reqwest::header::ToStrError; @@ -102,14 +101,14 @@ where /// Examples /// /// ``` -/// use geocoding::{Coordinate, Forward, Opencage, Point}; +/// use geocoding::{Coord, Forward, Opencage, Point}; /// /// let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string()); /// let address = "Schwabing, München"; /// let res: Vec> = oc.forward(address).unwrap(); /// assert_eq!( /// res, -/// vec![Point(Coordinate { x: 11.5884858, y: 48.1700887 })] +/// vec![Point(Coord { x: 11.5884858, y: 48.1700887 })] /// ); /// ``` pub trait Forward diff --git a/src/opencage.rs b/src/opencage.rs index 561be22..d0fa27e 100644 --- a/src/opencage.rs +++ b/src/opencage.rs @@ -635,8 +635,7 @@ where #[cfg(test)] mod test { use super::*; - #[allow(deprecated)] - use crate::Coordinate; + use crate::Coord; #[test] fn reverse_test() { @@ -668,7 +667,7 @@ mod test { let res = oc.forward(&address); assert_eq!( res.unwrap(), - vec![Point(Coordinate { + vec![Point(Coord { x: 11.5884858, y: 48.1700887 })] From deef29c91a0c3d25e3671e42597c009fe32bc654 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 11 Jul 2023 15:48:24 -0700 Subject: [PATCH 3/3] geo-types::Coord didn't come along until 0.7.8 --- CHANGES.md | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 6058b77..250ef11 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## unreleased - Remove `chrono` dependency +- update geo-types to 0.7.8 ### Breaking Changes diff --git a/Cargo.toml b/Cargo.toml index 05ddd0d..d5d026f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" [dependencies] thiserror = "1.0" -geo-types = "0.7" +geo-types = "0.7.8" num-traits = "0.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0"