1#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23 ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26pub const ID: ClusterId = 0x003E;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "OPCREDS";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod attribute {
41 use crate::im::AttributeId;
42
43 pub const NO_CS: AttributeId = 0x00;
45 pub const FABRICS: AttributeId = 0x01;
47 pub const SUPPORTED_FABRICS: AttributeId = 0x02;
49 pub const COMMISSIONED_FABRICS: AttributeId = 0x03;
51 pub const TRUSTED_ROOT_CERTIFICATES: AttributeId = 0x04;
53 pub const CURRENT_FABRIC_INDEX: AttributeId = 0x05;
55}
56
57pub mod command {
59 use crate::im::CommandId;
60
61 pub const ATTESTATION_REQUEST: CommandId = 0x00;
63 pub const ATTESTATION_RESPONSE: CommandId = 0x01;
65 pub const CERTIFICATE_CHAIN_REQUEST: CommandId = 0x02;
67 pub const CERTIFICATE_CHAIN_RESPONSE: CommandId = 0x03;
69 pub const CSR_REQUEST: CommandId = 0x04;
71 pub const CSR_RESPONSE: CommandId = 0x05;
73 pub const ADD_NOC: CommandId = 0x06;
75 pub const UPDATE_NOC: CommandId = 0x07;
77 pub const NOC_RESPONSE: CommandId = 0x08;
79 pub const UPDATE_FABRIC_LABEL: CommandId = 0x09;
81 pub const REMOVE_FABRIC: CommandId = 0x0A;
83 pub const ADD_TRUSTED_ROOT_CERTIFICATE: CommandId = 0x0B;
85 pub const SET_VID_VERIFICATION_STATEMENT: CommandId = 0x0C;
87 pub const SIGN_VID_VERIFICATION_REQUEST: CommandId = 0x0D;
89 pub const SIGN_VID_VERIFICATION_RESPONSE: CommandId = 0x0E;
91}
92
93#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
95#[repr(u8)]
96pub enum CertificateChainTypeEnum {
97 DACCertificate = 1,
99 PAICertificate = 2,
101}
102
103impl CertificateChainTypeEnum {
104 #[must_use]
106 pub const fn from_value(value: u8) -> Option<Self> {
107 match value {
108 1 => Some(Self::DACCertificate),
109 2 => Some(Self::PAICertificate),
110 _ => None,
111 }
112 }
113
114 #[must_use]
116 pub const fn value(self) -> u8 {
117 self as u8
118 }
119}
120
121impl ToTlv for CertificateChainTypeEnum {
122 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
123 self.value().to_tlv(w, tag)
124 }
125}
126
127impl<'a> FromTlv<'a> for CertificateChainTypeEnum {
128 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
129 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
130 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
131 }
132}
133
134#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
136#[repr(u8)]
137pub enum NodeOperationalCertStatusEnum {
138 OK = 0,
140 InvalidPublicKey = 1,
142 InvalidNodeOpId = 2,
144 InvalidNOC = 3,
146 MissingCsr = 4,
148 TableFull = 5,
150 InvalidAdminSubject = 6,
152 FabricConflict = 9,
154 LabelConflict = 10,
156 InvalidFabricIndex = 11,
158}
159
160impl NodeOperationalCertStatusEnum {
161 #[must_use]
163 pub const fn from_value(value: u8) -> Option<Self> {
164 match value {
165 0 => Some(Self::OK),
166 1 => Some(Self::InvalidPublicKey),
167 2 => Some(Self::InvalidNodeOpId),
168 3 => Some(Self::InvalidNOC),
169 4 => Some(Self::MissingCsr),
170 5 => Some(Self::TableFull),
171 6 => Some(Self::InvalidAdminSubject),
172 9 => Some(Self::FabricConflict),
173 10 => Some(Self::LabelConflict),
174 11 => Some(Self::InvalidFabricIndex),
175 _ => None,
176 }
177 }
178
179 #[must_use]
181 pub const fn value(self) -> u8 {
182 self as u8
183 }
184}
185
186impl ToTlv for NodeOperationalCertStatusEnum {
187 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
188 self.value().to_tlv(w, tag)
189 }
190}
191
192impl<'a> FromTlv<'a> for NodeOperationalCertStatusEnum {
193 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
194 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
195 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
196 }
197}
198
199#[derive(Debug, Clone, Copy, PartialEq)]
201pub struct FabricDescriptorStruct<'a> {
202 pub root_public_key: &'a [u8],
204 pub vendor_id: crate::msg::VendorId,
206 pub fabric_id: u64,
208 pub node_id: crate::msg::NodeId,
210 pub label: &'a str,
212 pub vid_verification_statement: Option<&'a [u8]>,
214 pub fabric_index: crate::msg::FabricIndex,
216}
217
218impl<'a> ToTlv for FabricDescriptorStruct<'a> {
219 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
220 w.start_structure(tag)?;
221 self.root_public_key.to_tlv(w, Tag::Context(1))?;
222 self.vendor_id.to_tlv(w, Tag::Context(2))?;
223 self.fabric_id.to_tlv(w, Tag::Context(3))?;
224 self.node_id.to_tlv(w, Tag::Context(4))?;
225 self.label.to_tlv(w, Tag::Context(5))?;
226 if let Some(value) = &self.vid_verification_statement {
227 value.to_tlv(w, Tag::Context(6))?;
228 }
229 self.fabric_index.to_tlv(w, Tag::Context(254))?;
230 w.end_container()
231 }
232}
233
234impl<'a> FromTlv<'a> for FabricDescriptorStruct<'a> {
235 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
236 if element.value.container() != Some(ContainerKind::Structure) {
237 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
238 }
239 let mut root_public_key = None;
240 let mut vendor_id = None;
241 let mut fabric_id = None;
242 let mut node_id = None;
243 let mut label = None;
244 let mut vid_verification_statement = None;
245 let mut fabric_index = None;
246 loop {
247 let Some(field) = reader.next_element()? else {
248 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
249 };
250 if field.value == Value::EndOfContainer {
251 break;
252 }
253 match field.tag.context() {
254 Some(1) => root_public_key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
255 Some(2) => vendor_id = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
256 Some(3) => fabric_id = Some(<u64>::from_tlv(reader, &field)?),
257 Some(4) => node_id = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
258 Some(5) => label = Some(<&'a str>::from_tlv(reader, &field)?),
259 Some(6) => vid_verification_statement = Some(<&'a [u8]>::from_tlv(reader, &field)?),
260 Some(254) => {
261 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
262 }
263 _ => reader.skip_value(&field)?,
267 }
268 }
269 Ok(Self {
270 root_public_key: root_public_key
271 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
272 vendor_id: vendor_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
273 fabric_id: fabric_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
274 node_id: node_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
275 label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
276 vid_verification_statement,
277 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
278 })
279 }
280}
281
282#[derive(Debug, Clone, Copy, PartialEq)]
284pub struct NOCStruct<'a> {
285 pub noc: &'a [u8],
287 pub icac: Nullable<&'a [u8]>,
289 pub vvsc: Option<&'a [u8]>,
291 pub fabric_index: crate::msg::FabricIndex,
293}
294
295impl<'a> ToTlv for NOCStruct<'a> {
296 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
297 w.start_structure(tag)?;
298 self.noc.to_tlv(w, Tag::Context(1))?;
299 self.icac.to_tlv(w, Tag::Context(2))?;
300 if let Some(value) = &self.vvsc {
301 value.to_tlv(w, Tag::Context(3))?;
302 }
303 self.fabric_index.to_tlv(w, Tag::Context(254))?;
304 w.end_container()
305 }
306}
307
308impl<'a> FromTlv<'a> for NOCStruct<'a> {
309 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
310 if element.value.container() != Some(ContainerKind::Structure) {
311 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
312 }
313 let mut noc = None;
314 let mut icac = None;
315 let mut vvsc = None;
316 let mut fabric_index = None;
317 loop {
318 let Some(field) = reader.next_element()? else {
319 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
320 };
321 if field.value == Value::EndOfContainer {
322 break;
323 }
324 match field.tag.context() {
325 Some(1) => noc = Some(<&'a [u8]>::from_tlv(reader, &field)?),
326 Some(2) => icac = Some(<Nullable<&'a [u8]>>::from_tlv(reader, &field)?),
327 Some(3) => vvsc = Some(<&'a [u8]>::from_tlv(reader, &field)?),
328 Some(254) => {
329 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
330 }
331 _ => reader.skip_value(&field)?,
335 }
336 }
337 Ok(Self {
338 noc: noc.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
339 icac: icac.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
340 vvsc,
341 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
342 })
343 }
344}
345
346#[derive(Debug, Clone, Copy, PartialEq)]
348pub struct AttestationRequestFields<'a> {
349 pub attestation_nonce: &'a [u8],
351}
352
353impl<'a> ToTlv for AttestationRequestFields<'a> {
354 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
355 w.start_structure(tag)?;
356 self.attestation_nonce.to_tlv(w, Tag::Context(0))?;
357 w.end_container()
358 }
359}
360
361impl<'a> FromTlv<'a> for AttestationRequestFields<'a> {
362 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
363 if element.value.container() != Some(ContainerKind::Structure) {
364 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
365 }
366 let mut attestation_nonce = None;
367 loop {
368 let Some(field) = reader.next_element()? else {
369 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
370 };
371 if field.value == Value::EndOfContainer {
372 break;
373 }
374 match field.tag.context() {
375 Some(0) => attestation_nonce = Some(<&'a [u8]>::from_tlv(reader, &field)?),
376 _ => reader.skip_value(&field)?,
380 }
381 }
382 Ok(Self {
383 attestation_nonce: attestation_nonce
384 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
385 })
386 }
387}
388
389#[derive(Debug, Clone, Copy, PartialEq)]
391pub struct AttestationResponseFields<'a> {
392 pub attestation_elements: &'a [u8],
394 pub attestation_signature: &'a [u8],
396}
397
398impl<'a> ToTlv for AttestationResponseFields<'a> {
399 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
400 w.start_structure(tag)?;
401 self.attestation_elements.to_tlv(w, Tag::Context(0))?;
402 self.attestation_signature.to_tlv(w, Tag::Context(1))?;
403 w.end_container()
404 }
405}
406
407impl<'a> FromTlv<'a> for AttestationResponseFields<'a> {
408 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
409 if element.value.container() != Some(ContainerKind::Structure) {
410 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
411 }
412 let mut attestation_elements = None;
413 let mut attestation_signature = None;
414 loop {
415 let Some(field) = reader.next_element()? else {
416 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
417 };
418 if field.value == Value::EndOfContainer {
419 break;
420 }
421 match field.tag.context() {
422 Some(0) => attestation_elements = Some(<&'a [u8]>::from_tlv(reader, &field)?),
423 Some(1) => attestation_signature = Some(<&'a [u8]>::from_tlv(reader, &field)?),
424 _ => reader.skip_value(&field)?,
428 }
429 }
430 Ok(Self {
431 attestation_elements: attestation_elements
432 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
433 attestation_signature: attestation_signature
434 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
435 })
436 }
437}
438
439#[derive(Debug, Clone, Copy, PartialEq)]
441pub struct CertificateChainRequestFields {
442 pub certificate_type: CertificateChainTypeEnum,
444}
445
446impl ToTlv for CertificateChainRequestFields {
447 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
448 w.start_structure(tag)?;
449 self.certificate_type.to_tlv(w, Tag::Context(0))?;
450 w.end_container()
451 }
452}
453
454impl<'a> FromTlv<'a> for CertificateChainRequestFields {
455 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
456 if element.value.container() != Some(ContainerKind::Structure) {
457 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
458 }
459 let mut certificate_type = None;
460 loop {
461 let Some(field) = reader.next_element()? else {
462 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
463 };
464 if field.value == Value::EndOfContainer {
465 break;
466 }
467 match field.tag.context() {
468 Some(0) => {
469 certificate_type = Some(<CertificateChainTypeEnum>::from_tlv(reader, &field)?)
470 }
471 _ => reader.skip_value(&field)?,
475 }
476 }
477 Ok(Self {
478 certificate_type: certificate_type
479 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
480 })
481 }
482}
483
484#[derive(Debug, Clone, Copy, PartialEq)]
486pub struct CertificateChainResponseFields<'a> {
487 pub certificate: &'a [u8],
489}
490
491impl<'a> ToTlv for CertificateChainResponseFields<'a> {
492 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
493 w.start_structure(tag)?;
494 self.certificate.to_tlv(w, Tag::Context(0))?;
495 w.end_container()
496 }
497}
498
499impl<'a> FromTlv<'a> for CertificateChainResponseFields<'a> {
500 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
501 if element.value.container() != Some(ContainerKind::Structure) {
502 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
503 }
504 let mut certificate = None;
505 loop {
506 let Some(field) = reader.next_element()? else {
507 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
508 };
509 if field.value == Value::EndOfContainer {
510 break;
511 }
512 match field.tag.context() {
513 Some(0) => certificate = Some(<&'a [u8]>::from_tlv(reader, &field)?),
514 _ => reader.skip_value(&field)?,
518 }
519 }
520 Ok(Self {
521 certificate: certificate.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
522 })
523 }
524}
525
526#[derive(Debug, Clone, Copy, PartialEq)]
528pub struct CSRRequestFields<'a> {
529 pub csr_nonce: &'a [u8],
531 pub is_for_update_noc: Option<bool>,
533}
534
535impl<'a> ToTlv for CSRRequestFields<'a> {
536 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
537 w.start_structure(tag)?;
538 self.csr_nonce.to_tlv(w, Tag::Context(0))?;
539 if let Some(value) = &self.is_for_update_noc {
540 value.to_tlv(w, Tag::Context(1))?;
541 }
542 w.end_container()
543 }
544}
545
546impl<'a> FromTlv<'a> for CSRRequestFields<'a> {
547 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
548 if element.value.container() != Some(ContainerKind::Structure) {
549 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
550 }
551 let mut csr_nonce = None;
552 let mut is_for_update_noc = None;
553 loop {
554 let Some(field) = reader.next_element()? else {
555 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
556 };
557 if field.value == Value::EndOfContainer {
558 break;
559 }
560 match field.tag.context() {
561 Some(0) => csr_nonce = Some(<&'a [u8]>::from_tlv(reader, &field)?),
562 Some(1) => is_for_update_noc = Some(<bool>::from_tlv(reader, &field)?),
563 _ => reader.skip_value(&field)?,
567 }
568 }
569 Ok(Self {
570 csr_nonce: csr_nonce.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
571 is_for_update_noc,
572 })
573 }
574}
575
576#[derive(Debug, Clone, Copy, PartialEq)]
578pub struct CSRResponseFields<'a> {
579 pub nocsr_elements: &'a [u8],
581 pub attestation_signature: &'a [u8],
583}
584
585impl<'a> ToTlv for CSRResponseFields<'a> {
586 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
587 w.start_structure(tag)?;
588 self.nocsr_elements.to_tlv(w, Tag::Context(0))?;
589 self.attestation_signature.to_tlv(w, Tag::Context(1))?;
590 w.end_container()
591 }
592}
593
594impl<'a> FromTlv<'a> for CSRResponseFields<'a> {
595 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
596 if element.value.container() != Some(ContainerKind::Structure) {
597 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
598 }
599 let mut nocsr_elements = None;
600 let mut attestation_signature = None;
601 loop {
602 let Some(field) = reader.next_element()? else {
603 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
604 };
605 if field.value == Value::EndOfContainer {
606 break;
607 }
608 match field.tag.context() {
609 Some(0) => nocsr_elements = Some(<&'a [u8]>::from_tlv(reader, &field)?),
610 Some(1) => attestation_signature = Some(<&'a [u8]>::from_tlv(reader, &field)?),
611 _ => reader.skip_value(&field)?,
615 }
616 }
617 Ok(Self {
618 nocsr_elements: nocsr_elements
619 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
620 attestation_signature: attestation_signature
621 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
622 })
623 }
624}
625
626#[derive(Debug, Clone, Copy, PartialEq)]
628pub struct AddNOCFields<'a> {
629 pub noc_value: &'a [u8],
631 pub icac_value: Option<&'a [u8]>,
633 pub ipk_value: &'a [u8],
635 pub case_admin_subject: u64,
637 pub admin_vendor_id: crate::msg::VendorId,
639}
640
641impl<'a> ToTlv for AddNOCFields<'a> {
642 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
643 w.start_structure(tag)?;
644 self.noc_value.to_tlv(w, Tag::Context(0))?;
645 if let Some(value) = &self.icac_value {
646 value.to_tlv(w, Tag::Context(1))?;
647 }
648 self.ipk_value.to_tlv(w, Tag::Context(2))?;
649 self.case_admin_subject.to_tlv(w, Tag::Context(3))?;
650 self.admin_vendor_id.to_tlv(w, Tag::Context(4))?;
651 w.end_container()
652 }
653}
654
655impl<'a> FromTlv<'a> for AddNOCFields<'a> {
656 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
657 if element.value.container() != Some(ContainerKind::Structure) {
658 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
659 }
660 let mut noc_value = None;
661 let mut icac_value = None;
662 let mut ipk_value = None;
663 let mut case_admin_subject = None;
664 let mut admin_vendor_id = None;
665 loop {
666 let Some(field) = reader.next_element()? else {
667 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
668 };
669 if field.value == Value::EndOfContainer {
670 break;
671 }
672 match field.tag.context() {
673 Some(0) => noc_value = Some(<&'a [u8]>::from_tlv(reader, &field)?),
674 Some(1) => icac_value = Some(<&'a [u8]>::from_tlv(reader, &field)?),
675 Some(2) => ipk_value = Some(<&'a [u8]>::from_tlv(reader, &field)?),
676 Some(3) => case_admin_subject = Some(<u64>::from_tlv(reader, &field)?),
677 Some(4) => {
678 admin_vendor_id = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?)
679 }
680 _ => reader.skip_value(&field)?,
684 }
685 }
686 Ok(Self {
687 noc_value: noc_value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
688 icac_value,
689 ipk_value: ipk_value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
690 case_admin_subject: case_admin_subject
691 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
692 admin_vendor_id: admin_vendor_id
693 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
694 })
695 }
696}
697
698#[derive(Debug, Clone, Copy, PartialEq)]
700pub struct UpdateNOCFields<'a> {
701 pub noc_value: &'a [u8],
703 pub icac_value: Option<&'a [u8]>,
705}
706
707impl<'a> ToTlv for UpdateNOCFields<'a> {
708 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
709 w.start_structure(tag)?;
710 self.noc_value.to_tlv(w, Tag::Context(0))?;
711 if let Some(value) = &self.icac_value {
712 value.to_tlv(w, Tag::Context(1))?;
713 }
714 w.end_container()
715 }
716}
717
718impl<'a> FromTlv<'a> for UpdateNOCFields<'a> {
719 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
720 if element.value.container() != Some(ContainerKind::Structure) {
721 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
722 }
723 let mut noc_value = None;
724 let mut icac_value = None;
725 loop {
726 let Some(field) = reader.next_element()? else {
727 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
728 };
729 if field.value == Value::EndOfContainer {
730 break;
731 }
732 match field.tag.context() {
733 Some(0) => noc_value = Some(<&'a [u8]>::from_tlv(reader, &field)?),
734 Some(1) => icac_value = Some(<&'a [u8]>::from_tlv(reader, &field)?),
735 _ => reader.skip_value(&field)?,
739 }
740 }
741 Ok(Self {
742 noc_value: noc_value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
743 icac_value,
744 })
745 }
746}
747
748#[derive(Debug, Clone, Copy, PartialEq)]
750pub struct NOCResponseFields<'a> {
751 pub status_code: NodeOperationalCertStatusEnum,
753 pub fabric_index: Option<crate::msg::FabricIndex>,
755 pub debug_text: Option<&'a str>,
757}
758
759impl<'a> ToTlv for NOCResponseFields<'a> {
760 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
761 w.start_structure(tag)?;
762 self.status_code.to_tlv(w, Tag::Context(0))?;
763 if let Some(value) = &self.fabric_index {
764 value.to_tlv(w, Tag::Context(1))?;
765 }
766 if let Some(value) = &self.debug_text {
767 value.to_tlv(w, Tag::Context(2))?;
768 }
769 w.end_container()
770 }
771}
772
773impl<'a> FromTlv<'a> for NOCResponseFields<'a> {
774 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
775 if element.value.container() != Some(ContainerKind::Structure) {
776 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
777 }
778 let mut status_code = None;
779 let mut fabric_index = None;
780 let mut debug_text = None;
781 loop {
782 let Some(field) = reader.next_element()? else {
783 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
784 };
785 if field.value == Value::EndOfContainer {
786 break;
787 }
788 match field.tag.context() {
789 Some(0) => {
790 status_code = Some(<NodeOperationalCertStatusEnum>::from_tlv(reader, &field)?)
791 }
792 Some(1) => {
793 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
794 }
795 Some(2) => debug_text = Some(<&'a str>::from_tlv(reader, &field)?),
796 _ => reader.skip_value(&field)?,
800 }
801 }
802 Ok(Self {
803 status_code: status_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
804 fabric_index,
805 debug_text,
806 })
807 }
808}
809
810#[derive(Debug, Clone, Copy, PartialEq)]
812pub struct UpdateFabricLabelFields<'a> {
813 pub label: &'a str,
815}
816
817impl<'a> ToTlv for UpdateFabricLabelFields<'a> {
818 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
819 w.start_structure(tag)?;
820 self.label.to_tlv(w, Tag::Context(0))?;
821 w.end_container()
822 }
823}
824
825impl<'a> FromTlv<'a> for UpdateFabricLabelFields<'a> {
826 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
827 if element.value.container() != Some(ContainerKind::Structure) {
828 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
829 }
830 let mut label = None;
831 loop {
832 let Some(field) = reader.next_element()? else {
833 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
834 };
835 if field.value == Value::EndOfContainer {
836 break;
837 }
838 match field.tag.context() {
839 Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
840 _ => reader.skip_value(&field)?,
844 }
845 }
846 Ok(Self {
847 label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
848 })
849 }
850}
851
852#[derive(Debug, Clone, Copy, PartialEq)]
854pub struct RemoveFabricFields {
855 pub fabric_index: crate::msg::FabricIndex,
857}
858
859impl ToTlv for RemoveFabricFields {
860 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
861 w.start_structure(tag)?;
862 self.fabric_index.to_tlv(w, Tag::Context(0))?;
863 w.end_container()
864 }
865}
866
867impl<'a> FromTlv<'a> for RemoveFabricFields {
868 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
869 if element.value.container() != Some(ContainerKind::Structure) {
870 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
871 }
872 let mut fabric_index = None;
873 loop {
874 let Some(field) = reader.next_element()? else {
875 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
876 };
877 if field.value == Value::EndOfContainer {
878 break;
879 }
880 match field.tag.context() {
881 Some(0) => {
882 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
883 }
884 _ => reader.skip_value(&field)?,
888 }
889 }
890 Ok(Self {
891 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
892 })
893 }
894}
895
896#[derive(Debug, Clone, Copy, PartialEq)]
898pub struct AddTrustedRootCertificateFields<'a> {
899 pub root_ca_certificate: &'a [u8],
901}
902
903impl<'a> ToTlv for AddTrustedRootCertificateFields<'a> {
904 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
905 w.start_structure(tag)?;
906 self.root_ca_certificate.to_tlv(w, Tag::Context(0))?;
907 w.end_container()
908 }
909}
910
911impl<'a> FromTlv<'a> for AddTrustedRootCertificateFields<'a> {
912 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
913 if element.value.container() != Some(ContainerKind::Structure) {
914 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
915 }
916 let mut root_ca_certificate = None;
917 loop {
918 let Some(field) = reader.next_element()? else {
919 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
920 };
921 if field.value == Value::EndOfContainer {
922 break;
923 }
924 match field.tag.context() {
925 Some(0) => root_ca_certificate = Some(<&'a [u8]>::from_tlv(reader, &field)?),
926 _ => reader.skip_value(&field)?,
930 }
931 }
932 Ok(Self {
933 root_ca_certificate: root_ca_certificate
934 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
935 })
936 }
937}
938
939#[derive(Debug, Clone, Copy, PartialEq)]
941pub struct SetVIDVerificationStatementFields<'a> {
942 pub vendor_id: Option<crate::msg::VendorId>,
944 pub vid_verification_statement: Option<&'a [u8]>,
946 pub vvsc: Option<&'a [u8]>,
948}
949
950impl<'a> ToTlv for SetVIDVerificationStatementFields<'a> {
951 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
952 w.start_structure(tag)?;
953 if let Some(value) = &self.vendor_id {
954 value.to_tlv(w, Tag::Context(0))?;
955 }
956 if let Some(value) = &self.vid_verification_statement {
957 value.to_tlv(w, Tag::Context(1))?;
958 }
959 if let Some(value) = &self.vvsc {
960 value.to_tlv(w, Tag::Context(2))?;
961 }
962 w.end_container()
963 }
964}
965
966impl<'a> FromTlv<'a> for SetVIDVerificationStatementFields<'a> {
967 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
968 if element.value.container() != Some(ContainerKind::Structure) {
969 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
970 }
971 let mut vendor_id = None;
972 let mut vid_verification_statement = None;
973 let mut vvsc = None;
974 loop {
975 let Some(field) = reader.next_element()? else {
976 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
977 };
978 if field.value == Value::EndOfContainer {
979 break;
980 }
981 match field.tag.context() {
982 Some(0) => vendor_id = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
983 Some(1) => vid_verification_statement = Some(<&'a [u8]>::from_tlv(reader, &field)?),
984 Some(2) => vvsc = Some(<&'a [u8]>::from_tlv(reader, &field)?),
985 _ => reader.skip_value(&field)?,
989 }
990 }
991 Ok(Self {
992 vendor_id,
993 vid_verification_statement,
994 vvsc,
995 })
996 }
997}
998
999#[derive(Debug, Clone, Copy, PartialEq)]
1001pub struct SignVIDVerificationRequestFields<'a> {
1002 pub fabric_index: crate::msg::FabricIndex,
1004 pub client_challenge: &'a [u8],
1006}
1007
1008impl<'a> ToTlv for SignVIDVerificationRequestFields<'a> {
1009 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1010 w.start_structure(tag)?;
1011 self.fabric_index.to_tlv(w, Tag::Context(0))?;
1012 self.client_challenge.to_tlv(w, Tag::Context(1))?;
1013 w.end_container()
1014 }
1015}
1016
1017impl<'a> FromTlv<'a> for SignVIDVerificationRequestFields<'a> {
1018 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1019 if element.value.container() != Some(ContainerKind::Structure) {
1020 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1021 }
1022 let mut fabric_index = None;
1023 let mut client_challenge = None;
1024 loop {
1025 let Some(field) = reader.next_element()? else {
1026 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1027 };
1028 if field.value == Value::EndOfContainer {
1029 break;
1030 }
1031 match field.tag.context() {
1032 Some(0) => {
1033 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
1034 }
1035 Some(1) => client_challenge = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1036 _ => reader.skip_value(&field)?,
1040 }
1041 }
1042 Ok(Self {
1043 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1044 client_challenge: client_challenge
1045 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1046 })
1047 }
1048}
1049
1050#[derive(Debug, Clone, Copy, PartialEq)]
1052pub struct SignVIDVerificationResponseFields<'a> {
1053 pub fabric_index: crate::msg::FabricIndex,
1055 pub fabric_binding_version: u8,
1057 pub signature: &'a [u8],
1059}
1060
1061impl<'a> ToTlv for SignVIDVerificationResponseFields<'a> {
1062 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1063 w.start_structure(tag)?;
1064 self.fabric_index.to_tlv(w, Tag::Context(0))?;
1065 self.fabric_binding_version.to_tlv(w, Tag::Context(1))?;
1066 self.signature.to_tlv(w, Tag::Context(2))?;
1067 w.end_container()
1068 }
1069}
1070
1071impl<'a> FromTlv<'a> for SignVIDVerificationResponseFields<'a> {
1072 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1073 if element.value.container() != Some(ContainerKind::Structure) {
1074 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1075 }
1076 let mut fabric_index = None;
1077 let mut fabric_binding_version = None;
1078 let mut signature = None;
1079 loop {
1080 let Some(field) = reader.next_element()? else {
1081 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1082 };
1083 if field.value == Value::EndOfContainer {
1084 break;
1085 }
1086 match field.tag.context() {
1087 Some(0) => {
1088 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
1089 }
1090 Some(1) => fabric_binding_version = Some(<u8>::from_tlv(reader, &field)?),
1091 Some(2) => signature = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1092 _ => reader.skip_value(&field)?,
1096 }
1097 }
1098 Ok(Self {
1099 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1100 fabric_binding_version: fabric_binding_version
1101 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1102 signature: signature.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1103 })
1104 }
1105}
1106
1107pub const ATTRIBUTES: &[Attribute] = &[
1109 Attribute {
1110 id: 0x0000,
1111 name: "NOCs",
1112 kind: "list[NOCStruct]",
1113 access: Access::read_only(Privilege::Administer)
1114 .with_qualities(AccessQualities::FABRIC_SCOPED),
1115 qualities: AttributeQualities::NON_VOLATILE,
1116 reporting: Reporting::ChangesOmitted,
1117 conform: Conform::MANDATORY,
1118 },
1119 Attribute {
1120 id: 0x0001,
1121 name: "Fabrics",
1122 kind: "list[FabricDescriptorStruct]",
1123 access: Access::read_only(Privilege::View).with_qualities(AccessQualities::FABRIC_SCOPED),
1124 qualities: AttributeQualities::NON_VOLATILE,
1125 reporting: Reporting::OnChange,
1126 conform: Conform::MANDATORY,
1127 },
1128 Attribute {
1129 id: 0x0002,
1130 name: "SupportedFabrics",
1131 kind: "uint8",
1132 access: Access::read_only(Privilege::View),
1133 qualities: AttributeQualities::FIXED,
1134 reporting: Reporting::OnChange,
1135 conform: Conform::MANDATORY,
1136 },
1137 Attribute {
1138 id: 0x0003,
1139 name: "CommissionedFabrics",
1140 kind: "uint8",
1141 access: Access::read_only(Privilege::View),
1142 qualities: AttributeQualities::NON_VOLATILE,
1143 reporting: Reporting::OnChange,
1144 conform: Conform::MANDATORY,
1145 },
1146 Attribute {
1147 id: 0x0004,
1148 name: "TrustedRootCertificates",
1149 kind: "list[octstr]",
1150 access: Access::read_only(Privilege::View),
1151 qualities: AttributeQualities::NON_VOLATILE,
1152 reporting: Reporting::ChangesOmitted,
1153 conform: Conform::MANDATORY,
1154 },
1155 Attribute {
1156 id: 0x0005,
1157 name: "CurrentFabricIndex",
1158 kind: "uint8",
1159 access: Access::read_only(Privilege::View),
1160 qualities: AttributeQualities::empty(),
1161 reporting: Reporting::OnChange,
1162 conform: Conform::MANDATORY,
1163 },
1164];
1165
1166pub const COMMANDS: &[Command] = &[
1168 Command {
1169 id: 0x00,
1170 name: "AttestationRequest",
1171 to_server: true,
1172 response: Some(0x01),
1173 access: Access::invoke(Privilege::Administer),
1174 conform: Conform::MANDATORY,
1175 },
1176 Command {
1177 id: 0x01,
1178 name: "AttestationResponse",
1179 to_server: false,
1180 response: None,
1181 access: Access::invoke(Privilege::Operate),
1182 conform: Conform::MANDATORY,
1183 },
1184 Command {
1185 id: 0x02,
1186 name: "CertificateChainRequest",
1187 to_server: true,
1188 response: Some(0x03),
1189 access: Access::invoke(Privilege::Administer),
1190 conform: Conform::MANDATORY,
1191 },
1192 Command {
1193 id: 0x03,
1194 name: "CertificateChainResponse",
1195 to_server: false,
1196 response: None,
1197 access: Access::invoke(Privilege::Operate),
1198 conform: Conform::MANDATORY,
1199 },
1200 Command {
1201 id: 0x04,
1202 name: "CSRRequest",
1203 to_server: true,
1204 response: Some(0x05),
1205 access: Access::invoke(Privilege::Administer),
1206 conform: Conform::MANDATORY,
1207 },
1208 Command {
1209 id: 0x05,
1210 name: "CSRResponse",
1211 to_server: false,
1212 response: None,
1213 access: Access::invoke(Privilege::Operate),
1214 conform: Conform::MANDATORY,
1215 },
1216 Command {
1217 id: 0x06,
1218 name: "AddNOC",
1219 to_server: true,
1220 response: Some(0x08),
1221 access: Access::invoke(Privilege::Administer),
1222 conform: Conform::MANDATORY,
1223 },
1224 Command {
1225 id: 0x07,
1226 name: "UpdateNOC",
1227 to_server: true,
1228 response: Some(0x08),
1229 access: Access::invoke(Privilege::Administer)
1230 .with_qualities(AccessQualities::FABRIC_SCOPED),
1231 conform: Conform::MANDATORY,
1232 },
1233 Command {
1234 id: 0x08,
1235 name: "NOCResponse",
1236 to_server: false,
1237 response: None,
1238 access: Access::invoke(Privilege::Operate),
1239 conform: Conform::MANDATORY,
1240 },
1241 Command {
1242 id: 0x09,
1243 name: "UpdateFabricLabel",
1244 to_server: true,
1245 response: Some(0x08),
1246 access: Access::invoke(Privilege::Administer)
1247 .with_qualities(AccessQualities::FABRIC_SCOPED),
1248 conform: Conform::MANDATORY,
1249 },
1250 Command {
1251 id: 0x0A,
1252 name: "RemoveFabric",
1253 to_server: true,
1254 response: Some(0x08),
1255 access: Access::invoke(Privilege::Administer),
1256 conform: Conform::MANDATORY,
1257 },
1258 Command {
1259 id: 0x0B,
1260 name: "AddTrustedRootCertificate",
1261 to_server: true,
1262 response: None,
1263 access: Access::invoke(Privilege::Administer),
1264 conform: Conform::MANDATORY,
1265 },
1266 Command {
1267 id: 0x0C,
1268 name: "SetVIDVerificationStatement",
1269 to_server: true,
1270 response: None,
1271 access: Access::invoke(Privilege::Administer)
1272 .with_qualities(AccessQualities::FABRIC_SCOPED),
1273 conform: Conform::MANDATORY,
1274 },
1275 Command {
1276 id: 0x0D,
1277 name: "SignVIDVerificationRequest",
1278 to_server: true,
1279 response: Some(0x0E),
1280 access: Access::invoke(Privilege::Administer),
1281 conform: Conform::MANDATORY,
1282 },
1283 Command {
1284 id: 0x0E,
1285 name: "SignVIDVerificationResponse",
1286 to_server: false,
1287 response: None,
1288 access: Access::invoke(Privilege::Operate),
1289 conform: Conform::MANDATORY,
1290 },
1291];
1292
1293pub const EVENTS: &[Event] = &[];
1295
1296pub const CLUSTER: Cluster = Cluster {
1298 id: ID,
1299 name: "Operational Credentials",
1300 revision: REVISION,
1301 pics: "OPCREDS",
1302 derived_from: None,
1303 features: FEATURES,
1304 attributes: ATTRIBUTES,
1305 commands: COMMANDS,
1306 events: EVENTS,
1307};