|
23 | 23 |
|
24 | 24 | //! ## Conventions used in this crate |
25 | 25 | //! |
26 | | -//! This crate uses the following type labels which are described in |
27 | | -//! [RFC4251 § 5]: |
| 26 | +//! This crate uses the following type labels which are described in [RFC4251 § 5], and also lists |
| 27 | +//! types with [`Decode`]/[`Encode`] trait impls which are compatible with this format: |
28 | 28 | //! |
29 | | -//! #### `byte`, `byte[n]`, `byte[]` |
30 | | -//! |
31 | | -//! A byte represents an arbitrary 8-bit value (octet). |
| 29 | +//! ### `byte`, `byte[n]`, `byte[]`: arbitrary 8-bit value (octet) or sequence thereof |
| 30 | +//! #### [`Decode`]/[`Encode`] trait impls: |
| 31 | +//! - `byte`: `u8` |
| 32 | +//! - `byte[n]`: `[u8; N]` |
| 33 | +//! - `byte[]`: `Vec<u8>`, `bytes::Bytes` (requires `bytes` crate feature) |
32 | 34 | //! |
33 | 35 | //! Fixed length data is sometimes represented as an array of bytes, written |
34 | 36 | //! `byte[n]` where `n` is the number of bytes in the array. |
|
37 | 39 | //! length bytestrings (similar to `string`, see below) but identifies data |
38 | 40 | //! which is inherently binary in nature, as opposed to text. |
39 | 41 | //! |
40 | | -//! #### `boolean` |
41 | | -//! |
42 | | -//! A boolean value is stored as a single byte. |
| 42 | +//! |
| 43 | +//! ### `boolean`: boolean value stored as a single byte |
| 44 | +//! #### [`Decode`]/[`Encode`] trait impls: `bool` |
43 | 45 | //! |
44 | 46 | //! The value 0 represents FALSE, and the value 1 represents TRUE. All non-zero |
45 | 47 | //! values MUST be interpreted as TRUE; however, applications MUST NOT |
46 | 48 | //! store values other than 0 and 1. |
47 | | -//! |
48 | | -//! #### `uint32` |
49 | | -//! |
50 | | -//! Represents a 32-bit unsigned integer. |
| 49 | +//! |
| 50 | +//! ### `uint32`: 32-bit unsigned integer |
| 51 | +//! #### [`Decode`]/[`Encode`] trait impls: `u32`, `usize` |
51 | 52 | //! |
52 | 53 | //! Stored as four bytes in the order of decreasing significance (network byte order). |
53 | 54 | //! |
54 | 55 | //! For example: the value `699921578` (`0x29b7f4aa`) is stored as |
55 | 56 | //! `29 b7 f4 aa`. |
56 | 57 | //! |
57 | | -//! #### `uint64` |
58 | | -//! |
59 | | -//! Represents a 64-bit unsigned integer. |
| 58 | +//! ### `uint64`: 64-bit unsigned integer |
| 59 | +//! #### [`Decode`]/[`Encode`] trait impls: `u64` |
60 | 60 | //! |
61 | 61 | //! Stored as eight bytes in the order of decreasing significance (network byte order). |
62 | 62 | //! |
63 | | -//! #### `string` |
| 63 | +//! ### `string`: arbitrary length *binary* string |
| 64 | +//! #### [`Decode`]/[`Encode`] trait impls: `Vec<u8>`, `String`, `bytes::Bytes` (requires `bytes` crate feature) |
64 | 65 | //! |
65 | | -//! Arbitrary length binary string. |
| 66 | +//! *NOTE: `string` is effectively equivalent to `byte[]`, however the latter is not defined in |
| 67 | +//! [RFC4251] and so trait impls in this crate for bytestring types like `[u8; N]` and `Vec<u8>` |
| 68 | +//! are described as being impls of `string`*. |
66 | 69 | //! |
67 | 70 | //! Strings are allowed to contain arbitrary binary data, including null characters and 8-bit |
68 | 71 | //! characters. |
69 | 72 | //! |
70 | | -//! They are stored as a `uint32` containing its length |
71 | | -//! (number of bytes that follow) and zero (= empty string) or more |
72 | | -//! bytes that are the value of the string. Terminating null |
| 73 | +//! They are stored as a `uint32` containing its length (number of bytes that follow) and |
| 74 | +//! zero (= empty string) or more bytes that are the value of the string. Terminating null |
73 | 75 | //! characters are not used. |
74 | 76 | //! |
75 | | -//! Strings are also used to store text. In that case, US-ASCII is |
76 | | -//! used for internal names, and ISO-10646 UTF-8 for text that might |
77 | | -//! be displayed to the user. The terminating null character SHOULD |
78 | | -//! NOT normally be stored in the string. For example: the US-ASCII |
79 | | -//! string "testing" is represented as `00 00 00 07 t e s t i n g`. The |
80 | | -//! UTF-8 mapping does not alter the encoding of US-ASCII characters. |
| 77 | +//! Strings are also used to store text. In that case, US-ASCII is used for internal names, and |
| 78 | +//! ISO-10646 UTF-8 for text that might be displayed to the user. |
| 79 | +//! |
| 80 | +//! The terminating null character SHOULD NOT normally be stored in the string. |
81 | 81 | //! |
82 | | -//! #### `mpint` |
| 82 | +//! For example: the US-ASCII string "testing" is represented as `00 00 00 07 t e s t i n g`. |
| 83 | +//! The UTF-8 mapping does not alter the encoding of US-ASCII characters. |
83 | 84 | //! |
84 | | -//! Represents multiple precision integers in two's complement format, |
85 | | -//! stored as a string, 8 bits per byte, MSB first. |
| 85 | +//! ### `mpint`: multiple precision integers in two's complement format |
| 86 | +//! |
| 87 | +//! Stored as a byte string, 8 bits per byte, MSB first (a.k.a. big endian). |
86 | 88 | //! |
87 | 89 | //! Negative numbers have the value 1 as the most significant bit of the first byte of |
88 | 90 | //! the data partition. If the most significant bit would be set for |
|
94 | 96 | //! By convention, a number that is used in modular computations in |
95 | 97 | //! `Z_n` SHOULD be represented in the range `0 <= x < n`. |
96 | 98 | //! |
97 | | -//! Examples: |
| 99 | +//! #### Examples: |
98 | 100 | //! |
99 | 101 | //! value (hex) | representation (hex) |
100 | 102 | //! -------------------|--------------------- |
|
104 | 106 | //! `-1234` | `00 00 00 02 ed cc` |
105 | 107 | //! `-deadbeef` | `00 00 00 05 ff 21 52 41 11` |
106 | 108 | //! |
107 | | -//! #### `name-list` |
108 | | -//! |
109 | | -//! A string containing a comma-separated list of names. |
| 109 | +//! ### `name-list`: string containing a comma-separated list of names |
| 110 | +//! #### [`Decode`]/[`Encode`] trait impls: `Vec<String>` |
110 | 111 | //! |
111 | 112 | //! A `name-list` is represented as a `uint32` containing its length |
112 | 113 | //! (number of bytes that follow) followed by a comma-separated list of zero or more |
|
125 | 126 | //! Terminating null characters MUST NOT be used, neither |
126 | 127 | //! for the individual names, nor for the list as a whole. |
127 | 128 | //! |
128 | | -//! Examples: |
| 129 | +//! #### Examples: |
129 | 130 | //! |
130 | 131 | //! value | representation (hex) |
131 | 132 | //! ---------------------------|--------------------- |
|
134 | 135 | //! `("zlib,none")` | `00 00 00 09 7a 6c 69 62 2c 6e 6f 6e 65` |
135 | 136 | //! |
136 | 137 | //! [RFC3066]: https://datatracker.ietf.org/doc/html/rfc3066 |
| 138 | +//! [RFC4251]: https://datatracker.ietf.org/doc/html/rfc4251 |
137 | 139 | //! [RFC4251 § 5]: https://datatracker.ietf.org/doc/html/rfc4251#section-5 |
138 | 140 | //! |
139 | 141 | //! ## Deriving [`Decode`] and [`Encode`] |
@@ -247,3 +249,6 @@ pub use crate::pem::{DecodePem, EncodePem}; |
247 | 249 |
|
248 | 250 | #[cfg(feature = "derive")] |
249 | 251 | pub use ssh_derive::{Decode, Encode}; |
| 252 | + |
| 253 | +#[cfg(all(doc, feature = "alloc"))] |
| 254 | +use alloc::vec::Vec; |
0 commit comments