Skip to content

Redesign decoding. #85

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Redesign decoding. #85

wants to merge 3 commits into from

Conversation

partim
Copy link
Member

@partim partim commented Apr 16, 2025

This PR redesigns how decoding works. The principles are still the same, however, the PR changes how the encoding mode is handled – i.e., whether data is in BER, CER, or DER encoding. This has now become a type argument for all the types involved in decoding. This will allow dedicated implementations particularly for the string types, which are much simpler in DER.

Somewhat more importantly, the Source trait has changed. It now enforces that the number of bytes you advance over is equal to the number you have received from the source. This allows to make decoding nearly entirely free of panics, there are only a few instances where slice indexing and other panicking methods are necessary and they are now concentrated in very few places, essentially treating this like unsafe code.

The way this now works is that you request some data from the source which it will give to you as a new value called a fragment. You can ask the fragment for the slice of data it contains (which may still be shorter than what you requested) and, if you so desire, you can “consume” the fragment and advance the source past the data contained in the fragment. If you just drop the fragment, the source doesn’t advance.

Side note: I would love to be able to force users to drop the fragment by explicitly calling one of two methods, but that doesn’t seem to be possible in Rust right now. So there is still a risk that you forget to consume a fragment, but I suppose that’s what tests are for.

This PR is currently a draft as I didn’t manage to complete it before the Easter break. As such, it won’t even compile.

@partim partim marked this pull request as draft April 16, 2025 18:13
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.

1 participant