Skip to content

Commit dab4de4

Browse files
committed
ssh-encoding: flatten custom derive docs
Places them in the toplevel rustdoc, rather than their own (and otherwise empty) module
1 parent d0b974d commit dab4de4

2 files changed

Lines changed: 66 additions & 67 deletions

File tree

ssh-encoding/src/derive.rs

Lines changed: 0 additions & 65 deletions
This file was deleted.

ssh-encoding/src/lib.rs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,72 @@
135135
//!
136136
//! [RFC3066]: https://datatracker.ietf.org/doc/html/rfc3066
137137
//! [RFC4251 § 5]: https://datatracker.ietf.org/doc/html/rfc4251#section-5
138+
//!
139+
//! ## Deriving [`Encode`] and [`Decode`]
140+
//!
141+
//! The traits [`Encode`] and [`Decode`] can be derived for any struct or enum where all its fields
142+
//! implement [`Encode`] and [`Decode`].
143+
//!
144+
//! [`Encode`]: [crate::Encode]
145+
//! [`Decode`]: [crate::Decode]
146+
//! ### Example
147+
//!
148+
//! Here is an example of how you could define a handful of the SSH message types.
149+
#![cfg_attr(feature = "alloc", doc = "```")]
150+
#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
151+
//! use ssh_encoding::{Decode, Encode};
152+
//!
153+
//! #[derive(Debug, PartialEq, Encode, Decode)]
154+
//! #[repr(u8)]
155+
//! enum Message {
156+
//! Disconnect {
157+
//! reason_code: u32,
158+
//! description: String,
159+
//! language_tag: String,
160+
//! } = 1,
161+
//! EcdhInit {
162+
//! client_public_key: Vec<u8>,
163+
//! } = 30,
164+
//! EcdhReply {
165+
//! host_key: HostKey,
166+
//! server_public_key: Vec<u8>,
167+
//! #[ssh(length_prefixed)]
168+
//! host_signature: HostSignature,
169+
//! } = 31,
170+
//! }
171+
//!
172+
//! #[derive(Debug, PartialEq, Encode, Decode)]
173+
//! #[ssh(length_prefixed)]
174+
//! struct HostKey {
175+
//! key_type: String,
176+
//! ecdsa_curve_identifier: String,
177+
//! ecdsa_public_key: Vec<u8>,
178+
//! }
179+
//!
180+
//! #[derive(Debug, PartialEq, Encode, Decode)]
181+
//! struct HostSignature {
182+
//! signature_type: String,
183+
//! signature: Vec<u8>,
184+
//! }
185+
//!
186+
//! let message = Message::EcdhReply {
187+
//! host_key: HostKey {
188+
//! key_type: "ecdsa-sha2-nistp256".into(),
189+
//! ecdsa_curve_identifier: "nistp256".into(),
190+
//! ecdsa_public_key: vec![0x01, 0x02, 0x03],
191+
//! },
192+
//! server_public_key: vec![0x04, 0x05, 0x06],
193+
//! host_signature: HostSignature {
194+
//! signature_type: "ecdsa-sha2-nistp256".into(),
195+
//! signature: vec![0x07, 0x08, 0x09],
196+
//! },
197+
//! };
198+
//!
199+
//! let encoded = message.encode_vec().unwrap();
200+
//! assert_eq!(&encoded[..13], &[31, 0, 0, 0, 42, 0, 0, 0, 19, 101, 99, 100, 115]);
201+
//! let decoded = Message::decode(&mut &encoded[..]).unwrap();
202+
//! assert_eq!(message, decoded);
203+
//! ```
138204
139205
#[cfg(feature = "alloc")]
140206
#[macro_use]
@@ -180,5 +246,3 @@ pub use crate::pem::{DecodePem, EncodePem};
180246

181247
#[cfg(feature = "derive")]
182248
pub use ssh_derive::{Decode, Encode};
183-
#[cfg(feature = "derive")]
184-
pub mod derive;

0 commit comments

Comments
 (0)