RustCrypto / RustCrypto/formats

der: Move `error.position` from Error to Reader

Open
#1,719 5 comments 0 reactions 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

Currently, it is annoying to track error.position in every function returning der::Error.

From another issue:

Attempting to even construct der::Error was confusing [...] It is also unclear to me whether the position that this method uses will be correct [...]

  • #1492

https://github.com/RustCrypto/formats/blob/9813667a89ff9cd91f99784ab13e9ae434fffdc2/der/src/error.rs#L23-L24

What I suggest is something like serde + quick-xml:

let mut reader = SliceReader::new(EXAMPLE_MSG).unwrap();
let err = SomeStruct::decode(&mut reader);
assert!(err.is_err());

assert_eq!(reader.error_position(), 28);

https://docs.rs/quick-xml/latest/quick_xml/de/struct.Deserializer.html#method.get_ref

https://github.com/tafia/quick-xml/pull/743

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

Start with der/src/error.rs and the SliceReader API described in the issue, then compare the referenced serde and quick-xml approach. Define how decoding errors expose their position through the reader, including the example expecting position 28. Done means the proposed reader-based error-position behavior is implemented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.