Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.