Skip to content

Commit 6b4b7a9

Browse files
committed
Use more refined array type aliases
1 parent 7f5884f commit 6b4b7a9

8 files changed

Lines changed: 138 additions & 81 deletions

File tree

rs-matter/src/dm/clusters/noc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,11 @@ impl ClusterHandler for NocHandler {
431431
request.admin_vendor_id()?,
432432
icac,
433433
request.noc_value()?.0,
434-
request.ipk_value()?.0,
434+
request
435+
.ipk_value()?
436+
.0
437+
.try_into()
438+
.map_err(|_| ErrorCode::ConstraintError)?,
435439
request.case_admin_subject()?,
436440
buf,
437441
&mut || ctx.exchange().matter().notify_mdns(),

rs-matter/src/fabric.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::cert::{CertRef, MAX_CERT_TLV_LEN};
2626
use crate::crypto::{self, hkdf_sha256, HmacSha256, KeyPair};
2727
use crate::dm::Privilege;
2828
use crate::error::{Error, ErrorCode};
29-
use crate::group_keys::KeySet;
29+
use crate::group_keys::{KeySet, KeySetKey};
3030
use crate::tlv::{FromTLV, TLVElement, TLVTag, TLVWrite, TagType, ToTLV};
3131
use crate::utils::init::{init, Init, InitMaybeUninit, IntoFallibleInit};
3232
use crate::utils::storage::{Vec, WriteBuf};
@@ -107,7 +107,7 @@ impl Fabric {
107107
root_ca: &[u8],
108108
noc: &[u8],
109109
icac: &[u8],
110-
ipk: Option<&[u8]>,
110+
ipk: Option<&KeySetKey>,
111111
vendor_id: Option<u16>,
112112
case_admin_subject: Option<u64>,
113113
mdns_notif: &mut dyn FnMut(),
@@ -137,7 +137,7 @@ impl Fabric {
137137
Self::compute_compressed_fabric_id(root_ca_p.pubkey()?, self.fabric_id);
138138

139139
if let Some(ipk) = ipk {
140-
self.ipk = KeySet::new(ipk, &self.compressed_fabric_id.to_be_bytes())?;
140+
self.ipk = KeySet::new(ipk, &self.compressed_fabric_id)?;
141141
}
142142

143143
if let Some(case_admin_subject) = case_admin_subject {
@@ -578,7 +578,7 @@ impl FabricMgr {
578578
root_ca: &[u8],
579579
noc: &[u8],
580580
icac: &[u8],
581-
ipk: &[u8],
581+
ipk: &KeySetKey,
582582
vendor_id: u16,
583583
case_admin_subject: u64,
584584
mdns_notif: &mut dyn FnMut(),

rs-matter/src/failsafe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::cert::{CertRef, MAX_CERT_TLV_LEN};
2222
use crate::crypto::KeyPair;
2323
use crate::error::{Error, ErrorCode};
2424
use crate::fabric::FabricMgr;
25+
use crate::group_keys::KeySetKey;
2526
use crate::im::IMStatusCode;
2627
use crate::tlv::TLVElement;
2728
use crate::transport::session::SessionMode;
@@ -279,7 +280,7 @@ impl FailSafe {
279280
vendor_id: u16,
280281
icac: Option<&[u8]>,
281282
noc: &[u8],
282-
ipk: &[u8],
283+
ipk: &KeySetKey,
283284
case_admin_subject: u64,
284285
buf: &mut [u8],
285286
mdns_notif: &mut dyn FnMut(),

rs-matter/src/group_keys.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
utils::init::{init, zeroed, Init},
2323
};
2424

25-
type KeySetKey = [u8; SYMM_KEY_LEN_BYTES];
25+
pub type KeySetKey = [u8; SYMM_KEY_LEN_BYTES];
2626

2727
#[derive(Debug, Default, FromTLV, ToTLV)]
2828
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -46,27 +46,36 @@ impl KeySet {
4646
})
4747
}
4848

49-
pub fn new(epoch_key: &[u8], compressed_id: &[u8]) -> Result<Self, Error> {
49+
pub fn new(epoch_key: &KeySetKey, compressed_fabric_id: &u64) -> Result<Self, Error> {
5050
let mut ks = KeySet::default();
51-
KeySet::op_key_from_ipk(epoch_key, compressed_id, &mut ks.op_key)?;
51+
Self::op_key_from_ipk(epoch_key, compressed_fabric_id, &mut ks.op_key)?;
5252
ks.epoch_key.copy_from_slice(epoch_key);
5353
Ok(ks)
5454
}
5555

56-
fn op_key_from_ipk(ipk: &[u8], compressed_id: &[u8], opkey: &mut [u8]) -> Result<(), Error> {
56+
fn op_key_from_ipk(
57+
ipk: &KeySetKey,
58+
compressed_fabric_id: &u64,
59+
opkey: &mut KeySetKey,
60+
) -> Result<(), Error> {
5761
const GRP_KEY_INFO: [u8; 13] = [
5862
0x47, 0x72, 0x6f, 0x75, 0x70, 0x4b, 0x65, 0x79, 0x20, 0x76, 0x31, 0x2e, 0x30,
5963
];
6064

61-
crypto::hkdf_sha256(compressed_id, ipk, &GRP_KEY_INFO, opkey)
62-
.map_err(|_| ErrorCode::InvalidData.into())
65+
crypto::hkdf_sha256(
66+
&compressed_fabric_id.to_be_bytes(),
67+
ipk,
68+
&GRP_KEY_INFO,
69+
opkey,
70+
)
71+
.map_err(|_| ErrorCode::InvalidData.into())
6372
}
6473

65-
pub fn op_key(&self) -> &[u8] {
74+
pub fn op_key(&self) -> &KeySetKey {
6675
&self.op_key
6776
}
6877

69-
pub fn epoch_key(&self) -> &[u8] {
78+
pub fn epoch_key(&self) -> &KeySetKey {
7079
&self.epoch_key
7180
}
7281
}

rs-matter/src/sc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod case;
3636
pub mod crypto;
3737
pub mod pake;
3838

39-
/* Interaction Model ID as per the Matter Spec */
39+
/// Interaction Model ID as per the Matter Spec
4040
pub const PROTO_ID_SECURE_CHANNEL: u16 = 0x00;
4141

4242
#[derive(FromPrimitive, Debug, Copy, Clone, Eq, PartialEq)]

0 commit comments

Comments
 (0)