-
Notifications
You must be signed in to change notification settings - Fork 1.7k
asn1: Add support for SIZE to SEQUENCE OF
#13899
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,19 @@ pub(crate) fn decode_annotated_type<'a>( | |
| let val = decode_annotated_type(py, d, inner_ann_type)?; | ||
| list.append(val)?; | ||
| } | ||
| if let Some(size) = &ann_type.annotation.get().size { | ||
| let list_len = list.len(); | ||
| let min = size.get().min; | ||
| let max = size.get().max.unwrap_or(usize::MAX); | ||
| if list_len < min || list_len > max { | ||
|
||
| return Err(CryptographyError::Py( | ||
| pyo3::exceptions::PyValueError::new_err(format!( | ||
| "SEQUENCE OF has size {0}, expected size in [{1}, {2}]", | ||
| list_len, min, max | ||
| )), | ||
| )); | ||
| } | ||
| } | ||
| Ok(list.into_any()) | ||
| })? | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,14 @@ impl asn1::Asn1Writable for AnnotatedTypeObject<'_> { | |
| value: e, | ||
| }) | ||
| .collect(); | ||
|
|
||
| if let Some(size) = &annotated_type.annotation.get().size { | ||
| let min = size.get().min; | ||
| let max = size.get().max.unwrap_or(usize::MAX); | ||
| if values.len() < min || values.len() > max { | ||
|
||
| return Err(asn1::WriteError::AllocationError); | ||
| } | ||
| } | ||
| write_value(writer, &asn1::SequenceOfWriter::new(values), encoding) | ||
| } | ||
| Type::Option(cls) => { | ||
|
|
||
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 guess if you want no min you just do min=0?
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.
yup