-
Notifications
You must be signed in to change notification settings - Fork 170
Description
Lines 26 to 28 in bd84063
| pub trait Decode<'a>: Sized + 'a { | |
| /// Type returned in the event of a decoding error. | |
| type Error: From<Error> + 'static; |
I think associated Error would be useful inside Reader trait. 1
Motivation
To prove usefulness, suppose we want to return annotated errors with .field stacktrace.
Example of such stacktrace from invalid PKCS#15:
Error: from_der_type CIOChoice
Caused by:
0: .choice AuthObjects
0: .choice Objects
0: [0]
0: (AuthenticationObjectChoice)
0: .choice Pwd
0: .type_attributes
0: .pwd_reference
1: incorrect length for INTEGER at DER byte 57
Because some ASN.1 DER definitions are really complicated, such error stacktrace is very helpful.
Field names in returned error are possible, because derive Sequence may generate .wrap_err_field("fieldname") calls.
Why not use Decode::Error?
Such errors may originate from x509-cert, as it is a part of PKCS#15:
CertificateChoice ::= CHOICE {
x509Certificate CertificateObject {X509CertificateAttributes},
-- ...
spkiCertificate [1] CertificateObject {SPKICertificateAttributes},Moreover, existing crates using der will benefit from such Decode error stacktrace feature, similar to my clarify Encode feature.
Footnotes
-
I mentioned that some time ago https://github.com/RustCrypto/formats/issues/1053#issuecomment-2393628486 ↩