Skip to content

Commit 98cabaa

Browse files
authored
Fix length calculation for explicit tags (#400)
When deriving `Choice`, the existing macros emit incorrect length calculation code when explicit tags are used. Signed-off-by: Nathaniel McCallum <nathaniel@profian.com>
1 parent b86d70e commit 98cabaa

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

der/derive/src/choice/variant.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,22 @@ impl ChoiceVariant {
6767
/// Derive a match arm for the impl body for `der::EncodeValue::value_len`.
6868
pub(super) fn to_value_len_tokens(&self) -> TokenStream {
6969
let ident = &self.ident;
70-
quote! {
71-
Self::#ident(variant) => variant.value_len(),
70+
71+
match self.attrs.context_specific {
72+
Some(tag_number) => {
73+
let tag_number = tag_number.to_tokens();
74+
let tag_mode = self.attrs.tag_mode.to_tokens();
75+
76+
quote! {
77+
Self::#ident(variant) => ::der::asn1::ContextSpecificRef {
78+
tag_number: #tag_number,
79+
tag_mode: #tag_mode,
80+
value: variant,
81+
}.value_len(),
82+
}
83+
}
84+
85+
_ => quote! { Self::#ident(variant) => variant.value_len(), },
7286
}
7387
}
7488

0 commit comments

Comments
 (0)