From 504d4f7cd9cac1c4b0ebd47e7c492af46fb025ec Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 19 Apr 2025 08:55:37 -0600 Subject: [PATCH] ssh-encoding: flatten custom derive docs Places them in the toplevel rustdoc, rather than their own (and otherwise empty) module --- ssh-encoding/src/derive.rs | 65 ----------------------------------- ssh-encoding/src/lib.rs | 69 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 67 deletions(-) delete mode 100644 ssh-encoding/src/derive.rs diff --git a/ssh-encoding/src/derive.rs b/ssh-encoding/src/derive.rs deleted file mode 100644 index 78aa319..0000000 --- a/ssh-encoding/src/derive.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! # Deriving [`Encode`] and [`Decode`] -//! -//! The traits [`Encode`] and [`Decode`] can be derived for any struct or enum where all its fields -//! implement [`Encode`] and [`Decode`]. -//! -//! [`Encode`]: [crate::Encode] -//! [`Decode`]: [crate::Decode] -//! ## Example -//! -//! Here is an example of how you could define a handful of the SSH message types. -#![cfg_attr(feature = "alloc", doc = "```")] -#![cfg_attr(not(feature = "alloc"), doc = "```ignore")] -//! use ssh_encoding::{Decode, Encode}; -//! -//! #[derive(Debug, PartialEq, Encode, Decode)] -//! #[repr(u8)] -//! enum Message { -//! Disconnect { -//! reason_code: u32, -//! description: String, -//! language_tag: String, -//! } = 1, -//! EcdhInit { -//! client_public_key: Vec, -//! } = 30, -//! EcdhReply { -//! host_key: HostKey, -//! server_public_key: Vec, -//! #[ssh(length_prefixed)] -//! host_signature: HostSignature, -//! } = 31, -//! } -//! -//! #[derive(Debug, PartialEq, Encode, Decode)] -//! #[ssh(length_prefixed)] -//! struct HostKey { -//! key_type: String, -//! ecdsa_curve_identifier: String, -//! ecdsa_public_key: Vec, -//! } -//! -//! #[derive(Debug, PartialEq, Encode, Decode)] -//! struct HostSignature { -//! signature_type: String, -//! signature: Vec, -//! } -//! -//! let message = Message::EcdhReply { -//! host_key: HostKey { -//! key_type: "ecdsa-sha2-nistp256".into(), -//! ecdsa_curve_identifier: "nistp256".into(), -//! ecdsa_public_key: vec![0x01, 0x02, 0x03], -//! }, -//! server_public_key: vec![0x04, 0x05, 0x06], -//! host_signature: HostSignature { -//! signature_type: "ecdsa-sha2-nistp256".into(), -//! signature: vec![0x07, 0x08, 0x09], -//! }, -//! }; -//! -//! let encoded = message.encode_vec().unwrap(); -//! assert_eq!(&encoded[..13], &[31, 0, 0, 0, 42, 0, 0, 0, 19, 101, 99, 100, 115]); -//! let decoded = Message::decode(&mut &encoded[..]).unwrap(); -//! assert_eq!(message, decoded); -//! ``` diff --git a/ssh-encoding/src/lib.rs b/ssh-encoding/src/lib.rs index 5606f88..245c336 100644 --- a/ssh-encoding/src/lib.rs +++ b/ssh-encoding/src/lib.rs @@ -135,6 +135,73 @@ //! //! [RFC3066]: https://datatracker.ietf.org/doc/html/rfc3066 //! [RFC4251 ยง 5]: https://datatracker.ietf.org/doc/html/rfc4251#section-5 +//! +//! ## Deriving [`Decode`] and [`Encode`] +//! +//! The traits [`Decode`] and [`Encode`] can be derived for any struct or enum where all its fields +//! implement [`Decode`] and [`Encode`] respectively. +//! +//! To use this functionality, enable the `derive` crate feature for `ssh-encoding`. +//! +//! ### Example +//! +//! Here is an example of how you could define a handful of the SSH message types: +//! +#![cfg_attr(all(feature = "alloc", feature = "derive"), doc = "```")] +#![cfg_attr(not(all(feature = "alloc", feature = "derive")), doc = "```ignore")] +//! use ssh_encoding::{Decode, Encode}; +//! +//! #[derive(Debug, PartialEq, Encode, Decode)] +//! #[repr(u8)] +//! enum Message { +//! Disconnect { +//! reason_code: u32, +//! description: String, +//! language_tag: String, +//! } = 1, +//! EcdhInit { +//! client_public_key: Vec, +//! } = 30, +//! EcdhReply { +//! host_key: HostKey, +//! server_public_key: Vec, +//! #[ssh(length_prefixed)] +//! host_signature: HostSignature, +//! } = 31, +//! } +//! +//! #[derive(Debug, PartialEq, Encode, Decode)] +//! #[ssh(length_prefixed)] +//! struct HostKey { +//! key_type: String, +//! ecdsa_curve_identifier: String, +//! ecdsa_public_key: Vec, +//! } +//! +//! #[derive(Debug, PartialEq, Encode, Decode)] +//! struct HostSignature { +//! signature_type: String, +//! signature: Vec, +//! } +//! +//! let message = Message::EcdhReply { +//! host_key: HostKey { +//! key_type: "ecdsa-sha2-nistp256".into(), +//! ecdsa_curve_identifier: "nistp256".into(), +//! ecdsa_public_key: vec![0x01, 0x02, 0x03], +//! }, +//! server_public_key: vec![0x04, 0x05, 0x06], +//! host_signature: HostSignature { +//! signature_type: "ecdsa-sha2-nistp256".into(), +//! signature: vec![0x07, 0x08, 0x09], +//! }, +//! }; +//! +//! let encoded = message.encode_vec().unwrap(); +//! assert_eq!(&encoded[..13], &[31, 0, 0, 0, 42, 0, 0, 0, 19, 101, 99, 100, 115]); +//! let decoded = Message::decode(&mut &encoded[..]).unwrap(); +//! assert_eq!(message, decoded); +//! ``` #[cfg(feature = "alloc")] #[macro_use] @@ -180,5 +247,3 @@ pub use crate::pem::{DecodePem, EncodePem}; #[cfg(feature = "derive")] pub use ssh_derive::{Decode, Encode}; -#[cfg(feature = "derive")] -pub mod derive;