Skip to content

der: clarify writer: add pretty-printing DER hex with comments #1892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

dishmaker
Copy link
Contributor

@dishmaker dishmaker commented Jun 23, 2025

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 -->

@dishmaker dishmaker changed the title der: clarify writer draft [WIP] der: clarify writer draft Jun 23, 2025
@dishmaker dishmaker changed the title [WIP] der: clarify writer draft der: clarify writer: add pretty-printing DER hex with comments Jul 11, 2025
@dishmaker dishmaker marked this pull request as ready for review July 11, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

der: add ClarifyWriter
1 participant