Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ secure = ["private", "signed", "key-expansion"]
private = ["aes-gcm", "base64", "rand", "subtle"]
signed = ["hmac", "sha2", "base64", "rand", "subtle"]
key-expansion = ["sha2", "hkdf"]
chrono = ["dep:chrono"]

[dependencies]
time = { version = "0.3", default-features = false, features = ["std", "parsing", "formatting", "macros"] }
chrono = { version = "0.4.39", optional = true }
percent-encoding = { version = "2.0", optional = true }

# dependencies for secure (private/signed) functionality
Expand Down
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<'c> CookieBuilder<'c> {
/// assert_eq!(c.inner().max_age(), Some(Duration::seconds(30 * 60)));
/// ```
#[inline]
pub fn max_age(mut self, value: time::Duration) -> Self {
pub fn max_age(mut self, value: crate::Duration) -> Self {
self.cookie.set_max_age(value);
self
}
Expand Down
18 changes: 9 additions & 9 deletions src/expiration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use time::OffsetDateTime;
use crate::UtcDateTime;

/// A cookie's expiration: either a date-time or session.
///
Expand All @@ -25,7 +25,7 @@ use time::OffsetDateTime;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Expiration {
/// Expiration for a "permanent" cookie at a specific date-time.
DateTime(OffsetDateTime),
DateTime(UtcDateTime),
/// Expiration for a "session" cookie. Browsers define the notion of a
/// "session" and will automatically expire session cookies when they deem
/// the "session" to be over. This is typically, but need not be, when the
Expand All @@ -51,7 +51,7 @@ impl Expiration {
pub fn is_datetime(&self) -> bool {
match self {
Expiration::DateTime(_) => true,
Expiration::Session => false
Expiration::Session => false,
}
}

Expand All @@ -72,7 +72,7 @@ impl Expiration {
pub fn is_session(&self) -> bool {
match self {
Expiration::DateTime(_) => false,
Expiration::Session => true
Expiration::Session => true,
}
}

Expand All @@ -91,10 +91,10 @@ impl Expiration {
/// let expires = Expiration::from(now);
/// assert_eq!(expires.datetime(), Some(now));
/// ```
pub fn datetime(self) -> Option<OffsetDateTime> {
pub fn datetime(self) -> Option<UtcDateTime> {
match self {
Expiration::Session => None,
Expiration::DateTime(v) => Some(v)
Expiration::DateTime(v) => Some(v),
}
}

Expand All @@ -117,7 +117,7 @@ impl Expiration {
/// assert_eq!(expires.map(|t| t + one_week).datetime(), None);
/// ```
pub fn map<F>(self, f: F) -> Self
where F: FnOnce(OffsetDateTime) -> OffsetDateTime
where F: FnOnce(UtcDateTime) -> UtcDateTime,
{
match self {
Expiration::Session => Expiration::Session,
Expand All @@ -126,11 +126,11 @@ impl Expiration {
}
}

impl<T: Into<Option<OffsetDateTime>>> From<T> for Expiration {
impl<T: Into<Option<UtcDateTime>>> From<T> for Expiration {
fn from(option: T) -> Self {
match option.into() {
Some(value) => Expiration::DateTime(value),
None => Expiration::Session
None => Expiration::Session,
}
}
}
7 changes: 4 additions & 3 deletions src/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ impl<'a> Iterator for Delta<'a> {
}
}

use std::collections::hash_set::Difference;
use std::collections::hash_map::RandomState;
use std::collections::hash_set::Difference;
use std::iter::Chain;

/// Iterator over all of the cookies in a jar.
Expand All @@ -616,7 +616,7 @@ impl<'a> Iterator for Iter<'a> {
fn next(&mut self) -> Option<&'a Cookie<'static>> {
for cookie in self.delta_cookies.by_ref() {
if !cookie.removed {
return Some(&*cookie);
return Some(cookie);
}
}

Expand Down Expand Up @@ -693,7 +693,8 @@ mod test {
#[test]
fn delta() {
use std::collections::HashMap;
use time::Duration;
#[cfg(feature = "chrono")] use chrono::Duration;
#[cfg(not(feature = "chrono"))] use time::Duration;

let mut c = CookieJar::new();

Expand Down
Loading