Skip to content

Commit

Permalink
Fix TLVTool
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Sep 14, 2024
1 parent 045b890 commit 26a7aff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rs-matter/src/cert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl<'a> CertRef<'a> {
Ok(authority.is_some())
}

fn as_asn1(&self, buf: &mut [u8]) -> Result<usize, Error> {
pub fn as_asn1(&self, buf: &mut [u8]) -> Result<usize, Error> {
let mut w = ASN1Writer::new(buf);
self.encode(&mut w)?;
Ok(w.as_slice().len())
Expand Down
9 changes: 6 additions & 3 deletions tools/tlv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ fn main() {
let tlv_list = base.parse_list(m.value_of("tlvs").unwrap(), ',');

// println!("Decoding: {:x?}", tlv_list.as_slice());

let tlv = tlv::TLVElement::new(tlv_list.as_slice());

if m.is_present("cert") {
let cert = cert::Cert::new(tlv_list.as_slice()).unwrap();
let cert = cert::CertRef::new(tlv);
println!("{}", cert);
} else if m.is_present("as-asn1") {
let mut asn1_cert = [0_u8; 1024];
let cert = cert::Cert::new(tlv_list.as_slice()).unwrap();
let cert = cert::CertRef::new(tlv);
let len = cert.as_asn1(&mut asn1_cert).unwrap();
println!("{:02x?}", &asn1_cert[..len]);
} else {
tlv::print_tlv_list(tlv_list.as_slice());
println!("TLV {tlv}");
}
}

0 comments on commit 26a7aff

Please sign in to comment.