rasn
rasn copied to clipboard
OER/UPER/APER roundtrip fails with untagged sequence fields and optional types
OER/UPER/APER fails to encode Sequence with untagged and optional fields
use rasn::{prelude::*, uper};
#[derive(AsnType, Decode, Encode, Clone, Debug, PartialEq, Eq)]
pub struct SequenceOptionals {
// #[rasn(tag(explicit(0)))]
pub it: Integer,
// #[rasn(tag(explicit(1)))]
pub is: Option<OctetString>,
// #[rasn(tag(explicit(2)))]
pub late: Option<Integer>,
}
fn main() {
let test_seq = SequenceOptionals {
it: 42.into(),
is: None,
late: None,
};
let encoded = uper::encode(&test_seq).unwrap();
dbg!(&encoded);
let decoded: SequenceOptionals = uper::decode(&encoded).unwrap();
dbg!(&decoded);
assert_eq!(test_seq, decoded);
}
Output:
[testing/src/main.rs:19:5] &encoded = [
0,
]
thread 'main' panicked at testing/src/main.rs:20:61:
called `Result::unwrap()` on an `Err` value: DecodeError { kind: FieldError { name: "SequenceOptionals.it", nested: DecodeError { kind: Incomplete { needed: Size(2) }, codec: Uper } }, codec: Uper }
stack backtrace:
0: rust_begin_unwind
at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:652:5
1: core::panicking::panic_fmt
at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:72:14
2: core::result::unwrap_failed
at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/result.rs:1679:5
3: core::result::Result<T,E>::unwrap
at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/result.rs:1102:23
4: testing::main
at ./src/main.rs:20:38
5: core::ops::function::FnOnce::call_once
at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace