From 3fc1be58aa7d71c8276e3111180c0f108b969213 Mon Sep 17 00:00:00 2001 From: Jonas Schneider-Bensch Date: Wed, 15 Jan 2025 10:53:24 +0100 Subject: [PATCH] Simplify use of `alloc` --- src/lib.rs | 3 +++ src/test_utils.rs | 6 +----- src/tls13crypto.rs | 8 ++------ src/tls13utils.rs | 6 +----- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 84e2a7a..94ee2da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,9 @@ extern crate std; #[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(not(feature = "std"))] +use alloc as std; + mod tls13formats; mod tls13handshake; mod tls13record; diff --git a/src/test_utils.rs b/src/test_utils.rs index 176fcaa..c151c75 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,9 +1,5 @@ +use crate::std::vec::Vec; use rand::{CryptoRng, RngCore}; -#[cfg(feature = "std")] -use std::vec::Vec; - -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; pub struct TestRng { bytes: Vec, diff --git a/src/tls13crypto.rs b/src/tls13crypto.rs index 6016caa..8cc2717 100644 --- a/src/tls13crypto.rs +++ b/src/tls13crypto.rs @@ -7,13 +7,9 @@ use libcrux::{ use libcrux_kem::{Ct, PrivateKey, PublicKey}; use rand::{CryptoRng, RngCore}; -#[cfg(feature = "std")] -use std::{format, vec::Vec}; +use crate::std::{format, vec::Vec}; -#[cfg(not(feature = "std"))] -use alloc::{format, vec::Vec}; - -use std::fmt::Display; +use crate::std::fmt::Display; use crate::tls13utils::{ check_mem, eq, length_u16_encoded, tlserr, Bytes, Error, TLSError, CRYPTO_ERROR, diff --git a/src/tls13utils.rs b/src/tls13utils.rs index 059b495..a76598c 100644 --- a/src/tls13utils.rs +++ b/src/tls13utils.rs @@ -3,11 +3,7 @@ use core::ops::Range; #[cfg(feature = "hax-fstar")] use hax_lib_macros::{attributes, requires}; -#[cfg(feature = "std")] -use std::{format, string::String, vec, vec::Vec}; - -#[cfg(not(feature = "std"))] -use alloc::{format, string::String, vec, vec::Vec}; +use crate::std::{format, string::String, vec, vec::Vec}; // FIXME: NOT HACSPEC | ONLY FOR DEBUGGING pub(crate) fn parse_failed() -> TLSError {