-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when encoding/decoding non-explicitely tagged vecs #165
Comments
Debugging this a bit more (couldn't help myself!) I modded fn decode_sequence_of<D: Decode>(
&mut self,
tag: Tag,
_: Constraints,
) -> Result<Vec<D>, Self::Error> {
self.parse_constructed_contents(tag, true, |decoder| {
let mut items = Vec::new();
match D::decode(decoder) {
Ok(item) => items.push(item),
Err(e) => panic!("SEQ: {:?} {} -- {:?}", tag, e, decoder.input),
}
//while let Ok(item) = D::decode(decoder) {
//items.push(item);
//}
Ok(items)
})
} (Obviously this is just for debugging, I have no intention of throwing in panics everywhere). This spits out:
That input |
Thank you for your issue!
Please do :) |
I think I'm about as far as I can get...any guidance would be appreciated =]. Seems the problem lies in if rasn::TagTree::tag_contains(& tag, &[rasn::TagTree::Leaf(rasn :: Tag :: new(rasn :: types :: Class :: Context, 0))]) {
return {
let decode_fn = | decoder : & mut D | -> core :: result :: Result < _,D :: Error > {
#[derive(rasn :: AsnType, rasn :: Decode, rasn :: Encode)] struct InnerMultisigPolicySignature { #[rasn(tag(0))] key : String, } ;
let inner = < InnerMultisigPolicySignature > :: decode_with_tag(decoder, rasn :: Tag :: new(rasn :: types :: Class :: Context, 0)) ? ;
Ok(Self :: Key { key : inner.key })
} ;
(decode_fn) (decoder)
}
}
Err(rasn :: de :: Error :: no_valid_choice("MultisigPolicySignature")) The tag value is coming through as I also managed to reduce the test case even further, eliminating the outer container and just using #[test]
fn decode_implicit_tagged_vec_choice() {
#[derive(Debug, Clone, AsnType, Encode, Decode)]
#[rasn(choice)]
pub enum MultisigPolicySignature {
#[rasn(tag(0))]
Key {
#[rasn(tag(0))]
key: String,
},
}
let transactions2 = vec![
MultisigPolicySignature::Key {
key: String::from("key1"),
},
];
let ser2 = rasn::der::encode(&transactions2).unwrap();
let transactions2_2: Vec<MultisigPolicySignature> = rasn::der::decode(&ser2[..]).unwrap();
assert_eq!(transactions2_2.len(), 1);
} Thanks! |
Using rasn v0.9.5. I recently decided to switch the serialization on the project I'm working on from
#[rasn(tag(explicit(N)))]
to#[rasn(tag(N))
and I'm now having an issue with deserialization. I reduced my case down to two examples:This test gives the output:
Notice the
transactions []
...it deserializes the outer vec as empty. This serializes to https://lapo.it/asn1js/#MA2gCzAJoAcwBYADa2V5 which I think is correct, so the issue might be in decoding.This can be reduced even more:
Output:
This serializes to https://lapo.it/asn1js/#MAmgBzAFgANrZXk which again looks correct to me.
Interestingly, this can be "fixed" in both examples by updating
MultisigPolicySignature
to either remove the tag specification or make it explicit:I'm guessing this has something to do with abiguity when dealing with SEQUENCE vs SEQUENCE OF, but not sure if there's an easy fix. I can try to pick at it and open a PR, but I am definitely moving out of my comfort space, so some guidance would be appreciated. Thank you!
The text was updated successfully, but these errors were encountered: