diff --git a/crates/asn1-parser/README.md b/crates/asn1-parser/README.md index 3a55388..6ec21cc 100644 --- a/crates/asn1-parser/README.md +++ b/crates/asn1-parser/README.md @@ -47,7 +47,7 @@ This `asn1` parser is aimed to parse input bytes and return an AST as the result - [X] [Sequence](https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/sequence.html) - [ ] [SequenceOf](https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/sequenceof.html) -- [ ] [Set](https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/set.html) +- [X] [Set](https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/set.html) - [ ] [SetOf](https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/setof.html) - [ ] [Choice](https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/choice.html) diff --git a/crates/prop-strategies/src/constructors.rs b/crates/prop-strategies/src/constructors.rs index 3b6b53d..282383a 100644 --- a/crates/prop-strategies/src/constructors.rs +++ b/crates/prop-strategies/src/constructors.rs @@ -3,10 +3,7 @@ use proptest::collection::vec; use proptest::prop_oneof; use proptest::strategy::{Just, Strategy}; -use crate::{ - any_bit_string, any_bmp_string, any_bool, any_integer, any_null, any_octet_string, - any_utf8_string, -}; +use crate::{any_bit_string, any_bmp_string, any_bool, any_integer, any_null, any_octet_string, any_utf8_string}; fn any_leaf_asn1_type() -> impl Strategy { prop_oneof![ diff --git a/src/asn1/hex_view.rs b/src/asn1/hex_view.rs index fca8dfd..603f751 100644 --- a/src/asn1/hex_view.rs +++ b/src/asn1/hex_view.rs @@ -158,6 +158,12 @@ fn build_data_bytes( .iter() .for_each(move |asn1| build_hex_bytes(asn1, cur_node, set_cur_node.clone(), bytes, select_all)); } + Asn1Type::Set(set) => { + let set_cur_node = set_cur_node.clone(); + set.fields() + .iter() + .for_each(move |asn1| build_hex_bytes(asn1, cur_node, set_cur_node.clone(), bytes, select_all)); + } Asn1Type::OctetString(octet) => match octet.inner() { Some(asn1) => build_hex_bytes(asn1, cur_node, set_cur_node.clone(), bytes, select_all), None => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all), diff --git a/src/asn1/scheme.rs b/src/asn1/scheme.rs index eee57cf..7f22719 100644 --- a/src/asn1/scheme.rs +++ b/src/asn1/scheme.rs @@ -1,6 +1,7 @@ mod oid; mod primitive; mod sequence; +mod set; mod strings; mod tag; @@ -14,6 +15,7 @@ use self::primitive::{BoolNode, IntegerNode, NullNode}; use self::sequence::SequenceNode; use self::strings::{BitStringNode, BmpStringNode, OctetStringNode, Utf8StringNode}; use self::tag::{ApplicationTagNode, ExplicitTagNode}; +use crate::asn1::scheme::set::SetNode; use crate::asn1::HighlightAction; #[derive(PartialEq, Properties, Clone)] @@ -70,6 +72,11 @@ pub fn build_asn1_schema(asn1: &Asn1<'_>, cur_id: &Option, set_cur_node: &C }, + Asn1Type::Set(set) => html! { + + + + }, Asn1Type::BitString(bit) => html! { diff --git a/src/asn1/scheme/set.rs b/src/asn1/scheme/set.rs new file mode 100644 index 0000000..635c244 --- /dev/null +++ b/src/asn1/scheme/set.rs @@ -0,0 +1,41 @@ +use asn1_parser::{OwnedRawAsn1EntityData, OwnedSet}; +use yew::{function_component, html, Callback, Html, Properties}; + +use crate::asn1::node_options::NodeOptions; +use crate::asn1::scheme::build_asn1_schema; +use crate::asn1::HighlightAction; + +#[derive(PartialEq, Properties, Clone)] +pub struct SetNodeProps { + pub node: OwnedSet, + pub cur_node: Option, + pub set_cur_node: Callback, + pub meta: OwnedRawAsn1EntityData, +} + +#[function_component(SetNode)] +pub fn set(props: &SetNodeProps) -> Html { + let fields = props.node.fields(); + + let set_cur_node = &props.set_cur_node; + let fields_components = fields + .iter() + .map(|f| build_asn1_schema(f, &props.cur_node, set_cur_node)) + .collect::>(); + + let offset = props.meta.tag_position(); + let length_len = props.meta.length_range().len(); + let data_len = props.meta.data_range().len(); + + html! { +
+
+ + {format!("({} fields)", fields.len())} +
+
+ {fields_components} +
+
+ } +}