Closed FrancisRussell closed 7 months ago
Ah, by adding automatic_tags
to Key
(I guess the omission might be part of the problem), I get instead:
thread 'main' panicked at src/main.rs:27:61:
failed to decode: DecodeError { kind: FieldError { name: "ConnectData.t124_identifier_key", nested: DecodeError { kind: Parser { msg: "Invalid length fragment" }, codec: Aper, backtrace: Backtrace( 0: rasn::error::decode::DecodeError::from_kind
1: rasn::per::de::Decoder::decode_length
2: rasn::per::de::Decoder::decode_octets
3: <rasn::per::de::Decoder as rasn::de::Decoder>::decode_object_identifier
4: <testcase::Key as rasn::types::DecodeChoice>::from_tag
5: <rasn::per::de::Decoder as rasn::de::Decoder>::decode_choice
6: <rasn::per::de::Decoder as rasn::de::Decoder>::decode_sequence
7: rasn::per::decode
8: testcase::main
9: std::sys_common::backtrace::__rust_begin_short_backtrace
10: std::rt::lang_start::{{closure}}
Thank you for your issue! Can you check if you're using the latest version there was a fix for APER in the last version.
This was produced with rasn 0.12.0 and rustc 1.75.0-nightly (aa1a71e9e 2023-10-26).
Seems like it happens in older versions too, and new changes did not introduce it.
Uper roundtrip fails too.
There are two issues, at first the tag value as parameter is incorrect here:
https://github.com/XAMPPRocky/rasn/blob/cdc4e24458ec727c7a2b029cc94ff961eca1075d/src/per/enc.rs#L838
Should be Tag::OBJECT_IDENTIFIER
. This fixes the issue for UPER
.
Secondly, alignment is incorrectly parsed on APER (maybe when parsing unknown length), but I could not figure out the correct way yet. This would require reading standard quite a bit.
Since I feel context/a use-case is helpful, I came across this because I wanted to replicate the output of this function using rasn, though since I was unclear if I should be able to expect bit identical output, I wanted to get rasn to parse the existing output as well for sanity checking.
Actually figured it out, it is similar problem that we just fixed.
When encoding choice, also the size of the choice index encoding should be noted when adjusting the alignment when encoding the inner value.
With current implementation this might be difficult to solve, since the inner value is encoded at first, so that we get the tag to identify the index for the correct variant.
But we should know it before we encode the inner value, so that we know the correct size to note...
Somehow we should know the selected variant before encoding the inner parts, is there any easy way?
Somehow we should know the selected variant before encoding the inner parts, is there any easy way?
I don't think there's a way to know before right now but it probably wouldn't be fitfully to add that to the trait implementation.
@FrancisRussell The fix was just released with 0.12.1, so you should be able to keep going now :) If you have any questions or problems feel free to create an issue or discussion on the GitHub.
Thanks for the quick response! One thing I did note is that bumping rasn didn't cause rasn-derive to be bumped, which caused a compilation error until I did a cargo update
.
I've been trying to use retrofit
rasn
into a codebase which requires aligned PER messages. Though I'm somewhat limited with my understanding of ASN.1/PER, I managed to produce the following test case which to my understanding should just be an identity operation but currently fails, though potentially I am just usingrasn
incorrectly:When executed, I get the following failure (backtrace truncated):