formats icon indicating copy to clipboard operation
formats copied to clipboard

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

Open dishmaker opened this issue 11 months ago • 5 comments

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

Actually, most functions don't return the position - example: https://github.com/RustCrypto/formats/blob/9813667a89ff9cd91f99784ab13e9ae434fffdc2/der/src/datetime.rs#L79-L83

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

dishmaker avatar Mar 14 '25 10:03 dishmaker