From 45bfd1e41c1789cde34e199d4e5d745bfb8cb5ad Mon Sep 17 00:00:00 2001 From: ondra Date: Sat, 12 Apr 2025 21:01:10 +0200 Subject: [PATCH] Update to newer libs --- CHANGELOG.md | 3 +++ Cargo.toml | 6 +++--- src/lib.rs | 13 ++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93994b0..3fae1a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# [0.4.0] +- Update to rocket `0.5.1` and rand `0.9` + # [0.3.0] - Update dependencies diff --git a/Cargo.toml b/Cargo.toml index e984ec8..e631c5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rocket_session" -version = "0.3.0" +version = "0.4.0" authors = ["Ondřej Hruška "] edition = "2021" license = "MIT" @@ -16,6 +16,6 @@ categories = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rand = "0.8" -rocket = "0.5.0-rc.2" +rand = "0.9" +rocket = "0.5" parking_lot = "0.12" diff --git a/src/lib.rs b/src/lib.rs index 60c1f3e..4f2ae0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ use std::ops::Add; use std::time::{Duration, Instant}; use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; -use rand::{rngs::OsRng, Rng}; +use rand::{rngs::OsRng, Rng, TryRngCore}; use rocket::{ fairing::{self, Fairing, Info}, http::{Cookie, Status}, @@ -126,7 +126,9 @@ where { type Error = (); - async fn from_request(request: &'r Request<'_>) -> Outcome { + async fn from_request( + request: &'r Request<'_>, + ) -> Outcome { let store = request.guard::<&State>>().await.unwrap(); Outcome::Success(Session { id: request.local_cache(|| { @@ -177,7 +179,8 @@ where // Find a new unique ID - we are still safely inside the write guard let new_id = SessionID(loop { let token: String = OsRng - .sample_iter(&rand::distributions::Alphanumeric) + .unwrap_err() + .sample_iter(&rand::distr::Alphanumeric) .take(store.config.cookie_len) .map(char::from) .collect(); @@ -321,9 +324,9 @@ where if !session.0.is_empty() { response.adjoin_header( - Cookie::build(self.config.cookie_name.clone(), session.to_string()) + Cookie::build((self.config.cookie_name.clone(), session.to_string())) .path("/") - .finish(), + .build(), ); } }