-
Notifications
You must be signed in to change notification settings - Fork 1.7k
asn1: Add support for IMPLICIT and EXPLICIT
#13735
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
Conversation
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
54a0c20 to
0a47aaa
Compare
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
30fc662 to
4b76630
Compare
src/cryptography/hazmat/asn1/asn1.py
Outdated
| 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) |
There was a problem hiding this comment.
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!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
src/cryptography/hazmat/asn1/asn1.py
Outdated
| value: U | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
| // 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified the comment to try to make it clearer:
// For optional types, annotations will always be associated to the `Optional` type
// i.e: `Annotated[Optional[T], annotation]`, as opposed to the inner `T` type.
// Therefore, when decoding the inner type `T` we must pass the annotation of the `Optional`|
@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. |
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
This PR adds support for
IMPLICITandEXPLICITfields to the ASN.1 API. The field types must be annotated withasn1.Implicit(tag=X)orasn1.Explicit(tag=Y):Part of #12283