Skip to content

Commit

Permalink
feat(crypto-helper): asn1: implement GeneralString rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestTvarynka committed Jan 21, 2024
1 parent 330bd39 commit c1abf5f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/asn1/hex_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ fn build_data_bytes(
Asn1Type::Utf8String(_) => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all),
Asn1Type::IA5String(_) => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all),
Asn1Type::PrintableString(_) => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all),
Asn1Type::GeneralString(_) => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all),
Asn1Type::UtcTime(_) => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all),
Asn1Type::BitString(_) => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all),
Asn1Type::BmpString(_) => default_bytes(asn1_node_id, cur_node, set_cur_node, asn1, bytes, select_all),
Expand Down
8 changes: 7 additions & 1 deletion src/asn1/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use self::oid::ObjectIdentifierNode;
use self::primitive::{BoolNode, IntegerNode, NullNode};
use self::sequence::SequenceNode;
use self::strings::{
BitStringNode, BmpStringNode, IA5StringNode, OctetStringNode, PrintableStringNode, Utf8StringNode,
BitStringNode, BmpStringNode, GeneralStringNode, IA5StringNode, OctetStringNode, PrintableStringNode,
Utf8StringNode,
};
use self::tag::{ApplicationTagNode, ExplicitTagNode, ImplicitTagNode};
use self::time::UtcTimeNode;
Expand Down Expand Up @@ -81,6 +82,11 @@ pub fn build_asn1_schema(asn1: &Asn1<'_>, cur_id: &Option<u64>, set_cur_node: &C
<PrintableStringNode node={printable.to_owned()} meta={asn1.meta().to_owned()} />
</Asn1Node>
},
Asn1Type::GeneralString(general) => html! {
<Asn1Node id={asn1.id()} {cur_id} set_cur_node={set_cur_node.clone()}>
<GeneralStringNode node={general.to_owned()} meta={asn1.meta().to_owned()} />
</Asn1Node>
},
Asn1Type::Sequence(sequence) => html! {
<Asn1Node id={asn1.id()} {cur_id} set_cur_node={set_cur_node.clone()}>
<SequenceNode node={sequence.to_owned()} cur_node={cur_id} set_cur_node={set_cur_node.clone()} meta={asn1.meta().to_owned()} />
Expand Down
24 changes: 22 additions & 2 deletions src/asn1/scheme/strings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use asn1_parser::{
OwnedBitString, OwnedBmpString, OwnedIA5String, OwnedOctetString, OwnedPrintableString, OwnedRawAsn1EntityData,
OwnedUtf8String,
OwnedBitString, OwnedBmpString, OwnedGeneralString, OwnedIA5String, OwnedOctetString, OwnedPrintableString,
OwnedRawAsn1EntityData, OwnedUtf8String,
};
use yew::{function_component, html, Callback, Html, Properties};

Expand Down Expand Up @@ -168,3 +168,23 @@ pub fn utf8_string(props: &PrintableStringNodeProps) -> Html {
</div>
}
}

#[derive(PartialEq, Properties, Clone)]
pub struct GeneralStringNodeProps {
pub node: OwnedGeneralString,
pub meta: OwnedRawAsn1EntityData,
}

#[function_component(GeneralStringNode)]
pub fn utf8_string(props: &GeneralStringNodeProps) -> Html {
let offset = props.meta.tag_position();
let length_len = props.meta.length_range().len();
let data_len = props.meta.data_range().len();

html! {
<div class="terminal-asn1-node">
<NodeOptions node_bytes={props.meta.raw_bytes().to_vec()} {offset} {length_len} {data_len} name={String::from("GeneralString")}/>
<span class="asn-simple-value">{props.node.string().to_owned()}</span>
</div>
}
}

0 comments on commit c1abf5f

Please sign in to comment.