|
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.
formats/der/src/decode.rs
Lines 26 to 28 in bd84063
I think associated
Errorwould be useful insideReadertrait. 1Motivation
To prove usefulness, suppose we want to return annotated errors with
.fieldstacktrace.Example of such stacktrace from invalid PKCS#15:
Because some ASN.1 DER definitions are really complicated, such error stacktrace is very helpful.
Field names in returned error are possible, because derive
Sequencemay 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:Moreover, existing crates using
derwill benefit from suchDecodeerror stacktrace feature, similar to myclarifyEncodefeature.Footnotes
I mentioned that some time ago https://github.com/RustCrypto/formats/issues/1053#issuecomment-2393628486 ↩