now_proto_pdu/session/
lock.rs

1use ironrdp_core::{Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor};
2
3use crate::{NowHeader, NowMessage, NowMessageClass, NowSessionMessage, NowSessionMessageKind};
4
5/// The NOW_SESSION_LOCK_MSG is used to request locking the user session.
6///
7/// NOW_PROTO: NOW_SESSION_LOCK_MSG
8#[derive(Debug, Clone, PartialEq, Eq, Default)]
9#[non_exhaustive]
10pub struct NowSessionLockMsg;
11
12impl NowSessionLockMsg {
13    const NAME: &'static str = "NOW_SESSION_LOCK_MSG";
14}
15
16impl Encode for NowSessionLockMsg {
17    fn encode(&self, dst: &mut WriteCursor<'_>) -> EncodeResult<()> {
18        let header = NowHeader {
19            size: 0,
20            class: NowMessageClass::SESSION,
21            kind: NowSessionMessageKind::LOCK.0,
22            flags: 0,
23        };
24
25        header.encode(dst)?;
26
27        Ok(())
28    }
29
30    fn name(&self) -> &'static str {
31        Self::NAME
32    }
33
34    fn size(&self) -> usize {
35        NowHeader::FIXED_PART_SIZE
36    }
37}
38
39impl Decode<'_> for NowSessionLockMsg {
40    fn decode(src: &mut ReadCursor<'_>) -> DecodeResult<Self> {
41        let header = NowHeader::decode(src)?;
42
43        match (header.class, NowSessionMessageKind(header.kind)) {
44            (NowMessageClass::SESSION, NowSessionMessageKind::LOCK) => Ok(Self::default()),
45            _ => Err(unsupported_message_err!(class: header.class.0, kind: header.kind)),
46        }
47    }
48}
49
50impl From<NowSessionLockMsg> for NowMessage<'_> {
51    fn from(val: NowSessionLockMsg) -> Self {
52        NowMessage::Session(NowSessionMessage::Lock(val))
53    }
54}