#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
pub const ID: ClusterId = 0x0801;
pub const REVISION: u16 = 1;
pub const PICS: &str = "TLSCERT";
pub const FEATURES: &[Feature] = &[];
pub mod attribute {
use crate::im::AttributeId;
pub const MAX_ROOT_CERTIFICATES: AttributeId = 0x00;
pub const PROVISIONED_ROOT_CERTIFICATES: AttributeId = 0x01;
pub const MAX_CLIENT_CERTIFICATES: AttributeId = 0x02;
pub const PROVISIONED_CLIENT_CERTIFICATES: AttributeId = 0x03;
}
pub mod command {
use crate::im::CommandId;
pub const PROVISION_ROOT_CERTIFICATE: CommandId = 0x00;
pub const PROVISION_ROOT_CERTIFICATE_RESPONSE: CommandId = 0x01;
pub const FIND_ROOT_CERTIFICATE: CommandId = 0x02;
pub const FIND_ROOT_CERTIFICATE_RESPONSE: CommandId = 0x03;
pub const LOOKUP_ROOT_CERTIFICATE: CommandId = 0x04;
pub const LOOKUP_ROOT_CERTIFICATE_RESPONSE: CommandId = 0x05;
pub const REMOVE_ROOT_CERTIFICATE: CommandId = 0x06;
pub const CLIENT_CSR: CommandId = 0x07;
pub const CLIENT_CSR_RESPONSE: CommandId = 0x08;
pub const PROVISION_CLIENT_CERTIFICATE: CommandId = 0x09;
pub const FIND_CLIENT_CERTIFICATE: CommandId = 0x0A;
pub const FIND_CLIENT_CERTIFICATE_RESPONSE: CommandId = 0x0B;
pub const LOOKUP_CLIENT_CERTIFICATE: CommandId = 0x0C;
pub const LOOKUP_CLIENT_CERTIFICATE_RESPONSE: CommandId = 0x0D;
pub const REMOVE_CLIENT_CERTIFICATE: CommandId = 0x0E;
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TLSCertStruct<'a> {
pub caid: u16,
pub certificate: Option<&'a [u8]>,
pub fabric_index: crate::msg::FabricIndex,
}
impl<'a> ToTlv for TLSCertStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.caid.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.certificate {
value.to_tlv(w, Tag::Context(1))?;
}
self.fabric_index.to_tlv(w, Tag::Context(254))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for TLSCertStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut caid = None;
let mut certificate = None;
let mut fabric_index = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => caid = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => certificate = Some(<&'a [u8]>::from_tlv(reader, &field)?),
Some(254) => {
fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
certificate,
fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TLSClientCertificateDetailStruct<'a> {
pub ccdid: u16,
pub client_certificate: Option<Nullable<&'a [u8]>>,
pub intermediate_certificates: Option<TlvList<'a, &'a [u8]>>,
pub fabric_index: crate::msg::FabricIndex,
}
impl<'a> ToTlv for TLSClientCertificateDetailStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.ccdid.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.client_certificate {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.intermediate_certificates {
value.to_tlv(w, Tag::Context(2))?;
}
self.fabric_index.to_tlv(w, Tag::Context(254))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for TLSClientCertificateDetailStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut ccdid = None;
let mut client_certificate = None;
let mut intermediate_certificates = None;
let mut fabric_index = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => ccdid = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => {
client_certificate = Some(<Nullable<&'a [u8]>>::from_tlv(reader, &field)?)
}
Some(2) => {
intermediate_certificates =
Some(<TlvList<'a, &'a [u8]>>::from_tlv(reader, &field)?)
}
Some(254) => {
fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
client_certificate,
intermediate_certificates,
fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProvisionRootCertificateFields<'a> {
pub certificate: &'a [u8],
pub caid: Nullable<u16>,
}
impl<'a> ToTlv for ProvisionRootCertificateFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.certificate.to_tlv(w, Tag::Context(0))?;
self.caid.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ProvisionRootCertificateFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut certificate = None;
let mut caid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => certificate = Some(<&'a [u8]>::from_tlv(reader, &field)?),
Some(1) => caid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
certificate: certificate.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProvisionRootCertificateResponseFields {
pub caid: u16,
}
impl ToTlv for ProvisionRootCertificateResponseFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.caid.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ProvisionRootCertificateResponseFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut caid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => caid = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FindRootCertificateFields {
pub caid: Nullable<u16>,
}
impl ToTlv for FindRootCertificateFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.caid.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for FindRootCertificateFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut caid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => caid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FindRootCertificateResponseFields<'a> {
pub certificate_details: TlvList<'a, TLSCertStruct<'a>>,
}
impl<'a> ToTlv for FindRootCertificateResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.certificate_details.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for FindRootCertificateResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut certificate_details = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => {
certificate_details =
Some(<TlvList<'a, TLSCertStruct<'a>>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
certificate_details: certificate_details
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LookupRootCertificateFields<'a> {
pub fingerprint: &'a [u8],
}
impl<'a> ToTlv for LookupRootCertificateFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.fingerprint.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for LookupRootCertificateFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut fingerprint = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => fingerprint = Some(<&'a [u8]>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
fingerprint: fingerprint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LookupRootCertificateResponseFields {
pub caid: u16,
}
impl ToTlv for LookupRootCertificateResponseFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.caid.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for LookupRootCertificateResponseFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut caid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => caid = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RemoveRootCertificateFields {
pub caid: u16,
}
impl ToTlv for RemoveRootCertificateFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.caid.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for RemoveRootCertificateFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut caid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => caid = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
caid: caid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ClientCSRFields<'a> {
pub nonce: &'a [u8],
pub ccdid: Nullable<u16>,
}
impl<'a> ToTlv for ClientCSRFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.nonce.to_tlv(w, Tag::Context(0))?;
self.ccdid.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ClientCSRFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut nonce = None;
let mut ccdid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => nonce = Some(<&'a [u8]>::from_tlv(reader, &field)?),
Some(1) => ccdid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
nonce: nonce.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ClientCSRResponseFields<'a> {
pub ccdid: u16,
pub csr: &'a [u8],
pub nonce_signature: &'a [u8],
}
impl<'a> ToTlv for ClientCSRResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.ccdid.to_tlv(w, Tag::Context(0))?;
self.csr.to_tlv(w, Tag::Context(1))?;
self.nonce_signature.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ClientCSRResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut ccdid = None;
let mut csr = None;
let mut nonce_signature = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => ccdid = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => csr = Some(<&'a [u8]>::from_tlv(reader, &field)?),
Some(2) => nonce_signature = Some(<&'a [u8]>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
csr: csr.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
nonce_signature: nonce_signature
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProvisionClientCertificateFields<'a> {
pub ccdid: u16,
pub client_certificate: &'a [u8],
pub intermediate_certificates: TlvList<'a, &'a [u8]>,
}
impl<'a> ToTlv for ProvisionClientCertificateFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.ccdid.to_tlv(w, Tag::Context(0))?;
self.client_certificate.to_tlv(w, Tag::Context(1))?;
self.intermediate_certificates.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ProvisionClientCertificateFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut ccdid = None;
let mut client_certificate = None;
let mut intermediate_certificates = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => ccdid = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => client_certificate = Some(<&'a [u8]>::from_tlv(reader, &field)?),
Some(2) => {
intermediate_certificates =
Some(<TlvList<'a, &'a [u8]>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
client_certificate: client_certificate
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
intermediate_certificates: intermediate_certificates
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FindClientCertificateFields {
pub ccdid: Nullable<u16>,
}
impl ToTlv for FindClientCertificateFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.ccdid.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for FindClientCertificateFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut ccdid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => ccdid = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FindClientCertificateResponseFields<'a> {
pub certificate_details: TlvList<'a, TLSClientCertificateDetailStruct<'a>>,
}
impl<'a> ToTlv for FindClientCertificateResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.certificate_details.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for FindClientCertificateResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut certificate_details = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => {
certificate_details = Some(
<TlvList<'a, TLSClientCertificateDetailStruct<'a>>>::from_tlv(
reader, &field,
)?,
)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
certificate_details: certificate_details
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LookupClientCertificateFields<'a> {
pub fingerprint: &'a [u8],
}
impl<'a> ToTlv for LookupClientCertificateFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.fingerprint.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for LookupClientCertificateFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut fingerprint = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => fingerprint = Some(<&'a [u8]>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
fingerprint: fingerprint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LookupClientCertificateResponseFields {
pub ccdid: u16,
}
impl ToTlv for LookupClientCertificateResponseFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.ccdid.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for LookupClientCertificateResponseFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut ccdid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => ccdid = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RemoveClientCertificateFields {
pub ccdid: u16,
}
impl ToTlv for RemoveClientCertificateFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.ccdid.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for RemoveClientCertificateFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut ccdid = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => ccdid = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
ccdid: ccdid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "MaxRootCertificates",
kind: "uint8",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::FIXED,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "ProvisionedRootCertificates",
kind: "list[TLSCertStruct]",
access: Access::read_only(Privilege::View)
.with_qualities(AccessQualities::FABRIC_SENSITIVE),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0002,
name: "MaxClientCertificates",
kind: "uint8",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::FIXED,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0003,
name: "ProvisionedClientCertificates",
kind: "list[TLSClientCertificateDetailStruct]",
access: Access::read_only(Privilege::View)
.with_qualities(AccessQualities::FABRIC_SENSITIVE),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "ProvisionRootCertificate",
to_server: true,
response: Some(0x01),
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "ProvisionRootCertificateResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x02,
name: "FindRootCertificate",
to_server: true,
response: Some(0x03),
access: Access::invoke(Privilege::Operate)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x03,
name: "FindRootCertificateResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x04,
name: "LookupRootCertificate",
to_server: true,
response: Some(0x05),
access: Access::invoke(Privilege::Operate)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x05,
name: "LookupRootCertificateResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x06,
name: "RemoveRootCertificate",
to_server: true,
response: None,
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x07,
name: "ClientCSR",
to_server: true,
response: Some(0x08),
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x08,
name: "ClientCSRResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x09,
name: "ProvisionClientCertificate",
to_server: true,
response: None,
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x0A,
name: "FindClientCertificate",
to_server: true,
response: Some(0x0B),
access: Access::invoke(Privilege::Operate)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x0B,
name: "FindClientCertificateResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x0C,
name: "LookupClientCertificate",
to_server: true,
response: Some(0x0D),
access: Access::invoke(Privilege::Operate)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
Command {
id: 0x0D,
name: "LookupClientCertificateResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
conform: Conform::MANDATORY,
},
Command {
id: 0x0E,
name: "RemoveClientCertificate",
to_server: true,
response: None,
access: Access::invoke(Privilege::Administer)
.with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
conform: Conform::MANDATORY,
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "TLS Certificate Management",
revision: REVISION,
pics: "TLSCERT",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};