formats
formats copied to clipboard
der: clarify writer: add pretty-printing DER hex with comments
Resolves #1835
I made sure it does not add any runtime overhead, even when using the "clarify" feature.
This PR is initial support.
In future I'd like to add Sequence field names in comments, as well as OID pretty-printing.
Examples
Rust:
hex!(
"30 51" // tag: SEQUENCE len: 81 type: OneAsymmetricKey
"02 01" // tag: INTEGER type: u8
"01"
"30 0D" // tag: SEQUENCE len: 13 type: AlgorithmIdentifier
"06 07" // tag: OBJECT IDENTIFIER type: ObjectIdentifier
"2A 03 04 05 06 07 08"
"A0 02" // tag: CONTEXT-SPECIFIC [0] (constructed) type: AnyRef
"AA BB"
"04 1C" // tag: OCTET STRING len: 28 type: OctetStringRef
"00 11 22 33 00 11 22 33 00 11 22 33 00 11 22 33
00 11 22 33 00 11 22 33 00 11 22 33"
"" // end: OctetStringRef
"A1 1F" // tag: CONTEXT-SPECIFIC [1] (constructed) len: 31 type: ContextSpecificRef<BitStringRef>
"03 1D" // tag: BIT STRING len: 29 type: BitStringRef
"00"
"44 55 66 77 44 55 66 77 44 55 66 77 44 55 66 77
44 55 66 77 44 55 66 77 44 55 66 77"
"" // end: BitStringRef
"" // end: ContextSpecificRef<BitStringRef>
"" // end: OneAsymmetricKey
);
XML:
30 51 <!-- tag: SEQUENCE len: 81 type: OneAsymmetricKey -->
02 01 <!-- tag: INTEGER type: u8 -->
01
30 0D <!-- tag: SEQUENCE len: 13 type: AlgorithmIdentifier -->
06 07 <!-- tag: OBJECT IDENTIFIER type: ObjectIdentifier -->
2A 03 04 05 06 07 08
A0 02 <!-- tag: CONTEXT-SPECIFIC [0] (constructed) type: AnyRef -->
AA BB
04 1C <!-- tag: OCTET STRING len: 28 type: OctetStringRef -->
00 11 22 33 00 11 22 33 00 11 22 33 00 11 22 33
00 11 22 33 00 11 22 33 00 11 22 33
<!-- end: OctetStringRef -->
A1 1F <!-- tag: CONTEXT-SPECIFIC [1] (constructed) len: 31 type: ContextSpecificRef<BitStringRef> -->
03 1D <!-- tag: BIT STRING len: 29 type: BitStringRef -->
00
44 55 66 77 44 55 66 77 44 55 66 77 44 55 66 77
44 55 66 77 44 55 66 77 44 55 66 77
<!-- end: BitStringRef -->
<!-- end: ContextSpecificRef<BitStringRef> -->
<!-- end: OneAsymmetricKey -->
rusticata/asn1-rs pretty-printer: https://github.com/rusticata/asn1-rs/issues/25