-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redesign error handling in the decode module (#65)
This commit changes the entire way that errors are handled while decoding. Sources now provide errors related to failing to get more data when more is requested via the associated Source::Error type. This has been renamed from Source::Err for consistency with other such associated types. A new type ContentError is introduced for errors where incorrectly encoded data is encountered, i.e., actual encoding errors or data that isn't following the ASN.1 definition or informal profiles. This type wraps an error message that currently can be either a static str or a boxed Display trait object but can be extended if necessary later. Since both source and content errors can happen during decoding, the compound type DecodeError wraps both these types. For content errors it also stores where in the source the error happened to facilitate debugging. Currently, this type only allows displaying the error. It can be extended if additional access to the internally stored error is necessary. The various content decoding methods now return this DecodeError. In order to implement all these changes, the Source trait had to be adjusted. First, it needs to be able to provide the current position. This meant that it couldn’t be implemented on Bytes and &[u8] directly anymore. Therefore, the new trait IntoSource allows to convert a type into its Source implementation. Finally, the trait's methods got cleaned up a bit. Specifically, Source::advance now only allows advancing as far as the length most recently returned by Source::request which also means it cannot fail anymore but needs to panic if the length is too large. This consistent to how Source::bytes already behaves.
- Loading branch information
Showing
18 changed files
with
1,369 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.