|
113 | 113 | //! type Error = der::Error; |
114 | 114 | //! |
115 | 115 | //! fn decode_value<R: Reader<'a>>(reader: &mut R, _header: Header) -> der::Result<Self> { |
116 | | -//! // The `der::Decoder::Decode` method can be used to decode any |
| 116 | +//! // The `der::Decode::decode` method can be used to decode any |
117 | 117 | //! // type which impls the `Decode` trait, which is impl'd for |
118 | 118 | //! // all of the ASN.1 built-in types in the `der` crate. |
119 | | -//! // |
120 | | -//! // Note that if your struct's fields don't contain an ASN.1 |
121 | | -//! // built-in type specifically, there are also helper methods |
122 | | -//! // for all of the built-in types supported by this library |
123 | | -//! // which can be used to select a specific type. |
124 | | -//! // |
125 | | -//! // For example, another way of decoding this particular field, |
126 | | -//! // which contains an ASN.1 `OBJECT IDENTIFIER`, is by calling |
127 | | -//! // `decoder.oid()`. Similar methods are defined for other |
128 | | -//! // ASN.1 built-in types. |
129 | 119 | //! let algorithm = reader.decode()?; |
130 | 120 | //! |
131 | 121 | //! // This field contains an ASN.1 `OPTIONAL` type. The `der` crate |
132 | 122 | //! // maps this directly to Rust's `Option` type and provides |
133 | 123 | //! // impls of the `Decode` and `Encode` traits for `Option`. |
134 | | -//! // To explicitly request an `OPTIONAL` type be decoded, use the |
135 | | -//! // `decoder.optional()` method. |
136 | 124 | //! let parameters = reader.decode()?; |
137 | 125 | //! |
138 | | -//! // The value returned from the provided `FnOnce` will be |
139 | | -//! // returned from the `any.sequence(...)` call above. |
| 126 | +//! // The value returned from this `decode_value` will be |
| 127 | +//! // returned from the `AlgorithmIdentifier::decode` call, unchanged. |
140 | 128 | //! // Note that the entire sequence body *MUST* be consumed |
141 | 129 | //! // or an error will be returned. |
142 | 130 | //! Ok(Self { algorithm, parameters }) |
|
171 | 159 | //! // which impls `Sequence` can be serialized by calling `Encode::to_der()`. |
172 | 160 | //! // |
173 | 161 | //! // If you would prefer to avoid allocations, you can create a byte array |
174 | | -//! // as backing storage instead, pass that to `der::Encoder::new`, and then |
175 | | -//! // encode the `parameters` value using `encoder.encode(parameters)`. |
| 162 | +//! // as backing storage instead, pass that to `der::SliceWriter::new`, and then |
| 163 | +//! // encode the `parameters` value using `writer.encode(parameters)`. |
176 | 164 | //! let der_encoded_parameters = parameters.to_der().unwrap(); |
177 | 165 | //! |
178 | 166 | //! let algorithm_identifier = AlgorithmIdentifier { |
179 | 167 | //! // OID for `id-ecPublicKey`, if you're curious |
180 | 168 | //! algorithm: "1.2.840.10045.2.1".parse().unwrap(), |
181 | 169 | //! |
182 | | -//! // `Any<'a>` impls `TryFrom<&'a [u8]>`, which parses the provided |
| 170 | +//! // `AnyRef<'a>` impls `TryFrom<&'a [u8]>`, which parses the provided |
183 | 171 | //! // slice as an ASN.1 DER-encoded message. |
184 | 172 | //! parameters: Some(der_encoded_parameters.as_slice().try_into().unwrap()) |
185 | 173 | //! }; |
|
188 | 176 | //! // allocating a `Vec<u8>` for storage. |
189 | 177 | //! // |
190 | 178 | //! // As mentioned earlier, if you don't have the `alloc` feature enabled you |
191 | | -//! // can create a fix-sized array instead, then call `Encoder::new` with a |
| 179 | +//! // can create a fix-sized array instead, then call `SliceWriter::new` with a |
192 | 180 | //! // reference to it, then encode the message using |
193 | | -//! // `encoder.encode(algorithm_identifier)`, then finally `encoder.finish()` |
| 181 | +//! // `writer.encode(algorithm_identifier)`, then finally `writer.finish()` |
194 | 182 | //! // to obtain a byte slice containing the encoded message. |
195 | 183 | //! let der_encoded_algorithm_identifier = algorithm_identifier.to_der().unwrap(); |
196 | 184 | //! |
197 | | -//! // Deserialize the `AlgorithmIdentifier` we just serialized from ASN.1 DER |
198 | | -//! // using `der::Decode::from_bytes`. |
| 185 | +//! // Deserialize the `AlgorithmIdentifier` bytes we just serialized from ASN.1 DER |
| 186 | +//! // using `der::Decode::from_der`. |
199 | 187 | //! let decoded_algorithm_identifier = AlgorithmIdentifier::from_der( |
200 | 188 | //! &der_encoded_algorithm_identifier |
201 | 189 | //! ).unwrap(); |
|
0 commit comments