Bugfix: fabric adding wrongly started at index 0

This commit is contained in:
ivmarkov 2023-04-26 05:20:02 +00:00
parent f9536be1e3
commit f804c21c0b
2 changed files with 20 additions and 14 deletions

View file

@ -199,6 +199,12 @@ impl KeyPair {
}
}
impl core::fmt::Debug for KeyPair {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("KeyPair").finish()
}
}
fn convert_r_s_to_asn1_sign(signature: &[u8], mbedtls_sign: &mut [u8]) -> Result<usize, Error> {
let r = &signature[0..32];
let s = &signature[32..64];

View file

@ -53,7 +53,7 @@ const ST_PBKEY: &str = "pubkey";
const ST_PRKEY: &str = "privkey";
#[allow(dead_code)]
#[derive(ToTLV)]
#[derive(Debug, ToTLV)]
#[tlvargs(lifetime = "'a", start = 1)]
pub struct FabricDescriptor<'a> {
root_public_key: OctetStr<'a>,
@ -66,6 +66,7 @@ pub struct FabricDescriptor<'a> {
pub fab_idx: Option<u8>,
}
#[derive(Debug)]
pub struct Fabric {
node_id: u64,
fabric_id: u64,
@ -532,22 +533,21 @@ impl FabricMgr {
}
pub fn add(&mut self, f: Fabric, mdns_mgr: &mut MdnsMgr) -> Result<u8, Error> {
let index = self
.fabrics
.iter()
.skip(1)
.position(|f| f.is_none())
.ok_or(Error::NoSpace)?;
self.fabrics[index] = Some(f);
for i in 1..MAX_SUPPORTED_FABRICS {
if self.fabrics[i].is_none() {
self.fabrics[i] = Some(f);
mdns_mgr.publish_service(
&self.fabrics[index].as_ref().unwrap().mdns_service_name,
&self.fabrics[i].as_ref().unwrap().mdns_service_name,
ServiceMode::Commissioned,
)?;
self.changed = true;
Ok(index as u8)
return Ok(i as u8);
}
}
Err(Error::NoSpace)
}
pub fn remove(&mut self, fab_idx: u8, mdns_mgr: &mut MdnsMgr) -> Result<(), Error> {