Skip to content
Merged
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
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cas-lib"
version = "0.2.73"
version = "0.2.74"
edition = "2021"
description = "A function wrapper layer for RustCrypto and Dalek-Cryptography. Intended to be used in FFI situations with a global heap deallactor at the top level project."
license = "Apache-2.0"
Expand Down Expand Up @@ -34,12 +34,17 @@ hkdf = "0.12.4"
chacha20poly1305 = "0.10.1"
slh-dsa = "0.0.3"
ml-kem = "0.2.1"
reqwest = { version = "0.12.24", default-features = false, features = ["json", "cookies", "rustls-tls"] }
serde = { version = "1.0.228", features = ["derive"] }
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
url = "2.5.7"
once_cell = "1.21.3"

[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.12.24", default-features = false, features = ["cookies", "json"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
reqwest = { version = "0.12.24", default-features = false, features = ["cookies", "rustls-tls", "json"] }

[profile.dev.package.num-bigint-dig]
opt-level = 3

Expand Down
12 changes: 11 additions & 1 deletion src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use reqwest::{Client, cookie::Jar};
use std::sync::{Arc, Mutex};
use url::Url;

#[cfg(not(target_arch = "wasm32"))]
use reqwest::{Client, cookie::Jar};

pub mod types;
use crate::http::types::{BenchmarkRequest};

Expand All @@ -10,8 +12,11 @@ static BASE_URL: Mutex<String> = Mutex::new(String::new());

static TOKEN: Mutex<String> = Mutex::new(String::new());
static REFRESH_TOKEN: Mutex<String> = Mutex::new(String::new());

#[cfg(not(target_arch = "wasm32"))]
static BENCHMARK_SENDER_CLIENT: Mutex<Option<Client>> = Mutex::new(None);

#[cfg(not(target_arch = "wasm32"))]
fn create_benchmark_sender_client(token: String, refresh_token: String) -> Client {
let cookie_store = Arc::new(Jar::default());
let base_url = Url::parse(BASE_URL.lock().unwrap().as_str()).unwrap();
Expand All @@ -23,6 +28,7 @@ fn create_benchmark_sender_client(token: String, refresh_token: String) -> Clien
.unwrap()
}

#[cfg(not(target_arch = "wasm32"))]
fn determine_api_route() -> String {
let base_url = BASE_URL.lock().unwrap();
if base_url.contains("cryptographicapiservices.com") {
Expand All @@ -32,17 +38,20 @@ fn determine_api_route() -> String {
}
}

#[cfg(not(target_arch = "wasm32"))]
pub async fn set_api_key_in_cache(api_key: String) {
let mut key = API_KEY.lock().unwrap();
*key = api_key.clone();
set_tokens_in_cache(api_key).await;
}

#[cfg(not(target_arch = "wasm32"))]
pub fn set_base_url_in_cache(base_url: String) {
let mut url = BASE_URL.lock().unwrap();
*url = base_url
}

#[cfg(not(target_arch = "wasm32"))]
pub async fn set_tokens_in_cache(api_key: String) {
let client = Client::new();
let base_url = BASE_URL.lock().unwrap().clone();
Expand Down Expand Up @@ -79,6 +88,7 @@ pub async fn set_tokens_in_cache(api_key: String) {
}
}

#[cfg(not(target_arch = "wasm32"))]
pub async fn send_benchmark(time_in_milliseconds: i64, class_name: String, method_name: String) {
let payload = BenchmarkRequest {
class_name,
Expand Down
4 changes: 3 additions & 1 deletion src/http/types/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

#[cfg(not(target_arch = "wasm32"))]
use once_cell::sync::Lazy;
#[cfg(not(target_arch = "wasm32"))]
use tokio::runtime::Runtime;

#[cfg(not(target_arch = "wasm32"))]
pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
Expand Down