RustCrypto / RustCrypto/formats

der: Error stacktraces

Open
#1,951 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
338
Forks
188
Avg merge
4d 6h
Merged PRs (30d)
15

Description

https://github.com/RustCrypto/formats/blob/bd840638835fcf66c4ffc3baed6d7c3b727c4ef3/der/src/decode.rs#L26-L28

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.

[^1]: I mentioned that some time ago https://github.com/RustCrypto/formats/issues/1053#issuecomment-2393628486

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read der/src/decode.rs at lines 26-28 and the linked discussion in issue #1053. Examine how the Reader trait currently handles errors and how an associated Error could support the annotated field stacktrace described here. Done means the proposed error design is implemented and supports the PKCS#15-style trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.