Skip to content

Conversation

@facutuesca
Copy link
Contributor

This PR adds support for IMPLICIT and EXPLICIT fields to the ASN.1 API. The field types must be annotated with asn1.Implicit(tag=X) or asn1.Explicit(tag=Y):

@asn1.sequence
class Example
  a: Annotated[typing.Union[int, None], asn1.Implicit(0)]
  b: Annotated[typing.Union[int, None], asn1.Implicit(1)]

Part of #12283

@facutuesca facutuesca force-pushed the ft/asn1-implicit-explicit branch from 54a0c20 to 0a47aaa Compare October 24, 2025 21:28
@facutuesca facutuesca force-pushed the ft/asn1-implicit-explicit branch from 30fc662 to 4b76630 Compare October 24, 2025 23:12
@facutuesca facutuesca marked this pull request as ready for review October 24, 2025 23:26
Comment on lines +63 to +70
encoding = None
for raw_annotation in metadata:
if isinstance(raw_annotation, Default):
default = raw_annotation.value
elif isinstance(raw_annotation, Explicit):
encoding = declarative_asn1.Encoding.Explicit(raw_annotation.tag)
elif isinstance(raw_annotation, Implicit):
encoding = declarative_asn1.Encoding.Implicit(raw_annotation.tag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to prohibit duplicates (I guess this is true of defaults as well!)

value: U


@dataclasses.dataclass(frozen=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these, or could we expose Encoding.Explicit and Encoding.Implicit as these types?

Comment on lines +158 to +159
// Since for optional types the annotations are enforced to be associated with the Option
// (instead of the inner type), when decoding the inner type we add the annotations of the Option
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow.

Comment on lines +300 to +301
Encoding::Implicit(n) => asn1::implicit_tag(*n, inner_tag),
Encoding::Explicit(n) => asn1::explicit_tag(*n),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are currenyly #[doc(hidden)] and thus not part of the stable API. We need to either change that, or represent these a different way.

@reaperhulk
Copy link
Member

@facutuesca Just a friendly ping since we're probably only a few weeks away from 47.0.0. If we need to slip to 48 that's fine of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants