Open str4d opened 3 weeks ago
The Decode
trait (now) has an associated Error
type: https://docs.rs/der/0.8.0-rc.0/der/trait.Decode.html#associatedtype.Error
If der::Error
is too limited for a given use case it would be good to switch to a dedicated error type.
@str4d was this issue primarily motivated by https://github.com/iqlusioninc/yubikey.rs/issues/580 or something else?
The Decode
trait now has an associated Error
type, which would be my suggested way of handling any errors which aren't a direct result of DER decoding (i.e. define a custom error type and do whatever you want error handling-wise).
That's a new addition which may not be properly reflected in the documentation yet.
Regarding speculative decoding and computing the exact position for that, you can use the peek functionality to look ahead without actually modifying the cursor in the buffer, if that's helpful.
Otherwise, Error::new
can be used to construct a new der::Error
with whatever computed position you'd like.
As part of #1491, I needed to implement decoding for the custom extension I wrote for #1490. I encounted several problems:
der::Decode::decode
returnsder::Result
, and AFAICT there is no way to return a type-specific error code inder::Error
. None of the existingder::ErrorKind
s appear to be usable for this (or at least, I cannot figure out whether returning one of them will cause unexpected side-effects).der::Error
was confusing, until I stumbled uponder::Reader::error
. Theder::Decode
trait (as well asder::Error
) should document that errors should be created usingdecoder.error()
(or whatever new method is added for defining user errors). It is also unclear to me whether the position that this method uses will be correct, if I am doing post-read validation (in which case I think the position will be one after the actual problem position).