Clean-up
This commit is contained in:
parent
bbdf680fe4
commit
13c522d4be
5 changed files with 28 additions and 17 deletions
|
@ -61,7 +61,7 @@ impl Matter {
|
||||||
let mdns = Mdns::get()?;
|
let mdns = Mdns::get()?;
|
||||||
mdns.set_values(dev_det.vid, dev_det.pid, &dev_det.device_name);
|
mdns.set_values(dev_det.vid, dev_det.pid, &dev_det.device_name);
|
||||||
|
|
||||||
print_pairing_code_and_qr(dev_det, dev_comm, DiscoveryCapabilities::default());
|
print_pairing_code_and_qr(dev_det, &dev_comm, DiscoveryCapabilities::default());
|
||||||
|
|
||||||
let fabric_mgr = Arc::new(FabricMgr::new()?);
|
let fabric_mgr = Arc::new(FabricMgr::new()?);
|
||||||
let acl_mgr = Arc::new(AclMgr::new()?);
|
let acl_mgr = Arc::new(AclMgr::new()?);
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
//!
|
//!
|
||||||
//! /// Get the Matter Object
|
//! /// Get the Matter Object
|
||||||
//! /// The dev_att is an object that implements the DevAttDataFetcher trait.
|
//! /// The dev_att is an object that implements the DevAttDataFetcher trait.
|
||||||
//! let mut matter = Matter::new(&dev_info, dev_att, &comm_data).unwrap();
|
//! let mut matter = Matter::new(&dev_info, dev_att, comm_data).unwrap();
|
||||||
//! let dm = matter.get_data_model();
|
//! let dm = matter.get_data_model();
|
||||||
//! {
|
//! {
|
||||||
//! let mut node = dm.node.write().unwrap();
|
//! let mut node = dm.node.write().unwrap();
|
||||||
|
|
|
@ -4,11 +4,8 @@ pub(super) fn compute_pairing_code(comm_data: &CommissioningData) -> String {
|
||||||
// 0: no Vendor ID and Product ID present in Manual Pairing Code
|
// 0: no Vendor ID and Product ID present in Manual Pairing Code
|
||||||
const VID_PID_PRESENT: u8 = 0;
|
const VID_PID_PRESENT: u8 = 0;
|
||||||
|
|
||||||
let CommissioningData {
|
let passwd = passwd_from_comm_data(comm_data);
|
||||||
discriminator,
|
let CommissioningData { discriminator, .. } = comm_data;
|
||||||
passwd,
|
|
||||||
..
|
|
||||||
} = comm_data;
|
|
||||||
|
|
||||||
let mut digits = String::new();
|
let mut digits = String::new();
|
||||||
digits.push_str(&((VID_PID_PRESENT << 2) | (discriminator >> 10) as u8).to_string());
|
digits.push_str(&((VID_PID_PRESENT << 2) | (discriminator >> 10) as u8).to_string());
|
||||||
|
@ -38,21 +35,20 @@ pub(super) fn pretty_print_pairing_code(pairing_code: &str) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::secure_channel::spake2p::VerifierData;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_compute_pairing_code() {
|
fn can_compute_pairing_code() {
|
||||||
let comm_data = CommissioningData {
|
let comm_data = CommissioningData {
|
||||||
passwd: 123456,
|
verifier: VerifierData::new_with_pw(123456),
|
||||||
discriminator: 250,
|
discriminator: 250,
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let pairing_code = compute_pairing_code(&comm_data);
|
let pairing_code = compute_pairing_code(&comm_data);
|
||||||
assert_eq!(pairing_code, "00876800071");
|
assert_eq!(pairing_code, "00876800071");
|
||||||
|
|
||||||
let comm_data = CommissioningData {
|
let comm_data = CommissioningData {
|
||||||
passwd: 34567890,
|
verifier: VerifierData::new_with_pw(34567890),
|
||||||
discriminator: 2976,
|
discriminator: 2976,
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let pairing_code = compute_pairing_code(&comm_data);
|
let pairing_code = compute_pairing_code(&comm_data);
|
||||||
assert_eq!(pairing_code, "26318621095");
|
assert_eq!(pairing_code, "26318621095");
|
||||||
|
|
|
@ -27,7 +27,7 @@ use verhoeff::Verhoeff;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
codec::base38, data_model::cluster_basic_information::BasicInfoConfig, error::Error,
|
codec::base38, data_model::cluster_basic_information::BasicInfoConfig, error::Error,
|
||||||
CommissioningData,
|
secure_channel::spake2p::VerifierOption, CommissioningData,
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
|
@ -94,3 +94,11 @@ pub fn print_pairing_code_and_qr(
|
||||||
pretty_print_pairing_code(&pairing_code);
|
pretty_print_pairing_code(&pairing_code);
|
||||||
print_qr_code(&data_str);
|
print_qr_code(&data_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(self) fn passwd_from_comm_data(comm_data: &CommissioningData) -> u32 {
|
||||||
|
// todo: should this be part of the comm_data implementation?
|
||||||
|
match comm_data.verifier.data {
|
||||||
|
VerifierOption::Password(pwd) => pwd,
|
||||||
|
VerifierOption::Verifier(_) => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ impl<'data> QrCodeData<'data> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_valid(&self) -> bool {
|
fn is_valid(&self) -> bool {
|
||||||
|
let passwd = passwd_from_comm_data(self.comm_data);
|
||||||
|
|
||||||
// 3-bit value specifying the QR code payload version.
|
// 3-bit value specifying the QR code payload version.
|
||||||
if self.version >= 1 << VERSION_FIELD_LENGTH_IN_BITS {
|
if self.version >= 1 << VERSION_FIELD_LENGTH_IN_BITS {
|
||||||
return false;
|
return false;
|
||||||
|
@ -57,7 +59,7 @@ impl<'data> QrCodeData<'data> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.comm_data.passwd >= 1 << SETUP_PINCODE_FIELD_LENGTH_IN_BITS {
|
if passwd >= 1 << SETUP_PINCODE_FIELD_LENGTH_IN_BITS {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +72,9 @@ impl<'data> QrCodeData<'data> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !Self::is_valid_setup_pin(self.comm_data.passwd) {
|
let passwd = passwd_from_comm_data(self.comm_data);
|
||||||
|
|
||||||
|
if !Self::is_valid_setup_pin(passwd) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +210,8 @@ fn generate_bit_set(
|
||||||
return Err(Error::BufferTooSmall);
|
return Err(Error::BufferTooSmall);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let passwd = passwd_from_comm_data(payload.comm_data);
|
||||||
|
|
||||||
populate_bits(
|
populate_bits(
|
||||||
bits,
|
bits,
|
||||||
&mut offset,
|
&mut offset,
|
||||||
|
@ -257,7 +263,7 @@ fn generate_bit_set(
|
||||||
populate_bits(
|
populate_bits(
|
||||||
bits,
|
bits,
|
||||||
&mut offset,
|
&mut offset,
|
||||||
payload.comm_data.passwd as u64,
|
passwd as u64,
|
||||||
SETUP_PINCODE_FIELD_LENGTH_IN_BITS,
|
SETUP_PINCODE_FIELD_LENGTH_IN_BITS,
|
||||||
total_payload_size_in_bits,
|
total_payload_size_in_bits,
|
||||||
)?;
|
)?;
|
||||||
|
@ -278,16 +284,17 @@ fn generate_bit_set(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::secure_channel::spake2p::VerifierData;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_base38_encode() {
|
fn can_base38_encode() {
|
||||||
const QR_CODE: &str = "MT:YNJV7VSC00CMVH7SR00";
|
const QR_CODE: &str = "MT:YNJV7VSC00CMVH7SR00";
|
||||||
|
|
||||||
let comm_data = CommissioningData {
|
let comm_data = CommissioningData {
|
||||||
passwd: 34567890,
|
verifier: VerifierData::new_with_pw(34567890),
|
||||||
discriminator: 2976,
|
discriminator: 2976,
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let dev_det = BasicInfoConfig {
|
let dev_det = BasicInfoConfig {
|
||||||
vid: 9050,
|
vid: 9050,
|
||||||
|
|
Loading…
Add table
Reference in a new issue