RustCrypto / formats

Cryptography-related format encoders/decoders: DER, PEM, PKCS, PKIX
239 stars 127 forks source link

der: Document (or improve) `der::Decode` trait impl error handling #1492

Open str4d opened 3 weeks ago

str4d commented 3 weeks ago

As part of #1491, I needed to implement decoding for the custom extension I wrote for #1490. I encounted several problems:

tarcieri commented 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.

tarcieri commented 1 week ago

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

tarcieri commented 1 week ago

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.