Skip to content

Commit

Permalink
Add more documentation for the ToDerSequence attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
chifflier committed Jan 13, 2025
1 parent 2171df0 commit df789ec
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions doc/DERIVE.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,35 @@ 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
Expand Down

0 comments on commit df789ec

Please sign in to comment.