Skip to content

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

Open
@str4d

Description

@str4d

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

  • I need to validate the data present inside the extension. In particular, for the YubiKey PIV attestation policy extension I need to verify that the PIN and touch policies are one of the expected values. However, der::Decode::decode returns der::Result, and AFAICT there is no way to return a type-specific error code in der::Error. None of the existing der::ErrorKinds appear to be usable for this (or at least, I cannot figure out whether returning one of them will cause unexpected side-effects).
  • Attempting to even construct der::Error was confusing, until I stumbled upon der::Reader::error. The der::Decode trait (as well as der::Error) should document that errors should be created using decoder.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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions