diff --git a/Cargo.lock b/Cargo.lock index ccab3c2e..8914b795 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2113,6 +2113,7 @@ name = "ironrdp-connector" version = "0.1.0" dependencies = [ "arbitrary", + "ironrdp-core", "ironrdp-error", "ironrdp-pdu", "ironrdp-svc", @@ -2147,6 +2148,7 @@ dependencies = [ name = "ironrdp-dvc" version = "0.1.0" dependencies = [ + "ironrdp-core", "ironrdp-pdu", "ironrdp-svc", "slab", @@ -2217,6 +2219,7 @@ dependencies = [ "byteorder", "der-parser", "expect-test", + "ironrdp-core", "ironrdp-error", "lazy_static", "md-5", @@ -2330,6 +2333,7 @@ name = "ironrdp-svc" version = "0.1.0" dependencies = [ "bitflags 2.6.0", + "ironrdp-core", "ironrdp-pdu", ] diff --git a/crates/ironrdp-connector/Cargo.toml b/crates/ironrdp-connector/Cargo.toml index 0ba5cfdb..4bd9854c 100644 --- a/crates/ironrdp-connector/Cargo.toml +++ b/crates/ironrdp-connector/Cargo.toml @@ -21,9 +21,12 @@ arbitrary = ["dep:arbitrary"] [dependencies] arbitrary = { version = "1", features = ["derive"], optional = true } ironrdp-svc.workspace = true +ironrdp-core.workspace = true ironrdp-error.workspace = true ironrdp-pdu = { workspace = true, features = ["std"] } -rand_core = { version = "0.6", features = ["std"] } # TODO: dependency injection? +rand_core = { version = "0.6", features = [ + "std", +] } # TODO: dependency injection? sspi.workspace = true tracing.workspace = true url = "2.5" @@ -39,4 +42,3 @@ winapi = { version = "0.3", features = ["std"] } [lints] workspace = true - diff --git a/crates/ironrdp-connector/src/lib.rs b/crates/ironrdp-connector/src/lib.rs index 906c2550..8a77e876 100644 --- a/crates/ironrdp-connector/src/lib.rs +++ b/crates/ironrdp-connector/src/lib.rs @@ -168,7 +168,7 @@ pub struct Config { pub performance_flags: PerformanceFlags, } -ironrdp_pdu::assert_impl!(Config: Send, Sync); +ironrdp_core::assert_impl!(Config: Send, Sync); pub trait State: Send + fmt::Debug + 'static { fn name(&self) -> &'static str; @@ -176,7 +176,7 @@ pub trait State: Send + fmt::Debug + 'static { fn as_any(&self) -> &dyn Any; } -ironrdp_pdu::assert_obj_safe!(State); +ironrdp_core::assert_obj_safe!(State); pub fn state_downcast(state: &dyn State) -> Option<&T> { state.as_any().downcast_ref() @@ -241,7 +241,7 @@ pub trait Sequence: Send { } } -ironrdp_pdu::assert_obj_safe!(Sequence); +ironrdp_core::assert_obj_safe!(Sequence); pub type ConnectorResult = Result; diff --git a/crates/ironrdp-core/src/lib.rs b/crates/ironrdp-core/src/lib.rs index bf6031f7..6a95a799 100644 --- a/crates/ironrdp-core/src/lib.rs +++ b/crates/ironrdp-core/src/lib.rs @@ -7,6 +7,9 @@ #[cfg(feature = "alloc")] extern crate alloc; +#[macro_use] +mod macros; + // Trait that can only be implemented within the current module pub(crate) mod private { #[doc(hidden)] diff --git a/crates/ironrdp-core/src/macros.rs b/crates/ironrdp-core/src/macros.rs new file mode 100644 index 00000000..b7367994 --- /dev/null +++ b/crates/ironrdp-core/src/macros.rs @@ -0,0 +1,24 @@ +/// Asserts that the traits support dynamic dispatch. +/// +/// From +#[macro_export] +macro_rules! assert_obj_safe { + ($($xs:path),+ $(,)?) => { + $(const _: Option<&dyn $xs> = None;)+ + }; +} + +/// Asserts that the type implements _all_ of the given traits. +/// +/// From +#[macro_export] +macro_rules! assert_impl { + ($type:ty: $($trait:path),+ $(,)?) => { + const _: fn() = || { + // Only callable when `$type` implements all traits in `$($trait)+`. + fn assert_impl_all() {} + assert_impl_all::<$type>(); + }; + }; +} + diff --git a/crates/ironrdp-dvc/Cargo.toml b/crates/ironrdp-dvc/Cargo.toml index 4286b052..7601e92f 100644 --- a/crates/ironrdp-dvc/Cargo.toml +++ b/crates/ironrdp-dvc/Cargo.toml @@ -20,6 +20,7 @@ default = [] std = [] [dependencies] +ironrdp-core.workspace = true ironrdp-svc.workspace = true ironrdp-pdu = { workspace = true, features = ["alloc"] } tracing.workspace = true @@ -27,4 +28,3 @@ slab = "0.4" [lints] workspace = true - diff --git a/crates/ironrdp-dvc/src/lib.rs b/crates/ironrdp-dvc/src/lib.rs index b7aa5bcc..ec18ba44 100644 --- a/crates/ironrdp-dvc/src/lib.rs +++ b/crates/ironrdp-dvc/src/lib.rs @@ -16,7 +16,8 @@ use alloc::vec::Vec; // Re-export ironrdp_pdu crate for convenience #[rustfmt::skip] // do not re-order this pub use pub use ironrdp_pdu; -use ironrdp_pdu::{assert_obj_safe, cast_length, encode_vec, other_err, PduEncode, PduResult}; +use ironrdp_core::assert_obj_safe; +use ironrdp_pdu::{cast_length, encode_vec, other_err, PduEncode, PduResult}; use ironrdp_svc::{self, AsAny, SvcMessage}; mod complete_data; diff --git a/crates/ironrdp-pdu/Cargo.toml b/crates/ironrdp-pdu/Cargo.toml index debd3c22..ca044c70 100644 --- a/crates/ironrdp-pdu/Cargo.toml +++ b/crates/ironrdp-pdu/Cargo.toml @@ -18,23 +18,24 @@ doctest = false [features] default = [] std = ["alloc", "ironrdp-error/std"] -alloc = ["ironrdp-error/alloc"] +alloc = ["ironrdp-core/alloc", "ironrdp-error/alloc"] [dependencies] bitflags.workspace = true +ironrdp-core.workspace = true ironrdp-error.workspace = true tap = "1" # TODO: get rid of these dependencies (related code should probably go into another crate) bit_field = "0.10" -byteorder.workspace = true # TODO: remove +byteorder.workspace = true # TODO: remove der-parser = "9.0" thiserror.workspace = true md5 = { package = "md-5", version = "0.10" } num-bigint = "0.4" -num-derive.workspace = true # TODO: remove +num-derive.workspace = true # TODO: remove num-integer = "0.1" -num-traits.workspace = true # TODO: remove +num-traits.workspace = true # TODO: remove sha1 = "0.10" x509-cert = { version = "0.2", default-features = false, features = ["std"] } pkcs1 = "0.7" @@ -45,4 +46,3 @@ lazy_static.workspace = true # TODO: remove in favor of https://doc.rust-lang.or [lints] workspace = true - diff --git a/crates/ironrdp-pdu/src/lib.rs b/crates/ironrdp-pdu/src/lib.rs index 0ccafc6a..492b730b 100644 --- a/crates/ironrdp-pdu/src/lib.rs +++ b/crates/ironrdp-pdu/src/lib.rs @@ -155,7 +155,7 @@ pub trait PduEncode { fn size(&self) -> usize; } -assert_obj_safe!(PduEncode); +ironrdp_core::assert_obj_safe!(PduEncode); /// Encodes the given PDU in-place into the provided buffer and returns the number of bytes written. pub fn encode(pdu: &T, dst: &mut [u8]) -> PduResult diff --git a/crates/ironrdp-pdu/src/macros.rs b/crates/ironrdp-pdu/src/macros.rs index 5f622c12..830907c8 100644 --- a/crates/ironrdp-pdu/src/macros.rs +++ b/crates/ironrdp-pdu/src/macros.rs @@ -205,30 +205,6 @@ macro_rules! cast_int { }}; } -/// Asserts that the traits support dynamic dispatch. -/// -/// From -#[macro_export] -macro_rules! assert_obj_safe { - ($($xs:path),+ $(,)?) => { - $(const _: Option<&dyn $xs> = None;)+ - }; -} - -/// Asserts that the type implements _all_ of the given traits. -/// -/// From -#[macro_export] -macro_rules! assert_impl { - ($type:ty: $($trait:path),+ $(,)?) => { - const _: fn() = || { - // Only callable when `$type` implements all traits in `$($trait)+`. - fn assert_impl_all() {} - assert_impl_all::<$type>(); - }; - }; -} - /// Asserts that constant expressions evaluate to `true`. /// /// From diff --git a/crates/ironrdp-svc/Cargo.toml b/crates/ironrdp-svc/Cargo.toml index 7e863073..02e2a492 100644 --- a/crates/ironrdp-svc/Cargo.toml +++ b/crates/ironrdp-svc/Cargo.toml @@ -22,6 +22,7 @@ std = [] [dependencies] ironrdp-pdu = { workspace = true, features = ["alloc"] } bitflags.workspace = true +ironrdp-core.workspace = true [lints] workspace = true diff --git a/crates/ironrdp-svc/src/lib.rs b/crates/ironrdp-svc/src/lib.rs index 94121d8b..6771370c 100644 --- a/crates/ironrdp-svc/src/lib.rs +++ b/crates/ironrdp-svc/src/lib.rs @@ -15,9 +15,10 @@ use std::borrow::Cow; use std::marker::PhantomData; use bitflags::bitflags; +use ironrdp_core::assert_obj_safe; use ironrdp_pdu::gcc::{ChannelName, ChannelOptions}; use ironrdp_pdu::write_buf::WriteBuf; -use ironrdp_pdu::{assert_obj_safe, mcs, PduResult}; +use ironrdp_pdu::{mcs, PduResult}; use pdu::cursor::{ReadCursor, WriteCursor}; use pdu::gcc::ChannelDef; use pdu::rdp::vc::ChannelControlFlags;