diff --git a/crates/ironrdp-pdu/src/gcc/cluster_data.rs b/crates/ironrdp-pdu/src/gcc/cluster_data.rs index 58e2f1880..18c8773db 100644 --- a/crates/ironrdp-pdu/src/gcc/cluster_data.rs +++ b/crates/ironrdp-pdu/src/gcc/cluster_data.rs @@ -1,6 +1,3 @@ -use core::fmt; -use std::io; - use bitflags::bitflags; use ironrdp_core::{ Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, ensure_fixed_part_size, invalid_field_err, @@ -96,33 +93,3 @@ impl RedirectionVersion { self as u32 } } - -#[derive(Debug)] -pub enum ClusterDataError { - IOError(io::Error), - InvalidRedirectionFlags, -} - -impl fmt::Display for ClusterDataError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::InvalidRedirectionFlags => f.write_str("invalid redirection flags field"), - } - } -} - -impl core::error::Error for ClusterDataError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::InvalidRedirectionFlags => None, - } - } -} - -impl From for ClusterDataError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} diff --git a/crates/ironrdp-pdu/src/gcc/core_data/mod.rs b/crates/ironrdp-pdu/src/gcc/core_data/mod.rs index 693eb29c0..3afd61cbe 100644 --- a/crates/ironrdp-pdu/src/gcc/core_data/mod.rs +++ b/crates/ironrdp-pdu/src/gcc/core_data/mod.rs @@ -1,11 +1,6 @@ pub(crate) mod client; pub(crate) mod server; -use core::fmt; -use std::io; - -use crate::PduError; - const VERSION_SIZE: usize = 4; #[repr(transparent)] @@ -41,69 +36,3 @@ impl RdpVersion { pub const V10_11: Self = Self(0x0008_0010); pub const V10_12: Self = Self(0x0008_0011); } - -#[derive(Debug)] -pub enum CoreDataError { - IOError(io::Error), - InvalidVersion, - InvalidColorDepth, - InvalidPostBetaColorDepth, - InvalidHighColorDepth, - InvalidSupportedColorDepths, - InvalidSecureAccessSequence, - InvalidKeyboardType, - InvalidEarlyCapabilityFlags, - InvalidConnectionType, - InvalidServerSecurityProtocol, - Pdu(PduError), -} - -impl fmt::Display for CoreDataError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::InvalidVersion => f.write_str("invalid version field"), - Self::InvalidColorDepth => f.write_str("invalid color depth field"), - Self::InvalidPostBetaColorDepth => f.write_str("invalid post beta color depth field"), - Self::InvalidHighColorDepth => f.write_str("invalid high color depth field"), - Self::InvalidSupportedColorDepths => f.write_str("invalid supported color depths field"), - Self::InvalidSecureAccessSequence => f.write_str("invalid secure access sequence field"), - Self::InvalidKeyboardType => f.write_str("invalid keyboard type field"), - Self::InvalidEarlyCapabilityFlags => f.write_str("invalid early capability flags field"), - Self::InvalidConnectionType => f.write_str("invalid connection type field"), - Self::InvalidServerSecurityProtocol => f.write_str("invalid server security protocol field"), - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } -} - -impl core::error::Error for CoreDataError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::InvalidVersion - | Self::InvalidColorDepth - | Self::InvalidPostBetaColorDepth - | Self::InvalidHighColorDepth - | Self::InvalidSupportedColorDepths - | Self::InvalidSecureAccessSequence - | Self::InvalidKeyboardType - | Self::InvalidEarlyCapabilityFlags - | Self::InvalidConnectionType - | Self::InvalidServerSecurityProtocol - | Self::Pdu(_) => None, - } - } -} - -impl From for CoreDataError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for CoreDataError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } -} diff --git a/crates/ironrdp-pdu/src/gcc/mod.rs b/crates/ironrdp-pdu/src/gcc/mod.rs index bde8c6e91..ecb84979e 100644 --- a/crates/ironrdp-pdu/src/gcc/mod.rs +++ b/crates/ironrdp-pdu/src/gcc/mod.rs @@ -1,6 +1,3 @@ -use core::fmt; -use std::io; - use ironrdp_core::{ Decode, DecodeErrorKind, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, cast_length, decode, ensure_fixed_part_size, ensure_size, invalid_field_err, @@ -8,8 +5,6 @@ use ironrdp_core::{ use num_derive::FromPrimitive; use num_traits::FromPrimitive; -use crate::PduError; - pub mod conference_create; mod cluster_data; @@ -21,26 +16,22 @@ mod multi_transport_channel_data; mod network_data; mod security_data; -pub use self::cluster_data::{ClientClusterData, ClusterDataError, RedirectionFlags, RedirectionVersion}; +pub use self::cluster_data::{ClientClusterData, RedirectionFlags, RedirectionVersion}; pub use self::conference_create::{ConferenceCreateRequest, ConferenceCreateResponse}; +pub use self::core_data::RdpVersion; pub use self::core_data::client::{ ClientColorDepth, ClientCoreData, ClientCoreOptionalData, ClientEarlyCapabilityFlags, ColorDepth, ConnectionType, HighColorDepth, IME_FILE_NAME_SIZE, KeyboardType, SecureAccessSequence, SupportedColorDepths, }; pub use self::core_data::server::{ServerCoreData, ServerCoreOptionalData, ServerEarlyCapabilityFlags}; -pub use self::core_data::{CoreDataError, RdpVersion}; pub use self::message_channel_data::{ClientMessageChannelData, ServerMessageChannelData}; pub use self::monitor_data::{ ClientMonitorData, MONITOR_COUNT_SIZE, MONITOR_FLAGS_SIZE, MONITOR_SIZE, Monitor, MonitorFlags, }; pub use self::monitor_extended_data::{ClientMonitorExtendedData, ExtendedMonitorInfo, MonitorOrientation}; pub use self::multi_transport_channel_data::{MultiTransportChannelData, MultiTransportFlags}; -pub use self::network_data::{ - ChannelDef, ChannelName, ChannelOptions, ClientNetworkData, NetworkDataError, ServerNetworkData, -}; -pub use self::security_data::{ - ClientSecurityData, EncryptionLevel, EncryptionMethod, SecurityDataError, ServerSecurityData, -}; +pub use self::network_data::{ChannelDef, ChannelName, ChannelOptions, ClientNetworkData, ServerNetworkData}; +pub use self::security_data::{ClientSecurityData, EncryptionLevel, EncryptionMethod, ServerSecurityData}; macro_rules! user_header_try { ($e:expr) => { @@ -355,94 +346,3 @@ impl UserDataHeader { Ok((block_type, src.read_slice(len))) } } - -#[derive(Debug)] -pub enum GccError { - IOError(io::Error), - CoreError(CoreDataError), - SecurityError(SecurityDataError), - NetworkError(NetworkDataError), - ClusterError(ClusterDataError), - InvalidGccType, - InvalidConferenceCreateRequest(String), - InvalidConferenceCreateResponse(String), - RequiredClientDataBlockIsAbsent(ClientGccType), - RequiredServerDataBlockIsAbsent(ServerGccType), - Pdu(PduError), -} - -impl fmt::Display for GccError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::CoreError(_) => f.write_str("core data block error"), - Self::SecurityError(_) => f.write_str("security data block error"), - Self::NetworkError(_) => f.write_str("network data block error"), - Self::ClusterError(_) => f.write_str("cluster data block error"), - Self::InvalidGccType => f.write_str("invalid GCC block type"), - Self::InvalidConferenceCreateRequest(s) => write!(f, "invalid conference create request: {s}"), - Self::InvalidConferenceCreateResponse(s) => write!(f, "invalid Conference create response: {s}"), - Self::RequiredClientDataBlockIsAbsent(ty) => { - write!(f, "a server did not send the required GCC data block: {ty:?}") - } - Self::RequiredServerDataBlockIsAbsent(ty) => { - write!(f, "a client did not send the required GCC data block: {ty:?}") - } - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } -} - -impl core::error::Error for GccError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::CoreError(e) => Some(e), - Self::SecurityError(e) => Some(e), - Self::NetworkError(e) => Some(e), - Self::ClusterError(e) => Some(e), - Self::InvalidGccType - | Self::InvalidConferenceCreateRequest(_) - | Self::InvalidConferenceCreateResponse(_) - | Self::RequiredClientDataBlockIsAbsent(_) - | Self::RequiredServerDataBlockIsAbsent(_) - | Self::Pdu(_) => None, - } - } -} - -impl From for GccError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for GccError { - fn from(e: CoreDataError) -> Self { - Self::CoreError(e) - } -} - -impl From for GccError { - fn from(e: SecurityDataError) -> Self { - Self::SecurityError(e) - } -} - -impl From for GccError { - fn from(e: NetworkDataError) -> Self { - Self::NetworkError(e) - } -} - -impl From for GccError { - fn from(e: ClusterDataError) -> Self { - Self::ClusterError(e) - } -} - -impl From for GccError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } -} diff --git a/crates/ironrdp-pdu/src/gcc/network_data.rs b/crates/ironrdp-pdu/src/gcc/network_data.rs index 17f47365d..a1b8956b7 100644 --- a/crates/ironrdp-pdu/src/gcc/network_data.rs +++ b/crates/ironrdp-pdu/src/gcc/network_data.rs @@ -1,6 +1,5 @@ -use core::fmt; use std::borrow::Cow; -use std::{io, str}; +use std::str; use bitflags::bitflags; use ironrdp_core::{ @@ -288,44 +287,3 @@ bitflags! { const REMOTE_CONTROL_PERSISTENT = 0x0010_0000; } } - -#[derive(Debug)] -pub enum NetworkDataError { - IOError(io::Error), - Utf8Error(str::Utf8Error), - InvalidChannelOptions, - InvalidChannelCount, -} - -impl fmt::Display for NetworkDataError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::Utf8Error(_) => f.write_str("UTF-8 error"), - Self::InvalidChannelOptions => f.write_str("invalid channel options field"), - Self::InvalidChannelCount => f.write_str("invalid channel count field"), - } - } -} - -impl core::error::Error for NetworkDataError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::Utf8Error(e) => Some(e), - Self::InvalidChannelOptions | Self::InvalidChannelCount => None, - } - } -} - -impl From for NetworkDataError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for NetworkDataError { - fn from(e: str::Utf8Error) -> Self { - Self::Utf8Error(e) - } -} diff --git a/crates/ironrdp-pdu/src/gcc/security_data.rs b/crates/ironrdp-pdu/src/gcc/security_data.rs index 8757dcc4a..9f726f393 100644 --- a/crates/ironrdp-pdu/src/gcc/security_data.rs +++ b/crates/ironrdp-pdu/src/gcc/security_data.rs @@ -1,6 +1,3 @@ -use core::fmt; -use std::io; - use bitflags::bitflags; use ironrdp_core::{ Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, cast_length, ensure_fixed_part_size, @@ -218,45 +215,3 @@ impl EncryptionLevel { self as u32 } } - -#[derive(Debug)] -pub enum SecurityDataError { - IOError(io::Error), - InvalidEncryptionMethod, - InvalidEncryptionLevel, - InvalidServerRandomLen(u32), - InvalidInput(String), - InvalidServerCertificateLen(u32), -} - -impl fmt::Display for SecurityDataError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::InvalidEncryptionMethod => f.write_str("invalid encryption methods field"), - Self::InvalidEncryptionLevel => f.write_str("invalid encryption level field"), - Self::InvalidServerRandomLen(n) => write!(f, "invalid server random length field: {n}"), - Self::InvalidInput(s) => write!(f, "invalid input: {s}"), - Self::InvalidServerCertificateLen(n) => write!(f, "invalid server certificate length: {n}"), - } - } -} - -impl core::error::Error for SecurityDataError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::InvalidEncryptionMethod - | Self::InvalidEncryptionLevel - | Self::InvalidServerRandomLen(_) - | Self::InvalidInput(_) - | Self::InvalidServerCertificateLen(_) => None, - } - } -} - -impl From for SecurityDataError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} diff --git a/crates/ironrdp-pdu/src/input/mod.rs b/crates/ironrdp-pdu/src/input/mod.rs index 2eacbce9f..df4cf70a4 100644 --- a/crates/ironrdp-pdu/src/input/mod.rs +++ b/crates/ironrdp-pdu/src/input/mod.rs @@ -1,6 +1,3 @@ -use core::fmt; -use std::io; - use ironrdp_core::{ Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, cast_length, ensure_fixed_part_size, ensure_size, invalid_field_err, read_padding, write_padding, @@ -181,48 +178,3 @@ impl From<&InputEvent> for InputEventType { } } } - -#[derive(Debug)] -pub enum InputEventError { - IOError(io::Error), - InvalidInputEventType(u16), - EncryptionNotSupported, - EventCodeUnsupported(u8), - KeyboardFlagsUnsupported(u8), - SynchronizeFlagsUnsupported(u8), - EmptyFastPathInput, -} - -impl fmt::Display for InputEventError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::InvalidInputEventType(n) => write!(f, "invalid Input Event type: {n}"), - Self::EncryptionNotSupported => f.write_str("encryption not supported"), - Self::EventCodeUnsupported(n) => write!(f, "event code not supported {n}"), - Self::KeyboardFlagsUnsupported(n) => write!(f, "keyboard flags not supported {n}"), - Self::SynchronizeFlagsUnsupported(n) => write!(f, "synchronize flags not supported {n}"), - Self::EmptyFastPathInput => f.write_str("Fast-Path Input Event PDU is empty"), - } - } -} - -impl core::error::Error for InputEventError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::InvalidInputEventType(_) - | Self::EncryptionNotSupported - | Self::EventCodeUnsupported(_) - | Self::KeyboardFlagsUnsupported(_) - | Self::SynchronizeFlagsUnsupported(_) - | Self::EmptyFastPathInput => None, - } - } -} - -impl From for InputEventError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} diff --git a/crates/ironrdp-pdu/src/mcs.rs b/crates/ironrdp-pdu/src/mcs.rs index c95ab1d7d..6ef289a3b 100644 --- a/crates/ironrdp-pdu/src/mcs.rs +++ b/crates/ironrdp-pdu/src/mcs.rs @@ -9,7 +9,7 @@ use crate::gcc::{ChannelDef, ClientGccBlocks, ConferenceCreateRequest, Conferenc use crate::tpdu::{TpduCode, TpduHeader}; use crate::tpkt::TpktHeader; use crate::x224::{X224Pdu, user_data_size}; -use crate::{DecodeResult, EncodeResult, PduError, impl_x224_pdu_borrowing, impl_x224_pdu_pod, per}; +use crate::{DecodeResult, EncodeResult, impl_x224_pdu_borrowing, impl_x224_pdu_pod, per}; // T.125 MCS is defined in: // @@ -932,24 +932,19 @@ impl DomainParameters { } } -pub use legacy::McsError; - mod legacy { #![allow( clippy::multiple_inherent_impl, reason = "Cannot move the implementation from the legacy module" )] - use core::fmt; - use std::io; - use ironrdp_core::{Decode, DecodeResult, Encode, cast_int}; use super::{ - ConnectInitial, ConnectResponse, DomainParameters, PduError, RESULT_ENUM_LENGTH, ReadCursor, WriteCursor, - cast_length, ensure_size, + ConnectInitial, ConnectResponse, DomainParameters, RESULT_ENUM_LENGTH, ReadCursor, WriteCursor, cast_length, + ensure_size, }; - use crate::gcc::{ConferenceCreateRequest, ConferenceCreateResponse, GccError}; + use crate::gcc::{ConferenceCreateRequest, ConferenceCreateResponse}; use crate::{EncodeResult, ber}; // impl<'de> McsPdu<'de> for ConnectInitial { @@ -1176,67 +1171,4 @@ mod legacy { }) } } - - #[derive(Debug)] - pub enum McsError { - IOError(io::Error), - GccError(GccError), - InvalidDisconnectProviderUltimatum, - InvalidDomainMcsPdu, - InvalidPdu(String), - UnexpectedChannelId(String), - Pdu(PduError), - } - - impl fmt::Display for McsError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::GccError(_) => f.write_str("GCC block error"), - Self::InvalidDisconnectProviderUltimatum => f.write_str("invalid disconnect provider ultimatum"), - Self::InvalidDomainMcsPdu => f.write_str("invalid domain MCS PDU"), - Self::InvalidPdu(_) => f.write_str("invalid MCS Connection Sequence PDU"), - Self::UnexpectedChannelId(_) => f.write_str("invalid MCS channel id"), - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } - } - - impl core::error::Error for McsError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::GccError(e) => Some(e), - Self::InvalidDisconnectProviderUltimatum - | Self::InvalidDomainMcsPdu - | Self::InvalidPdu(_) - | Self::UnexpectedChannelId(_) - | Self::Pdu(_) => None, - } - } - } - - impl From for McsError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } - } - - impl From for McsError { - fn from(e: GccError) -> Self { - Self::GccError(e) - } - } - - impl From for McsError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } - } - - impl From for io::Error { - fn from(e: McsError) -> io::Error { - io::Error::other(format!("MCS Connection Sequence error: {e}")) - } - } } diff --git a/crates/ironrdp-pdu/src/rdp/capability_sets/mod.rs b/crates/ironrdp-pdu/src/rdp/capability_sets/mod.rs index adcfa0189..a0d9a0ffb 100644 --- a/crates/ironrdp-pdu/src/rdp/capability_sets/mod.rs +++ b/crates/ironrdp-pdu/src/rdp/capability_sets/mod.rs @@ -1,6 +1,3 @@ -use core::fmt; -use std::io; - use ironrdp_core::{ Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, cast_length, decode, ensure_fixed_part_size, ensure_size, invalid_field_err, unsupported_value_err, write_padding, @@ -8,7 +5,7 @@ use ironrdp_core::{ use num_derive::FromPrimitive; use num_traits::FromPrimitive as _; -use crate::{PduError, utils}; +use crate::utils; mod bitmap; mod bitmap_cache; @@ -605,123 +602,3 @@ impl CapabilitySetType { self as u16 } } - -#[derive(Debug)] -pub enum CapabilitySetsError { - IOError(io::Error), - Utf8Error(std::string::FromUtf8Error), - InvalidType, - InvalidCompressionFlag, - InvalidMultipleRectSupport, - InvalidProtocolVersion, - InvalidCompressionTypes, - InvalidUpdateCapFlag, - InvalidRemoteUnshareFlag, - InvalidCompressionLevel, - InvalidBrushSupportLevel, - InvalidGlyphSupportLevel, - InvalidRfxICapVersion, - InvalidRfxICapTileSize, - InvalidRfxICapColorConvBits, - InvalidRfxICapTransformBits, - InvalidRfxICapEntropyBits, - InvalidRfxCapsetBlockType, - InvalidRfxCapsetType, - InvalidRfxCapsBlockType, - InvalidRfxCapsBockLength, - InvalidRfxCapsNumCapsets, - InvalidCodecProperty, - InvalidCodecID, - InvalidChunkSize, - InvalidPropertyLength, - InvalidLength, - Pdu(PduError), -} - -impl fmt::Display for CapabilitySetsError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::Utf8Error(_) => f.write_str("UTF-8 error"), - Self::InvalidType => f.write_str("invalid type field"), - Self::InvalidCompressionFlag => f.write_str("invalid bitmap compression field"), - Self::InvalidMultipleRectSupport => f.write_str("invalid multiple rectangle support field"), - Self::InvalidProtocolVersion => f.write_str("invalid protocol version field"), - Self::InvalidCompressionTypes => f.write_str("invalid compression types field"), - Self::InvalidUpdateCapFlag => f.write_str("invalid update capability flags field"), - Self::InvalidRemoteUnshareFlag => f.write_str("invalid remote unshare flag field"), - Self::InvalidCompressionLevel => f.write_str("invalid compression level field"), - Self::InvalidBrushSupportLevel => f.write_str("invalid brush support level field"), - Self::InvalidGlyphSupportLevel => f.write_str("invalid glyph support level field"), - Self::InvalidRfxICapVersion => f.write_str("invalid RemoteFX capability version"), - Self::InvalidRfxICapTileSize => f.write_str("invalid RemoteFX capability tile size"), - Self::InvalidRfxICapColorConvBits => f.write_str("invalid RemoteFXICap color conversion bits"), - Self::InvalidRfxICapTransformBits => f.write_str("invalid RemoteFXICap transform bits"), - Self::InvalidRfxICapEntropyBits => f.write_str("invalid RemoteFXICap entropy bits field"), - Self::InvalidRfxCapsetBlockType => f.write_str("invalid RemoteFX capability set block type"), - Self::InvalidRfxCapsetType => f.write_str("invalid RemoteFX capability set type"), - Self::InvalidRfxCapsBlockType => f.write_str("invalid RemoteFX capabilities block type"), - Self::InvalidRfxCapsBockLength => f.write_str("invalid RemoteFX capabilities block length"), - Self::InvalidRfxCapsNumCapsets => f.write_str("invalid number of capability sets in RemoteFX capabilities"), - Self::InvalidCodecProperty => f.write_str("invalid codec property field"), - Self::InvalidCodecID => f.write_str("invalid codec ID"), - Self::InvalidChunkSize => f.write_str("invalid channel chunk size field"), - Self::InvalidPropertyLength => f.write_str("invalid codec property length for the current property ID"), - Self::InvalidLength => f.write_str("invalid data length"), - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } -} - -impl core::error::Error for CapabilitySetsError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::Utf8Error(e) => Some(e), - Self::InvalidType - | Self::InvalidCompressionFlag - | Self::InvalidMultipleRectSupport - | Self::InvalidProtocolVersion - | Self::InvalidCompressionTypes - | Self::InvalidUpdateCapFlag - | Self::InvalidRemoteUnshareFlag - | Self::InvalidCompressionLevel - | Self::InvalidBrushSupportLevel - | Self::InvalidGlyphSupportLevel - | Self::InvalidRfxICapVersion - | Self::InvalidRfxICapTileSize - | Self::InvalidRfxICapColorConvBits - | Self::InvalidRfxICapTransformBits - | Self::InvalidRfxICapEntropyBits - | Self::InvalidRfxCapsetBlockType - | Self::InvalidRfxCapsetType - | Self::InvalidRfxCapsBlockType - | Self::InvalidRfxCapsBockLength - | Self::InvalidRfxCapsNumCapsets - | Self::InvalidCodecProperty - | Self::InvalidCodecID - | Self::InvalidChunkSize - | Self::InvalidPropertyLength - | Self::InvalidLength - | Self::Pdu(_) => None, - } - } -} - -impl From for CapabilitySetsError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for CapabilitySetsError { - fn from(e: std::string::FromUtf8Error) -> Self { - Self::Utf8Error(e) - } -} - -impl From for CapabilitySetsError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } -} diff --git a/crates/ironrdp-pdu/src/rdp/client_info.rs b/crates/ironrdp-pdu/src/rdp/client_info.rs index 05ce17aa8..c3e819144 100644 --- a/crates/ironrdp-pdu/src/rdp/client_info.rs +++ b/crates/ironrdp-pdu/src/rdp/client_info.rs @@ -1,5 +1,4 @@ use core::fmt; -use std::io; use bitflags::bitflags; use ironrdp_core::{ @@ -9,8 +8,8 @@ use ironrdp_core::{ use num_derive::FromPrimitive; use num_traits::FromPrimitive as _; +use crate::utils; use crate::utils::CharacterSet; -use crate::{PduError, utils}; const RECONNECT_COOKIE_LEN: usize = 28; const TIMEZONE_INFO_NAME_LEN: usize = 64; @@ -756,63 +755,6 @@ impl CompressionType { } } -#[derive(Debug)] -pub enum ClientInfoError { - IOError(io::Error), - Utf8Error(std::string::FromUtf8Error), - InvalidAddressFamily, - InvalidClientInfoFlags, - InvalidPerformanceFlags, - InvalidReconnectCookie, - Pdu(PduError), -} - -impl fmt::Display for ClientInfoError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::Utf8Error(_) => f.write_str("UTF-8 error"), - Self::InvalidAddressFamily => f.write_str("invalid address family field"), - Self::InvalidClientInfoFlags => f.write_str("invalid flags field"), - Self::InvalidPerformanceFlags => f.write_str("invalid performance flags field"), - Self::InvalidReconnectCookie => f.write_str("invalid reconnect cookie field"), - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } -} - -impl core::error::Error for ClientInfoError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::Utf8Error(e) => Some(e), - Self::InvalidAddressFamily - | Self::InvalidClientInfoFlags - | Self::InvalidPerformanceFlags - | Self::InvalidReconnectCookie - | Self::Pdu(_) => None, - } - } -} - -impl From for ClientInfoError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for ClientInfoError { - fn from(e: std::string::FromUtf8Error) -> Self { - Self::Utf8Error(e) - } -} - -impl From for ClientInfoError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } -} - fn string_len(value: &str, character_set: CharacterSet) -> usize { match character_set { CharacterSet::Ansi => value.len(), diff --git a/crates/ironrdp-pdu/src/rdp/mod.rs b/crates/ironrdp-pdu/src/rdp/mod.rs index c9b1582c0..759de20d9 100644 --- a/crates/ironrdp-pdu/src/rdp/mod.rs +++ b/crates/ironrdp-pdu/src/rdp/mod.rs @@ -1,16 +1,9 @@ -use core::fmt; -use std::io; - use ironrdp_core::{ Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, ensure_fixed_part_size, invalid_field_err, }; -use crate::PduError; -use crate::input::InputEventError; -use crate::rdp::capability_sets::CapabilitySetsError; -use crate::rdp::client_info::{ClientInfo, ClientInfoError}; -use crate::rdp::headers::{BasicSecurityHeader, BasicSecurityHeaderFlags, ShareControlPduType, ShareDataPduType}; -use crate::rdp::server_license::ServerLicenseError; +use crate::rdp::client_info::ClientInfo; +use crate::rdp::headers::{BasicSecurityHeader, BasicSecurityHeaderFlags}; pub mod autodetect; pub mod capability_sets; @@ -73,111 +66,3 @@ impl<'de> Decode<'de> for ClientInfoPdu { }) } } - -#[derive(Debug)] -pub enum RdpError { - IOError(io::Error), - ClientInfoError(ClientInfoError), - ServerLicenseError(ServerLicenseError), - CapabilitySetsError(CapabilitySetsError), - InvalidSecurityHeader, - InvalidShareControlHeader(String), - InvalidShareDataHeader(String), - InvalidPdu(String), - UnexpectedShareControlPdu(ShareControlPduType), - UnexpectedShareDataPdu(ShareDataPduType), - SaveSessionInfoError(session_info::SessionError), - InputEventError(InputEventError), - NotEnoughBytes, - Pdu(PduError), -} - -impl fmt::Display for RdpError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::ClientInfoError(_) => f.write_str("client Info PDU error"), - Self::ServerLicenseError(_) => f.write_str("server License PDU error"), - Self::CapabilitySetsError(_) => f.write_str("capability sets error"), - Self::InvalidSecurityHeader => f.write_str("invalid RDP security header"), - Self::InvalidShareControlHeader(s) => write!(f, "invalid RDP Share Control Header: {s}"), - Self::InvalidShareDataHeader(s) => write!(f, "invalid RDP Share Data Header: {s}"), - Self::InvalidPdu(_) => f.write_str("invalid RDP Connection Sequence PDU"), - Self::UnexpectedShareControlPdu(ty) => write!(f, "unexpected RDP Share Control Header PDU type: {ty:?}"), - Self::UnexpectedShareDataPdu(ty) => write!(f, "unexpected RDP Share Data Header PDU type: {ty:?}"), - Self::SaveSessionInfoError(_) => f.write_str("save session info PDU error"), - Self::InputEventError(_) => f.write_str("input event PDU error"), - Self::NotEnoughBytes => f.write_str("not enough bytes"), - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } -} - -impl core::error::Error for RdpError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::ClientInfoError(e) => Some(e), - Self::ServerLicenseError(e) => Some(e), - Self::CapabilitySetsError(e) => Some(e), - Self::SaveSessionInfoError(e) => Some(e), - Self::InputEventError(e) => Some(e), - Self::InvalidSecurityHeader - | Self::InvalidShareControlHeader(_) - | Self::InvalidShareDataHeader(_) - | Self::InvalidPdu(_) - | Self::UnexpectedShareControlPdu(_) - | Self::UnexpectedShareDataPdu(_) - | Self::NotEnoughBytes - | Self::Pdu(_) => None, - } - } -} - -impl From for RdpError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for RdpError { - fn from(e: ClientInfoError) -> Self { - Self::ClientInfoError(e) - } -} - -impl From for RdpError { - fn from(e: ServerLicenseError) -> Self { - Self::ServerLicenseError(e) - } -} - -impl From for RdpError { - fn from(e: CapabilitySetsError) -> Self { - Self::CapabilitySetsError(e) - } -} - -impl From for RdpError { - fn from(e: session_info::SessionError) -> Self { - Self::SaveSessionInfoError(e) - } -} - -impl From for RdpError { - fn from(e: InputEventError) -> Self { - Self::InputEventError(e) - } -} - -impl From for RdpError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } -} - -impl From for io::Error { - fn from(e: RdpError) -> io::Error { - io::Error::other(format!("RDP Connection Sequence error: {e}")) - } -} diff --git a/crates/ironrdp-pdu/src/rdp/server_license/mod.rs b/crates/ironrdp-pdu/src/rdp/server_license/mod.rs index b5e714a7f..eda756111 100644 --- a/crates/ironrdp-pdu/src/rdp/server_license/mod.rs +++ b/crates/ironrdp-pdu/src/rdp/server_license/mod.rs @@ -199,6 +199,8 @@ impl BlobType { pub const CLIENT_MACHINE_NAME_BLOB: Self = Self(0x10); } +// FIXME: licensing logic and any code that is not purely about PDU +// encoding/decoding concerns should be moved out of ironrdp-pdu. #[derive(Debug)] pub enum ServerLicenseError { IOError(io::Error), diff --git a/crates/ironrdp-pdu/src/rdp/session_info/mod.rs b/crates/ironrdp-pdu/src/rdp/session_info/mod.rs index 1b6b679c9..87a396be0 100644 --- a/crates/ironrdp-pdu/src/rdp/session_info/mod.rs +++ b/crates/ironrdp-pdu/src/rdp/session_info/mod.rs @@ -1,6 +1,3 @@ -use core::fmt; -use std::io; - use ironrdp_core::{ Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, ensure_fixed_part_size, ensure_size, invalid_field_err, read_padding, write_padding, @@ -8,8 +5,6 @@ use ironrdp_core::{ use num_derive::FromPrimitive; use num_traits::FromPrimitive as _; -use crate::PduError; - #[cfg(test)] mod tests; @@ -126,66 +121,3 @@ pub enum InfoData { PlainNotify, LogonExtended(LogonInfoExtended), } - -#[derive(Debug)] -pub enum SessionError { - IOError(io::Error), - InvalidSaveSessionInfoType, - InvalidDomainNameSize, - InvalidUserNameSize, - InvalidLogonVersion2, - InvalidLogonVersion2Size, - InvalidAutoReconnectPacketSize, - InvalidAutoReconnectVersion, - InvalidLogonErrorType, - InvalidLogonErrorData, - Pdu(PduError), -} - -impl fmt::Display for SessionError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::InvalidSaveSessionInfoType => f.write_str("invalid save session info type value"), - Self::InvalidDomainNameSize => f.write_str("invalid domain name size value"), - Self::InvalidUserNameSize => f.write_str("invalid user name size value"), - Self::InvalidLogonVersion2 => f.write_str("invalid logon version value"), - Self::InvalidLogonVersion2Size => f.write_str("invalid logon info version2 size value"), - Self::InvalidAutoReconnectPacketSize => f.write_str("invalid server auto-reconnect packet size value"), - Self::InvalidAutoReconnectVersion => f.write_str("invalid server auto-reconnect version"), - Self::InvalidLogonErrorType => f.write_str("invalid logon error type value"), - Self::InvalidLogonErrorData => f.write_str("invalid logon error data value"), - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } -} - -impl core::error::Error for SessionError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::InvalidSaveSessionInfoType - | Self::InvalidDomainNameSize - | Self::InvalidUserNameSize - | Self::InvalidLogonVersion2 - | Self::InvalidLogonVersion2Size - | Self::InvalidAutoReconnectPacketSize - | Self::InvalidAutoReconnectVersion - | Self::InvalidLogonErrorType - | Self::InvalidLogonErrorData - | Self::Pdu(_) => None, - } - } -} - -impl From for SessionError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for SessionError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } -} diff --git a/crates/ironrdp-pdu/src/rdp/vc/mod.rs b/crates/ironrdp-pdu/src/rdp/vc/mod.rs index 8bc2f9903..a154bf5bd 100644 --- a/crates/ironrdp-pdu/src/rdp/vc/mod.rs +++ b/crates/ironrdp-pdu/src/rdp/vc/mod.rs @@ -3,14 +3,9 @@ pub mod dvc; #[cfg(test)] mod tests; -use core::fmt; -use std::{io, str}; - use bitflags::bitflags; use ironrdp_core::{Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, ensure_fixed_part_size}; -use crate::PduError; - const CHANNEL_PDU_HEADER_SIZE: usize = 8; /// Channel PDU Header (CHANNEL_PDU_HEADER) @@ -78,83 +73,3 @@ bitflags! { const _ = !0; } } - -#[derive(Debug)] -pub enum ChannelError { - IOError(io::Error), - FromUtf8Error(std::string::FromUtf8Error), - InvalidChannelPduHeader, - InvalidChannelTotalDataLength, - InvalidDvcPduType, - InvalidDVChannelIdLength, - InvalidDvcDataLength, - InvalidDvcCapabilitiesVersion, - InvalidDvcMessageSize, - InvalidDvcTotalMessageSize { actual: usize, expected: usize }, - Pdu(PduError), -} - -impl fmt::Display for ChannelError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::IOError(_) => f.write_str("IO error"), - Self::FromUtf8Error(_) => f.write_str("from UTF-8 error"), - Self::InvalidChannelPduHeader => f.write_str("invalid channel PDU header"), - Self::InvalidChannelTotalDataLength => f.write_str("invalid channel total data length"), - Self::InvalidDvcPduType => f.write_str("invalid DVC PDU type"), - Self::InvalidDVChannelIdLength => f.write_str("invalid DVC id length value"), - Self::InvalidDvcDataLength => f.write_str("invalid DVC data length value"), - Self::InvalidDvcCapabilitiesVersion => f.write_str("invalid DVC capabilities version"), - Self::InvalidDvcMessageSize => f.write_str("invalid DVC message size"), - Self::InvalidDvcTotalMessageSize { actual, expected } => { - write!( - f, - "invalid DVC total message size: actual ({actual}) > expected ({expected})" - ) - } - Self::Pdu(e) => write!(f, "PDU error: {e}"), - } - } -} - -impl core::error::Error for ChannelError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - Self::IOError(e) => Some(e), - Self::FromUtf8Error(e) => Some(e), - Self::InvalidChannelPduHeader - | Self::InvalidChannelTotalDataLength - | Self::InvalidDvcPduType - | Self::InvalidDVChannelIdLength - | Self::InvalidDvcDataLength - | Self::InvalidDvcCapabilitiesVersion - | Self::InvalidDvcMessageSize - | Self::InvalidDvcTotalMessageSize { .. } - | Self::Pdu(_) => None, - } - } -} - -impl From for ChannelError { - fn from(e: io::Error) -> Self { - Self::IOError(e) - } -} - -impl From for ChannelError { - fn from(e: std::string::FromUtf8Error) -> Self { - Self::FromUtf8Error(e) - } -} - -impl From for ChannelError { - fn from(e: PduError) -> Self { - Self::Pdu(e) - } -} - -impl From for io::Error { - fn from(e: ChannelError) -> io::Error { - io::Error::other(format!("Virtual channel error: {e}")) - } -}