Skip to content

Commit

Permalink
use parking_lot mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Sep 3, 2023
1 parent 1a6db4c commit cd0b228
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ log = "0.4"
once_cell = "1"
p256 = { version = "0.13", features = ["pkcs8", "ecdsa-core"] }
p384 = { version = "0.13", features = ["pkcs8", "ecdsa-core"] }
parking_lot = "0.12"
pem = { package = "pem-rfc7468", version = "0.7" }
pkcs8 = "0.10"
rand = "0.8"
Expand Down
14 changes: 8 additions & 6 deletions src/trans.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{
collections::VecDeque,
sync::{Arc, Mutex},
};
use std::{collections::VecDeque, sync::Arc};

use base64::prelude::*;
use parking_lot::Mutex;
use serde::Serialize;

use crate::{
Expand Down Expand Up @@ -128,10 +126,13 @@ impl NoncePool {
fn extract_nonce(&self, res: &reqwest::Response) {
if let Some(nonce) = res.headers().get("replay-nonce") {
log::trace!("Extracting new nonce");
let mut pool = self.pool.lock().unwrap();

let mut pool = self.pool.lock();

// TODO: ignore invalid replay-nonce values
// see https://datatracker.ietf.org/doc/html/rfc8555#section-6.5.1
pool.push_back(nonce.to_str().unwrap().to_owned());

if pool.len() > 10 {
pool.pop_front();
}
Expand All @@ -140,7 +141,8 @@ impl NoncePool {

async fn get_nonce(&self) -> eyre::Result<String> {
{
let mut pool = self.pool.lock().unwrap();
let mut pool = self.pool.lock();

if let Some(nonce) = pool.pop_front() {
log::trace!("Use previous nonce");
return Ok(nonce);
Expand Down

0 comments on commit cd0b228

Please sign in to comment.