refactor(pdu): drop impl_pdu_parsing!() macros

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2024-02-13 18:08:07 +04:00 committed by Benoît Cortier
parent 282731bfe8
commit c046e5396b
52 changed files with 0 additions and 203 deletions

View file

@ -204,8 +204,6 @@ impl<'de> PduDecode<'de> for FrameAcknowledgePdu {
}
}
impl_pdu_parsing!(FrameAcknowledgePdu);
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
#[repr(u16)]
pub enum BlockType {

View file

@ -68,8 +68,6 @@ impl<'de> PduDecode<'de> for ClientClusterData {
}
}
impl_pdu_parsing!(ClientClusterData);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RedirectionFlags: u32 {

View file

@ -172,8 +172,6 @@ impl<'de> PduDecode<'de> for ConferenceCreateRequest {
}
}
impl_pdu_parsing_max!(ConferenceCreateRequest);
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ConferenceCreateResponse {
pub user_id: u16,
@ -322,5 +320,3 @@ impl<'de> PduDecode<'de> for ConferenceCreateResponse {
Ok(Self { user_id, gcc_blocks })
}
}
impl_pdu_parsing_max!(ConferenceCreateResponse);

View file

@ -41,8 +41,6 @@ impl<'de> PduDecode<'de> for ClientMessageChannelData {
}
}
impl_pdu_parsing!(ClientMessageChannelData);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ServerMessageChannelData {
pub mcs_message_channel_id: u16,
@ -81,5 +79,3 @@ impl<'de> PduDecode<'de> for ServerMessageChannelData {
Ok(Self { mcs_message_channel_id })
}
}
impl_pdu_parsing!(ServerMessageChannelData);

View file

@ -121,8 +121,6 @@ impl<'de> PduDecode<'de> for Monitor {
}
}
impl_pdu_parsing!(Monitor);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MonitorFlags: u32 {

View file

@ -131,8 +131,6 @@ impl<'de> PduDecode<'de> for ExtendedMonitorInfo {
}
}
impl_pdu_parsing!(ExtendedMonitorInfo);
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum MonitorOrientation {
Landscape = 0,

View file

@ -43,8 +43,6 @@ impl<'de> PduDecode<'de> for MultiTransportChannelData {
}
}
impl_pdu_parsing!(MultiTransportChannelData);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MultiTransportFlags: u32 {

View file

@ -267,8 +267,6 @@ impl<'de> PduDecode<'de> for ChannelDef {
}
}
impl_pdu_parsing!(ChannelDef);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ChannelOptions: u32 {

View file

@ -71,8 +71,6 @@ impl<'de> PduDecode<'de> for ClientSecurityData {
}
}
impl_pdu_parsing!(ClientSecurityData);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ServerSecurityData {
pub encryption_method: EncryptionMethod,

View file

@ -222,8 +222,6 @@ impl<'de> PduDecode<'de> for FastPathInputEvent {
}
}
impl_pdu_parsing!(FastPathInputEvent);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct KeyboardFlags: u8 {
@ -298,5 +296,3 @@ impl<'de> PduDecode<'de> for FastPathInput {
Ok(Self(events))
}
}
impl_pdu_parsing_max!(FastPathInput);

View file

@ -71,8 +71,6 @@ impl<'de> PduDecode<'de> for InputEventPdu {
}
}
impl_pdu_parsing_max!(InputEventPdu);
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InputEvent {
Sync(SyncPdu),
@ -147,8 +145,6 @@ impl<'de> PduDecode<'de> for InputEvent {
}
}
impl_pdu_parsing!(InputEvent);
#[derive(Debug, Copy, Clone, PartialEq, FromPrimitive, ToPrimitive)]
#[repr(u16)]
enum InputEventType {

View file

@ -76,8 +76,6 @@ impl<'de> PduDecode<'de> for MousePdu {
})
}
}
impl_pdu_parsing!(MousePdu);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PointerFlags: u16 {

View file

@ -54,8 +54,6 @@ impl<'de> PduDecode<'de> for MouseRelPdu {
}
}
impl_pdu_parsing!(MouseRelPdu);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PointerRelFlags: u16 {

View file

@ -54,8 +54,6 @@ impl<'de> PduDecode<'de> for MouseXPdu {
}
}
impl_pdu_parsing!(MouseXPdu);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PointerXFlags: u16 {

View file

@ -49,8 +49,6 @@ impl<'de> PduDecode<'de> for ScanCodePdu {
}
}
impl_pdu_parsing!(ScanCodePdu);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct KeyboardFlags: u16 {

View file

@ -46,8 +46,6 @@ impl<'de> PduDecode<'de> for SyncPdu {
}
}
impl_pdu_parsing!(SyncPdu);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SyncToggleFlags: u32 {

View file

@ -49,8 +49,6 @@ impl<'de> PduDecode<'de> for UnicodePdu {
}
}
impl_pdu_parsing!(UnicodePdu);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct KeyboardFlags: u16 {

View file

@ -37,5 +37,3 @@ impl<'de> PduDecode<'de> for UnusedPdu {
Ok(Self)
}
}
impl_pdu_parsing!(UnusedPdu);

View file

@ -325,62 +325,3 @@ macro_rules! try_write_optional {
}
};
}
#[macro_export]
macro_rules! from_buffer {
($stream:expr, size: $expected:expr) => {{
let mut buf = [0; $expected];
let len = match $stream.read(&mut buf) {
Ok(len) => len,
Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {
return Err(not_enough_bytes_err!(0, $expected));
}
Err(e) => return Err(custom_err!(e)),
};
$crate::decode(&buf[0..len])
}};
}
#[macro_export]
macro_rules! to_buffer {
($self:expr, $stream:expr, size: $expected:expr) => {{
let mut buf = vec![0; $expected];
let len = $crate::encode($self, &mut buf)?;
$stream.write_all(&buf[0..len]).map_err(|e| custom_err!(e))?;
Ok(())
}};
}
#[macro_export]
macro_rules! impl_pdu_parsing {
($pdu_ty:ty, $size:expr) => {
impl $crate::PduParsing for $pdu_ty {
type Error = $crate::PduError;
fn from_buffer(mut stream: impl std::io::Read) -> Result<Self, Self::Error> {
from_buffer!(stream, size: $size)
}
fn to_buffer(&self, mut stream: impl std::io::Write) -> Result<(), Self::Error> {
to_buffer!(self, stream, size: self.size())
}
fn buffer_length(&self) -> usize {
self.size()
}
}
};
($pdu_ty:ty) => {
$crate::impl_pdu_parsing!($pdu_ty, Self::FIXED_PART_SIZE);
};
}
// This is only suitable for temporary code translation, as it will "eat"
// MAX_PDU_SIZE input data...
#[deprecated(note = "FIXME: this macro will eat too much data!")]
#[macro_export]
macro_rules! impl_pdu_parsing_max {
($pdu_ty:ty) => {
$crate::impl_pdu_parsing!($pdu_ty, $crate::legacy::MAX_PDU_SIZE);
};
}

View file

@ -1154,8 +1154,6 @@ mod legacy {
}
}
impl_pdu_parsing_max!(DomainParameters);
#[derive(Debug, Error)]
pub enum McsError {
#[error("IO error")]

View file

@ -100,8 +100,6 @@ impl<'de> PduDecode<'de> for ServerDemandActive {
}
}
impl_pdu_parsing_max!(ServerDemandActive);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClientConfirmActive {
/// According to [MSDN](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/4e9722c3-ad83-43f5-af5a-529f73d88b48),
@ -149,8 +147,6 @@ impl<'de> PduDecode<'de> for ClientConfirmActive {
}
}
impl_pdu_parsing_max!(ClientConfirmActive);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DemandActive {
pub source_descriptor: String,

View file

@ -107,5 +107,3 @@ impl<'de> PduDecode<'de> for Bitmap {
})
}
}
impl_pdu_parsing!(Bitmap);

View file

@ -63,8 +63,6 @@ impl<'de> PduDecode<'de> for BitmapCache {
}
}
impl_pdu_parsing!(BitmapCache);
#[derive(Debug, PartialEq, Eq, Copy, Clone, Default)]
pub struct CacheEntry {
pub entries: u16,
@ -178,8 +176,6 @@ impl<'de> PduDecode<'de> for BitmapCacheRev2 {
}
}
impl_pdu_parsing!(BitmapCacheRev2);
#[derive(Debug, PartialEq, Eq, Copy, Clone, Default)]
pub struct CellInfo {
pub num_entries: u32,

View file

@ -143,8 +143,6 @@ impl<'de> PduDecode<'de> for BitmapCodecs {
}
}
impl_pdu_parsing!(BitmapCodecs);
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Codec {
pub id: u8,

View file

@ -55,5 +55,3 @@ impl<'de> PduDecode<'de> for Brush {
Ok(Brush { support_level })
}
}
impl_pdu_parsing!(Brush);

View file

@ -42,8 +42,6 @@ impl<'de> PduDecode<'de> for FrameAcknowledge {
}
}
impl_pdu_parsing!(FrameAcknowledge);
#[cfg(test)]
mod test {
use super::*;

View file

@ -198,5 +198,3 @@ impl<'de> PduDecode<'de> for General {
})
}
}
impl_pdu_parsing!(General);

View file

@ -122,5 +122,3 @@ impl<'de> PduDecode<'de> for GlyphCache {
})
}
}
impl_pdu_parsing!(GlyphCache);

View file

@ -104,5 +104,3 @@ impl<'de> PduDecode<'de> for Input {
})
}
}
impl_pdu_parsing!(Input);

View file

@ -42,8 +42,6 @@ impl<'de> PduDecode<'de> for LargePointer {
}
}
impl_pdu_parsing!(LargePointer);
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LargePointerSupportFlags: u16 {

View file

@ -40,8 +40,6 @@ impl<'de> PduDecode<'de> for MultifragmentUpdate {
}
}
impl_pdu_parsing!(MultifragmentUpdate);
#[cfg(test)]
mod test {
use super::*;

View file

@ -54,5 +54,3 @@ impl<'de> PduDecode<'de> for OffscreenBitmapCache {
})
}
}
impl_pdu_parsing!(OffscreenBitmapCache);

View file

@ -163,5 +163,3 @@ impl<'de> PduDecode<'de> for Order {
})
}
}
impl_pdu_parsing!(Order);

View file

@ -52,5 +52,3 @@ impl<'de> PduDecode<'de> for Pointer {
})
}
}
impl_pdu_parsing!(Pointer);

View file

@ -55,5 +55,3 @@ impl<'de> PduDecode<'de> for Sound {
Ok(Sound { flags })
}
}
impl_pdu_parsing!(Sound);

View file

@ -57,5 +57,3 @@ impl<'de> PduDecode<'de> for SurfaceCommands {
Ok(SurfaceCommands { flags })
}
}
impl_pdu_parsing!(SurfaceCommands);

View file

@ -88,5 +88,3 @@ impl<'de> PduDecode<'de> for VirtualChannel {
Ok(virtual_channel_pdu)
}
}
impl_pdu_parsing_max!(VirtualChannel);

View file

@ -56,8 +56,6 @@ impl<'de> PduDecode<'de> for SynchronizePdu {
}
}
impl_pdu_parsing!(SynchronizePdu);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ControlPdu {
pub action: ControlAction,
@ -108,8 +106,6 @@ impl<'de> PduDecode<'de> for ControlPdu {
}
}
impl_pdu_parsing!(ControlPdu);
/// [2.2.1.22.1] Font Map PDU Data (TS_FONT_MAP_PDU)
///
/// [2.2.1.22.1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/b4e557f3-7540-46fc-815d-0c12299cf1ee
@ -179,8 +175,6 @@ impl<'de> PduDecode<'de> for FontPdu {
}
}
impl_pdu_parsing!(FontPdu);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MonitorLayoutPdu {
pub monitors: Vec<gcc::Monitor>,
@ -232,8 +226,6 @@ impl<'de> PduDecode<'de> for MonitorLayoutPdu {
}
}
impl_pdu_parsing_max!(MonitorLayoutPdu);
#[repr(u16)]
#[derive(Debug, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum ControlAction {

View file

@ -70,8 +70,6 @@ impl<'de> PduDecode<'de> for BasicSecurityHeader {
}
}
impl_pdu_parsing!(BasicSecurityHeader);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShareControlHeader {
pub share_control_pdu: ShareControlPdu,
@ -155,8 +153,6 @@ impl<'de> PduDecode<'de> for ShareControlHeader {
}
}
impl_pdu_parsing!(ShareControlHeader);
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ShareControlPdu {
ServerDemandActive(ServerDemandActive),
@ -303,8 +299,6 @@ impl<'de> PduDecode<'de> for ShareDataHeader {
}
}
impl_pdu_parsing!(ShareDataHeader);
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ShareDataPdu {
Synchronize(SynchronizePdu),

View file

@ -60,5 +60,3 @@ impl<'de> PduDecode<'de> for RefreshRectanglePdu {
Ok(Self { areas_to_refresh })
}
}
impl_pdu_parsing!(RefreshRectanglePdu);

View file

@ -45,8 +45,6 @@ impl<'de> PduDecode<'de> for ServerSetErrorInfoPdu {
}
}
impl_pdu_parsing!(ServerSetErrorInfoPdu);
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ErrorInfo {
ProtocolIndependentCode(ProtocolIndependentCode),

View file

@ -126,8 +126,6 @@ impl<'de> PduDecode<'de> for LicenseHeader {
}
}
impl_pdu_parsing!(LicenseHeader);
/// [2.2.1.12.1.1] Licensing Preamble (LICENSE_PREAMBLE)
///
/// [2.2.1.12.1.1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/73170ca2-5f82-4a2d-9d1b-b439f3d8dadc
@ -313,8 +311,6 @@ impl<'de> PduDecode<'de> for BlobHeader {
}
}
impl_pdu_parsing!(BlobHeader);
fn compute_mac_data(mac_salt_key: &[u8], data: &[u8]) -> Vec<u8> {
let data_len_buffer = (data.len() as u32).to_le_bytes();

View file

@ -222,8 +222,6 @@ impl<'de> PduDecode<'de> for ClientNewLicenseRequest {
}
}
impl_pdu_parsing_max!(ClientNewLicenseRequest);
fn salted_hash(salt: &[u8], salt_first: &[u8], salt_second: &[u8], input: &[u8]) -> Vec<u8> {
let mut hasher = sha1::Sha1::new();
hasher.update([input, salt, salt_first, salt_second].concat().as_slice());

View file

@ -163,8 +163,6 @@ impl<'de> PduDecode<'de> for ClientPlatformChallengeResponse {
}
}
impl_pdu_parsing_max!(ClientPlatformChallengeResponse);
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive)]
enum ClientType {
Win32 = 0x0100,
@ -242,8 +240,6 @@ impl<'de> PduDecode<'de> for PlatformChallengeResponseData {
}
}
impl_pdu_parsing_max!(PlatformChallengeResponseData);
#[derive(Debug, PartialEq, Eq)]
pub(crate) struct ClientHardwareIdentification {
pub(crate) platform_id: u32,
@ -285,5 +281,3 @@ impl<'de> PduDecode<'de> for ClientHardwareIdentification {
Ok(Self { platform_id, data })
}
}
impl_pdu_parsing!(ClientHardwareIdentification);

View file

@ -74,8 +74,6 @@ impl<'de> PduDecode<'de> for LicensingErrorMessage {
}
}
impl_pdu_parsing_max!(LicensingErrorMessage);
#[derive(Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum LicenseErrorCode {
InvalidServerCertificate = 0x01,

View file

@ -135,8 +135,6 @@ impl<'de> PduDecode<'de> for InitialServerLicenseMessage {
}
}
// impl_pdu_parsing_max!(InitialServerLicenseMessage);
/// [2.2.2.1] Server License Request (SERVER_LICENSE_REQUEST)
///
/// [2.2.2.1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpele/e17772e9-9642-4bb6-a2bc-82875dd6da7c
@ -249,8 +247,6 @@ impl<'de> PduDecode<'de> for ServerLicenseRequest {
}
}
impl_pdu_parsing_max!(ServerLicenseRequest);
#[derive(Debug, PartialEq, Eq)]
pub struct Scope(pub String);
@ -302,8 +298,6 @@ impl<'de> PduDecode<'de> for Scope {
}
}
impl_pdu_parsing!(Scope);
/// [2.2.1.4.3.1] Server Certificate (SERVER_CERTIFICATE)
///
/// [2.2.1.4.3.1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/54e72cc6-3422-404c-a6b4-2486db125342
@ -419,8 +413,6 @@ impl<'de> PduDecode<'de> for ServerCertificate {
}
}
impl_pdu_parsing!(ServerCertificate);
#[derive(Debug, PartialEq, Eq)]
pub struct ProductInfo {
pub version: u32,
@ -505,5 +497,3 @@ impl<'de> PduDecode<'de> for ProductInfo {
})
}
}
impl_pdu_parsing_max!(ProductInfo);

View file

@ -97,8 +97,6 @@ impl<'de> PduDecode<'de> for X509CertificateChain {
}
}
impl_pdu_parsing_max!(X509CertificateChain);
/// [2.2.1.4.3.1.1] Server Proprietary Certificate (PROPRIETARYSERVERCERTIFICATE)
///
/// [2.2.1.4.3.1.1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/a37d449a-73ac-4f00-9b9d-56cefc954634
@ -168,8 +166,6 @@ impl<'de> PduDecode<'de> for ProprietaryCertificate {
}
}
impl_pdu_parsing!(ProprietaryCertificate);
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct RsaPublicKey {
pub public_exponent: u32,
@ -245,5 +241,3 @@ impl<'de> PduDecode<'de> for RsaPublicKey {
})
}
}
impl_pdu_parsing_max!(RsaPublicKey);

View file

@ -68,5 +68,3 @@ impl<'de> PduDecode<'de> for ServerPlatformChallenge {
})
}
}
impl_pdu_parsing!(ServerPlatformChallenge);

View file

@ -91,8 +91,6 @@ impl<'de> PduDecode<'de> for ServerUpgradeLicense {
}
}
impl_pdu_parsing_max!(ServerUpgradeLicense);
#[derive(Debug, PartialEq, Eq)]
pub struct NewLicenseInformation {
pub version: u32,
@ -181,5 +179,3 @@ impl<'de> PduDecode<'de> for NewLicenseInformation {
})
}
}
impl_pdu_parsing_max!(NewLicenseInformation);

View file

@ -97,8 +97,6 @@ impl<'de> PduDecode<'de> for SaveSessionInfoPdu {
}
}
impl_pdu_parsing!(SaveSessionInfoPdu);
#[repr(u32)]
#[derive(Debug, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum InfoType {

View file

@ -93,8 +93,6 @@ impl<'de> PduDecode<'de> for LogonInfoVersion1 {
}
}
impl_pdu_parsing!(LogonInfoVersion1);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LogonInfoVersion2 {
pub logon_info: LogonInfo,

View file

@ -87,5 +87,3 @@ impl<'de> PduDecode<'de> for SuppressOutputPdu {
Ok(Self { desktop_rect })
}
}
impl_pdu_parsing!(SuppressOutputPdu);