-
Notifications
You must be signed in to change notification settings - Fork 1.7k
asn1: Add SIZE support to BIT STRING
#13999
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>
alex
left a comment
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.
@reaperhulk this uses bits as the length unit for a size annotation, WDYT?
On the on one hand, bits are stupid.
@facutuesca is that waht RFCs do when SIZE OF annotations are on BIT STRING?
| let bitstring: asn1::BitString<'_> = | ||
| asn1::BitString::new(val.get().data.as_bytes(py), val.get().padding_bits) | ||
| .ok_or(asn1::WriteError::AllocationError)?; | ||
| let n_bits = bitstring.as_bytes().len() * 8 - (bitstring.padding_bits() as usize); |
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 can use into() instead of as so its clear there's no truncation risk
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 (with usize::from())
tests/hazmat/asn1/test_api.py
Outdated
| "field invalid has a SIZE annotation, but SIZE " | ||
| "annotations are only supported for fields of types: " | ||
| "[SEQUENCE OF, BIT STRING]" |
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.
We can probably simplify this to just the first part of the error, so it doesn't need to be updated for every type
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
They should. From ITU-T X.680: |
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>

Similar to #13899, this PR extends the support for
SIZEtoBIT STRINGThe logic to check the size constraint is moved to its own function (
check_size_constraint()), so that it can be reused by all types that supportSIZEannotations.I've also moved the existing tests for
SIZEto their own class.Part of #12283