1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use binrw::binrw;

pub mod arch;
pub mod connect;
pub mod cryptography;
pub mod trans;
pub mod userauth;

#[cfg(doc)]
use trans::{KexEcdhInit, KexEcdhReply};

/// The purpose of this macro is to automatically document variants
/// and link to the underlying item documentation.
macro_rules! message {
    ($( $name:ident($path:path) ),+ $(,)?) => {
        /// A SSH 2.0 message in it's decrypted form.
        ///
        /// # Caveats
        ///
        /// The [`userauth::PkOk`], [`userauth::PasswdChangereq`], [`userauth::InfoRequest`] and [`userauth::InfoResponse`]
        /// messages are not included in this enum because they share the same `magic` byte value in the protocol.
        ///
        /// This is the same for the [`KexEcdhInit`] and [`KexEcdhReply`].
        #[non_exhaustive]
        #[binrw]
        #[derive(Debug, Clone)]
        #[brw(big)]
        pub enum Message {
            $(
                #[doc = concat!("See [`", stringify!($path), "`] for more details.")]
                $name($path)
            ),+
        }
    };
}

message! {
    Disconnect(trans::Disconnect),
    Ignore(trans::Ignore),
    Unimplemented(trans::Unimplemented),
    Debug(trans::Debug),
    ServiceRequest(trans::ServiceRequest),
    ServiceAccept(trans::ServiceAccept),
    KexInit(trans::KexInit),
    NewKeys(trans::NewKeys),

    AuthRequest(userauth::Request),
    AuthFailure(userauth::Failure),
    AuthSuccess(userauth::Success),
    AuthBanner(userauth::Banner),

    GlobalRequest(connect::GlobalRequest),
    RequestSuccess(connect::RequestSuccess),
    ChannelOpen(connect::ChannelOpen),
    ChannelOpenConfirmation(connect::ChannelOpenConfirmation),
    ChannelOpenFailure(connect::ChannelOpenFailure),
    ChannelWindowAdjust(connect::ChannelWindowAdjust),
    ChannelData(connect::ChannelData),
    ChannelExtendedData(connect::ChannelExtendedData),
    ChannelEof(connect::ChannelEof),
    ChannelClose(connect::ChannelClose),
    ChannelRequest(connect::ChannelRequest),
    ChannelSuccess(connect::ChannelSuccess),
    ChannelFailure(connect::ChannelFailure),
}