From 02c0609e26056a8a12330803fc3776431145d692 Mon Sep 17 00:00:00 2001 From: Pierre Chifflier Date: Tue, 19 Nov 2024 14:13:34 +0100 Subject: [PATCH] Doc: reorder sections to match parsing/serialization --- doc/DERIVE.md | 58 +++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/doc/DERIVE.md b/doc/DERIVE.md index e3d37bc..ff87302 100644 --- a/doc/DERIVE.md +++ b/doc/DERIVE.md @@ -242,35 +242,6 @@ let ref_c = result.c.as_ref(); # Ok(()) }; ``` -# Serialization - -## BER/DER Sequence serialization - -To serialize a struct to a DER `SEQUENCE`, add the [`ToDerSequence`] derive attribute to an existing struct. -Serialization will be derived automatically for all fields, which must implement the [`ToDer`] trait. - -Some parser traits may be required, so also deriving parsers using [`DerSequence`] may be required. - -*Note*: serialization to BER is currently not available. In most cases, DER serialization should be enough. - - -For ex: - -```rust -# use asn1_rs::*; -#[derive(Debug, PartialEq, DerSequence, ToDerSequence)] -pub struct S { - a: u32, - b: u16, - c: u16, -} - -let s = S { a: 1, b: 2, c: 3 }; -let output = s.to_der_vec().expect("serialization failed"); -let (_rest, result) = S::from_ber(&output).expect("parsing failed"); -assert_eq!(s, result); -``` - # Advanced ## Custom errors @@ -340,6 +311,35 @@ pub struct T4 { *Note*: when deriving BER and DER parsers, errors paths are different (`TryFrom` returns the error type, while [`FromDer`] returns a [`ParseResult`]). Some code will be inserted by the `map_err` attribute to handle this transparently and keep the same function signature. +# Serialization + +## BER/DER Sequence serialization + +To serialize a struct to a DER `SEQUENCE`, add the [`ToDerSequence`] derive attribute to an existing struct. +Serialization will be derived automatically for all fields, which must implement the [`ToDer`] trait. + +Some parser traits may be required, so also deriving parsers using [`DerSequence`] may be required. + +*Note*: serialization to BER is currently not available. In most cases, DER serialization should be enough. + + +For ex: + +```rust +# use asn1_rs::*; +#[derive(Debug, PartialEq, DerSequence, ToDerSequence)] +pub struct S { + a: u32, + b: u16, + c: u16, +} + +let s = S { a: 1, b: 2, c: 3 }; +let output = s.to_der_vec().expect("serialization failed"); +let (_rest, result) = S::from_ber(&output).expect("parsing failed"); +assert_eq!(s, result); +``` + [`FromBer`]: crate::FromBer [`FromDer`]: crate::FromDer [`ToDer`]: crate::ToDer