diff --git a/Generator/ClassGenerator.cs b/Generator/ClassGenerator.cs index fed0123..03096df 100644 --- a/Generator/ClassGenerator.cs +++ b/Generator/ClassGenerator.cs @@ -42,7 +42,7 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer) if (child.Type != DataType.Structure) writer.WriteLine($"{indent} {(child.Optional? "public" : "public required")} {GetType(child)}{((child.Nullable || child.Optional) ? "?" : "")} {child.Name} {{ get; set; }} "); } - writer.WriteLine($"\r\n{indent} /// \r\n{indent} [SetsRequiredMembers]\r\n{indent} public {tag.Name}(TLVReader reader, long structNumber = -1) {{"); + writer.WriteLine($"\r\n{indent} [SetsRequiredMembers]\r\n{indent} internal {tag.Name}(TLVReader reader, long structNumber = -1) {{"); if (tag.Type == DataType.List) writer.WriteLine($"{indent} reader.StartList(structNumber);"); else if (tag.Type != DataType.Choice) @@ -109,10 +109,42 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer) writer.WriteLine($"{totalIndent}{child.Name} = reader.GetDouble({child.TagNumber}{(child.Nullable ? ", true)" : ")")}{(!child.Nullable && !child.Optional ? "!.Value;" : ";")}"); break; case DataType.Bytes: - writer.WriteLine($"{totalIndent}{child.Name} = reader.GetBytes({child.TagNumber}{(child.Nullable ? ", true)" : ")")}{(!child.Nullable && !child.Optional ? "!;" : ";")}"); + writer.Write($"{totalIndent}{child.Name} = reader.GetBytes({child.TagNumber}"); + if (child.Nullable) + writer.Write(", true"); + else if (child.Max != 0 || child.Min != 0) + writer.Write(", false"); + if (child.Max != 0) + writer.Write($", {child.Max}"); + if (child.Min != 0) + { + if (child.Max == 0) + writer.Write(", int.MaxValue"); + writer.Write($", {child.Min}"); + } + if (!child.Nullable && !child.Optional) + writer.WriteLine(")!;"); + else + writer.WriteLine(");"); break; case DataType.String: - writer.WriteLine($"{totalIndent}{child.Name} = reader.GetString({child.TagNumber}{(child.Nullable ? ", true)" : ")")}{(!child.Nullable && !child.Optional ? "!;" : ";")}"); + writer.Write($"{totalIndent}{child.Name} = reader.GetString({child.TagNumber}"); + if (child.Nullable) + writer.Write(", true"); + else if (child.Max != 0 || child.Min != 0) + writer.Write(", false"); + if (child.Max != 0) + writer.Write($", {child.Max}"); + if (child.Min != 0) + { + if (child.Max == 0) + writer.Write(", int.MaxValue"); + writer.Write($", {child.Min}"); + } + if (!child.Nullable && !child.Optional) + writer.WriteLine(")!;"); + else + writer.WriteLine(");"); break; case DataType.Any: writer.WriteLine($"{totalIndent}{child.Name} = reader.GetAny({child.TagNumber}{(child.Nullable ? ", true)" : ")")}{(!child.Nullable && !child.Optional ? "!;" : ";")}"); @@ -125,7 +157,7 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer) } if (tag.Type != DataType.Choice) writer.WriteLine($"{indent} reader.EndContainer();"); - writer.WriteLine($"{indent} }}\r\n\r\n{indent} /// \r\n{indent} public override void Serialize(TLVWriter writer, long structNumber = -1) {{"); + writer.WriteLine($"{indent} }}\r\n\r\n{indent} internal override void Serialize(TLVWriter writer, long structNumber = -1) {{"); if (tag.Type == DataType.List) writer.WriteLine($"{indent} writer.StartList(structNumber);"); else if (tag.Type != DataType.Choice) @@ -143,6 +175,14 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer) { case DataType.Array: writer.WriteLine($"{totalIndent}{{"); + if (child.Min != 0 || child.Max != 0) + { + writer.Write($"{totalIndent} Constrain({child.Name}, {child.Min}"); + if (child.Max != 0) + writer.WriteLine($", {child.Max});"); + else + writer.WriteLine(");"); + } writer.WriteLine($"{totalIndent} writer.StartArray({child.TagNumber});"); writer.WriteLine($"{totalIndent} foreach (var item in {child.Name}) {{"); writer.WriteLine($"{totalIndent} {GetWriter(GetEnumerationType(child), GetEnumerationIndex(child))};"); @@ -152,6 +192,14 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer) break; case DataType.List: writer.WriteLine($"{totalIndent}{{"); + if (child.Min != 0 || child.Max != 0) + { + writer.Write($"{totalIndent} Constrain({child.Name}, {child.Min}"); + if (child.Max != 0) + writer.WriteLine($", {child.Max});"); + else + writer.WriteLine(");"); + } writer.WriteLine($"{totalIndent} writer.StartList({child.TagNumber});"); writer.WriteLine($"{totalIndent} foreach (var item in {child.Name}) {{"); writer.WriteLine($"{totalIndent} {GetWriter(GetEnumerationType(child), GetEnumerationIndex(child))};"); @@ -189,10 +237,30 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer) writer.WriteLine($"{totalIndent}writer.WriteDouble({child.TagNumber}, {child.Name});"); break; case DataType.Bytes: - writer.WriteLine($"{totalIndent}writer.WriteBytes({child.TagNumber}, {child.Name});"); + writer.Write($"{totalIndent}writer.WriteBytes({child.TagNumber}, {child.Name}"); + if (child.Max != 0) + writer.Write($", {child.Max}"); + if (child.Min != 0) + { + if (child.Max == 0) + writer.Write($", int.MaxValue, {child.Min}"); + else + writer.Write($", {child.Min}"); + } + writer.WriteLine(");"); break; case DataType.String: - writer.WriteLine($"{totalIndent}writer.WriteString({child.TagNumber}, {child.Name});"); + writer.Write($"{totalIndent}writer.WriteString({child.TagNumber}, {child.Name}"); + if (child.Max != 0) + writer.Write($", {child.Max}"); + if (child.Min != 0) + { + if (child.Max == 0) + writer.Write($", int.MaxValue, {child.Min}"); + else + writer.Write($", {child.Min}"); + } + writer.WriteLine(");"); break; case DataType.Any: writer.WriteLine($"{totalIndent}writer.WriteAny({child.TagNumber}, {child.Name});"); diff --git a/Generator/ClusterGenerator.cs b/Generator/ClusterGenerator.cs index 9acee94..5d0d045 100644 --- a/Generator/ClusterGenerator.cs +++ b/Generator/ClusterGenerator.cs @@ -168,13 +168,13 @@ private static void WriteStruct(clusterCommand command, bool toServer, StreamWri } if (toServer) { - writer.WriteLine(" public override void Serialize(TLVWriter writer, long structNumber = -1) {"); + writer.WriteLine(" internal override void Serialize(TLVWriter writer, long structNumber = -1) {"); writer.WriteLine(" writer.StartStructure(structNumber);"); foreach (clusterCommandField field in command.field) { if (field.type == null || field.disallowConform != null) //Reserved/removed fields continue; - WriteStructType(field.optionalConform != null, field.type, field.id, (field.name == GeneratorUtil.SanitizeName(command.name) ? field.name + "Field" : field.name), cluster, writer); + WriteStructType(field.optionalConform != null, field.type, field.id, field.constraint?.fromSpecified == true ? field.constraint.from : null, field.constraint?.toSpecified == true ? field.constraint.to : null, (field.name == GeneratorUtil.SanitizeName(command.name) ? field.name + "Field" : field.name), cluster, writer); } writer.WriteLine(" writer.EndContainer();"); writer.WriteLine(" }"); @@ -182,7 +182,7 @@ private static void WriteStruct(clusterCommand command, bool toServer, StreamWri writer.WriteLine(" }"); } - private static void WriteStructType(bool optional, string type, byte id, string name, Cluster cluster, StreamWriter writer) + private static void WriteStructType(bool optional, string type, byte id, int? from, int? to, string name, Cluster cluster, StreamWriter writer) { string totalIndent = " "; if (optional) @@ -291,10 +291,10 @@ private static void WriteStructType(bool optional, string type, byte id, string case "ref_Ipv6Adr": case "ipv6pre": case "Hardware Address": - writer.WriteLine($"{totalIndent}writer.WriteBytes({id}, {name});"); + writer.WriteLine($"{totalIndent}writer.WriteBytes({id}, {name}{(to != null ? $", {to.Value});" : ");")}"); break; case "string": - writer.WriteLine($"{totalIndent}writer.WriteString({id}, {name});"); + writer.WriteLine($"{totalIndent}writer.WriteString({id}, {name}{(to != null ? $", {to.Value});" : ");")}"); break; default: if (HasEnum(cluster, type)) @@ -443,10 +443,10 @@ private static void WriteStruct(clusterDataTypesStruct structType, Cluster clust else writer.WriteLine(); } - writer.WriteLine(" public override void Serialize(TLVWriter writer, long structNumber = -1) {"); + writer.WriteLine(" internal override void Serialize(TLVWriter writer, long structNumber = -1) {"); writer.WriteLine(" writer.StartStructure(structNumber);"); foreach (clusterDataTypesStructField field in structType.field) - WriteStructType(field.@default != null, field.type, field.id, (field.name == GeneratorUtil.SanitizeName(structType.name) ? field.name + "Field" : field.name), cluster, writer); + WriteStructType(field.@default != null, field.type, field.id, field.constraint?.fromSpecified == true ? field.constraint.from : null, field.constraint?.toSpecified == true ? field.constraint.to : null, (field.name == GeneratorUtil.SanitizeName(structType.name) ? field.name + "Field" : field.name), cluster, writer); writer.WriteLine(" writer.EndContainer();"); writer.WriteLine(" }"); writer.WriteLine(" }"); diff --git a/Generator/Schema/Cluster.cs b/Generator/Schema/Cluster.cs index 70b4eeb..1052f93 100644 --- a/Generator/Schema/Cluster.cs +++ b/Generator/Schema/Cluster.cs @@ -12,7 +12,7 @@ namespace Generator.Schema { - // NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0. + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. /// [System.SerializableAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] @@ -822,6 +822,10 @@ public bool nullable [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] public partial class clusterDataTypesStructFieldConstraint { + private int toField; + private int fromField; + private bool fromFieldSpecified; + private bool toFieldSpecified; private string typeField; @@ -829,6 +833,62 @@ public partial class clusterDataTypesStructFieldConstraint private bool valueFieldSpecified; + /// + [System.Xml.Serialization.XmlAttributeAttribute()] + public int from + { + get + { + return this.fromField; + } + set + { + this.fromField = value; + } + } + + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + public bool fromSpecified + { + get + { + return this.fromFieldSpecified; + } + set + { + this.fromFieldSpecified = value; + } + } + + /// + [System.Xml.Serialization.XmlAttributeAttribute()] + public int to + { + get + { + return this.toField; + } + set + { + this.toField = value; + } + } + + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + public bool toSpecified + { + get + { + return this.toFieldSpecified; + } + set + { + this.toFieldSpecified = value; + } + } + /// [System.Xml.Serialization.XmlAttributeAttribute()] public string type @@ -1684,7 +1744,7 @@ public bool fabricScopedSpecified [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] public partial class clusterCommandField { - private clusterCommandFieldQuality qualityField; + private clusterCommandFieldQuality? qualityField; private object optionalConformField; @@ -1956,4 +2016,5 @@ public bool toSpecified } } } + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. } diff --git a/MatterDotNet/Clusters/AdministratorCommissioningCluster.cs b/MatterDotNet/Clusters/AdministratorCommissioningCluster.cs index 527ebd7..5499b34 100644 --- a/MatterDotNet/Clusters/AdministratorCommissioningCluster.cs +++ b/MatterDotNet/Clusters/AdministratorCommissioningCluster.cs @@ -59,7 +59,7 @@ private record OpenCommissioningWindowPayload : TLVPayload { public required ushort Discriminator { get; set; } public required uint Iterations { get; set; } public required byte[] Salt { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, CommissioningTimeout); writer.WriteBytes(1, PAKEPasscodeVerifier); @@ -72,7 +72,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { private record OpenBasicCommissioningWindowPayload : TLVPayload { public required ushort CommissioningTimeout { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, CommissioningTimeout); writer.EndContainer(); diff --git a/MatterDotNet/Clusters/BasicInformationCluster.cs b/MatterDotNet/Clusters/BasicInformationCluster.cs index 8478c7d..6ffbb4c 100644 --- a/MatterDotNet/Clusters/BasicInformationCluster.cs +++ b/MatterDotNet/Clusters/BasicInformationCluster.cs @@ -155,7 +155,7 @@ public enum ProductFinishEnum { public record CapabilityMinima : TLVPayload { public ushort? CaseSessionsPerFabric { get; set; } = 3; public ushort? SubscriptionsPerFabric { get; set; } = 3; - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (CaseSessionsPerFabric != null) writer.WriteUShort(0, CaseSessionsPerFabric); @@ -168,7 +168,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { public record ProductAppearance : TLVPayload { public required ProductFinishEnum Finish { get; set; } public required ColorEnum PrimaryColor { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, (ushort)Finish); writer.WriteUShort(1, (ushort)PrimaryColor); diff --git a/MatterDotNet/Clusters/DescriptorCluster.cs b/MatterDotNet/Clusters/DescriptorCluster.cs index 559eb76..d189253 100644 --- a/MatterDotNet/Clusters/DescriptorCluster.cs +++ b/MatterDotNet/Clusters/DescriptorCluster.cs @@ -34,7 +34,7 @@ public DescriptorCluster(ushort endPoint) : base(endPoint) { } public record DeviceType : TLVPayload { public required uint DeviceTypeField { get; set; } public required ushort Revision { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUInt(0, DeviceTypeField); writer.WriteUShort(1, Revision); diff --git a/MatterDotNet/Clusters/GeneralCommissioningCluster.cs b/MatterDotNet/Clusters/GeneralCommissioningCluster.cs index cc82d02..b2ad884 100644 --- a/MatterDotNet/Clusters/GeneralCommissioningCluster.cs +++ b/MatterDotNet/Clusters/GeneralCommissioningCluster.cs @@ -82,7 +82,7 @@ public enum RegulatoryLocationTypeEnum { public record BasicCommissioningInfo : TLVPayload { public required ushort FailSafeExpiryLengthSeconds { get; set; } public required ushort MaxCumulativeFailsafeSeconds { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, FailSafeExpiryLengthSeconds); writer.WriteUShort(1, MaxCumulativeFailsafeSeconds); @@ -95,7 +95,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { private record ArmFailSafePayload : TLVPayload { public required ushort ExpiryLengthSeconds { get; set; } = 900; public required ulong Breadcrumb { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, ExpiryLengthSeconds); writer.WriteULong(1, Breadcrumb); @@ -112,7 +112,7 @@ private record SetRegulatoryConfigPayload : TLVPayload { public required RegulatoryLocationTypeEnum NewRegulatoryConfig { get; set; } public required string CountryCode { get; set; } public required ulong Breadcrumb { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, (ushort)NewRegulatoryConfig); writer.WriteString(1, CountryCode); diff --git a/MatterDotNet/Clusters/GeneralDiagnosticsCluster.cs b/MatterDotNet/Clusters/GeneralDiagnosticsCluster.cs index 98e3648..cfd6475 100644 --- a/MatterDotNet/Clusters/GeneralDiagnosticsCluster.cs +++ b/MatterDotNet/Clusters/GeneralDiagnosticsCluster.cs @@ -210,7 +210,7 @@ public record NetworkInterface : TLVPayload { public required List IPv4Addresses { get; set; } public required List IPv6Addresses { get; set; } public required InterfaceTypeEnum Type { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteString(0, Name); writer.WriteBool(1, IsOperational); @@ -241,7 +241,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { private record TestEventTriggerPayload : TLVPayload { public required byte[] EnableKey { get; set; } public required ulong EventTrigger { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(0, EnableKey); writer.WriteULong(1, EventTrigger); @@ -258,7 +258,7 @@ private record PayloadTestRequestPayload : TLVPayload { public required byte[] EnableKey { get; set; } public required byte Value { get; set; } public required ushort Count { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(0, EnableKey); writer.WriteByte(1, Value); diff --git a/MatterDotNet/Clusters/GroupKeyManagementCluster.cs b/MatterDotNet/Clusters/GroupKeyManagementCluster.cs index d4e6a25..40e9478 100644 --- a/MatterDotNet/Clusters/GroupKeyManagementCluster.cs +++ b/MatterDotNet/Clusters/GroupKeyManagementCluster.cs @@ -67,7 +67,7 @@ public record GroupInfoMap : TLVPayload { public required ushort GroupId { get; set; } public required List Endpoints { get; set; } public required string GroupName { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(1, GroupId); { @@ -84,7 +84,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { public record GroupKeyMap : TLVPayload { public required ushort GroupId { get; set; } public required ushort GroupKeySetID { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(1, GroupId); writer.WriteUShort(2, GroupKeySetID); @@ -102,7 +102,7 @@ public record GroupKeySet : TLVPayload { public required byte[] EpochKey2 { get; set; } public required ulong EpochStartTime2 { get; set; } public required GroupKeyMulticastPolicyEnum GroupKeyMulticastPolicy { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, GroupKeySetID); writer.WriteUShort(1, (ushort)GroupKeySecurityPolicy); @@ -121,7 +121,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { #region Payloads private record KeySetWriteCommandPayload : TLVPayload { public required GroupKeySet GroupKeySet { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); GroupKeySet.Serialize(writer, 0); writer.EndContainer(); @@ -130,7 +130,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { private record KeySetReadCommandPayload : TLVPayload { public required ushort GroupKeySetID { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, GroupKeySetID); writer.EndContainer(); @@ -143,7 +143,7 @@ public struct KeySetReadResponseCommand() { private record KeySetRemoveCommandPayload : TLVPayload { public required ushort GroupKeySetID { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, GroupKeySetID); writer.EndContainer(); @@ -151,7 +151,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { } private record KeySetReadAllIndicesCommandPayload : TLVPayload { - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.EndContainer(); } diff --git a/MatterDotNet/Clusters/NodeOperationalCredentialsCluster.cs b/MatterDotNet/Clusters/NodeOperationalCredentialsCluster.cs index 9a91e5d..f8d4b7b 100644 --- a/MatterDotNet/Clusters/NodeOperationalCredentialsCluster.cs +++ b/MatterDotNet/Clusters/NodeOperationalCredentialsCluster.cs @@ -109,7 +109,7 @@ public record FabricDescriptor : TLVPayload { public required ulong FabricID { get; set; } public required ulong NodeID { get; set; } public string? Label { get; set; } = ""; - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, RootPublicKey); writer.WriteUShort(2, VendorID); @@ -124,7 +124,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { public record NOC : TLVPayload { public required byte[] NOCField { get; set; } public required byte[] ICAC { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, NOCField); writer.WriteBytes(2, ICAC); @@ -136,7 +136,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { #region Payloads private record AttestationRequestPayload : TLVPayload { public required byte[] AttestationNonce { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(0, AttestationNonce); writer.EndContainer(); @@ -150,7 +150,7 @@ public struct AttestationResponse() { private record CertificateChainRequestPayload : TLVPayload { public required CertificateChainTypeEnum CertificateType { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, (ushort)CertificateType); writer.EndContainer(); @@ -164,7 +164,7 @@ public struct CertificateChainResponse() { private record CSRRequestPayload : TLVPayload { public required byte[] CSRNonce { get; set; } public bool? IsForUpdateNOC { get; set; } = false; - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(0, CSRNonce); if (IsForUpdateNOC != null) @@ -184,7 +184,7 @@ private record AddNOCPayload : TLVPayload { public required byte[] IPKValue { get; set; } public required ulong CaseAdminSubject { get; set; } public required ushort AdminVendorId { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(0, NOCValue); if (ICACValue != null) @@ -199,7 +199,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { private record UpdateNOCPayload : TLVPayload { public required byte[] NOCValue { get; set; } public byte[]? ICACValue { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(0, NOCValue); if (ICACValue != null) @@ -216,7 +216,7 @@ public struct NOCResponse() { private record UpdateFabricLabelPayload : TLVPayload { public required string Label { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteString(0, Label); writer.EndContainer(); @@ -225,7 +225,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { private record RemoveFabricPayload : TLVPayload { public required byte FabricIndex { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteByte(0, FabricIndex); writer.EndContainer(); @@ -234,7 +234,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { private record AddTrustedRootCertificatePayload : TLVPayload { public required byte[] RootCACertificate { get; set; } - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(0, RootCACertificate); writer.EndContainer(); diff --git a/MatterDotNet/Messages/CASE/Sigma1.cs b/MatterDotNet/Messages/CASE/Sigma1.cs index 3bc63b2..e93afd5 100644 --- a/MatterDotNet/Messages/CASE/Sigma1.cs +++ b/MatterDotNet/Messages/CASE/Sigma1.cs @@ -38,34 +38,34 @@ public Sigma1(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma1(TLVReader reader, long structNumber = -1) { + internal Sigma1(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - InitiatorRandom = reader.GetBytes(1)!; + InitiatorRandom = reader.GetBytes(1, false, 32, 32)!; InitiatorSessionId = reader.GetUShort(2)!.Value; - DestinationId = reader.GetBytes(3)!; - InitiatorEphPubKey = reader.GetBytes(4)!; + DestinationId = reader.GetBytes(3, false, 32, 32)!; + InitiatorEphPubKey = reader.GetBytes(4, false, 65, 65)!; if (reader.IsTag(5)) InitiatorSessionParams = new SessionParameter(reader, 5); if (reader.IsTag(6)) - ResumptionID = reader.GetBytes(6); + ResumptionID = reader.GetBytes(6, false, 16, 16); if (reader.IsTag(7)) - InitiatorResumeMIC = reader.GetBytes(7); + InitiatorResumeMIC = reader.GetBytes(7, false, 16, 16); reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, InitiatorRandom); + writer.WriteBytes(1, InitiatorRandom, 32, 32); writer.WriteUShort(2, InitiatorSessionId); - writer.WriteBytes(3, DestinationId); - writer.WriteBytes(4, InitiatorEphPubKey); + writer.WriteBytes(3, DestinationId, 32, 32); + writer.WriteBytes(4, InitiatorEphPubKey, 65, 65); if (InitiatorSessionParams != null) InitiatorSessionParams.Serialize(writer, 5); if (ResumptionID != null) - writer.WriteBytes(6, ResumptionID); + writer.WriteBytes(6, ResumptionID, 16, 16); if (InitiatorResumeMIC != null) - writer.WriteBytes(7, InitiatorResumeMIC); + writer.WriteBytes(7, InitiatorResumeMIC, 16, 16); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/CASE/Sigma2.cs b/MatterDotNet/Messages/CASE/Sigma2.cs index 1436c6c..a320cab 100644 --- a/MatterDotNet/Messages/CASE/Sigma2.cs +++ b/MatterDotNet/Messages/CASE/Sigma2.cs @@ -36,11 +36,11 @@ public Sigma2(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma2(TLVReader reader, long structNumber = -1) { + internal Sigma2(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - ResponderRandom = reader.GetBytes(1)!; + ResponderRandom = reader.GetBytes(1, false, 32, 32)!; ResponderSessionId = reader.GetUShort(2)!.Value; - ResponderEphPubKey = reader.GetBytes(3)!; + ResponderEphPubKey = reader.GetBytes(3, false, 65, 65)!; Encrypted2 = reader.GetBytes(4)!; if (reader.IsTag(5)) ResponderSessionParams = new SessionParameter(reader, 5); @@ -48,11 +48,11 @@ public Sigma2(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, ResponderRandom); + writer.WriteBytes(1, ResponderRandom, 32, 32); writer.WriteUShort(2, ResponderSessionId); - writer.WriteBytes(3, ResponderEphPubKey); + writer.WriteBytes(3, ResponderEphPubKey, 65, 65); writer.WriteBytes(4, Encrypted2); if (ResponderSessionParams != null) ResponderSessionParams.Serialize(writer, 5); diff --git a/MatterDotNet/Messages/CASE/Sigma2Resume.cs b/MatterDotNet/Messages/CASE/Sigma2Resume.cs index eaeed3d..702e44e 100644 --- a/MatterDotNet/Messages/CASE/Sigma2Resume.cs +++ b/MatterDotNet/Messages/CASE/Sigma2Resume.cs @@ -35,10 +35,10 @@ public Sigma2Resume(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma2Resume(TLVReader reader, long structNumber = -1) { + internal Sigma2Resume(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - ResumptionID = reader.GetBytes(1)!; - Sigma2ResumeMIC = reader.GetBytes(2)!; + ResumptionID = reader.GetBytes(1, false, 16, 16)!; + Sigma2ResumeMIC = reader.GetBytes(2, false, 16, 16)!; ResponderSessionID = reader.GetUShort(3)!.Value; if (reader.IsTag(4)) ResponderSessionParams = new SessionParameter(reader, 4); @@ -46,10 +46,10 @@ public Sigma2Resume(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, ResumptionID); - writer.WriteBytes(2, Sigma2ResumeMIC); + writer.WriteBytes(1, ResumptionID, 16, 16); + writer.WriteBytes(2, Sigma2ResumeMIC, 16, 16); writer.WriteUShort(3, ResponderSessionID); if (ResponderSessionParams != null) ResponderSessionParams.Serialize(writer, 4); diff --git a/MatterDotNet/Messages/CASE/Sigma2Tbedata.cs b/MatterDotNet/Messages/CASE/Sigma2Tbedata.cs index 3505664..9c60388 100644 --- a/MatterDotNet/Messages/CASE/Sigma2Tbedata.cs +++ b/MatterDotNet/Messages/CASE/Sigma2Tbedata.cs @@ -34,24 +34,24 @@ public Sigma2Tbedata(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma2Tbedata(TLVReader reader, long structNumber = -1) { + internal Sigma2Tbedata(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); ResponderNOC = reader.GetBytes(1)!; if (reader.IsTag(2)) ResponderICAC = reader.GetBytes(2); - Signature = reader.GetBytes(3)!; - ResumptionID = reader.GetBytes(4)!; + Signature = reader.GetBytes(3, false, 64, 64)!; + ResumptionID = reader.GetBytes(4, false, 16, 16)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, ResponderNOC); if (ResponderICAC != null) writer.WriteBytes(2, ResponderICAC); - writer.WriteBytes(3, Signature); - writer.WriteBytes(4, ResumptionID); + writer.WriteBytes(3, Signature, 64, 64); + writer.WriteBytes(4, ResumptionID, 16, 16); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/CASE/Sigma2Tbsdata.cs b/MatterDotNet/Messages/CASE/Sigma2Tbsdata.cs index a64ba12..859eba6 100644 --- a/MatterDotNet/Messages/CASE/Sigma2Tbsdata.cs +++ b/MatterDotNet/Messages/CASE/Sigma2Tbsdata.cs @@ -34,24 +34,24 @@ public Sigma2Tbsdata(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma2Tbsdata(TLVReader reader, long structNumber = -1) { + internal Sigma2Tbsdata(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); ResponderNOC = reader.GetBytes(1)!; if (reader.IsTag(2)) ResponderICAC = reader.GetBytes(2); - ResponderEphPubKey = reader.GetBytes(3)!; - InitiatorEphPubKey = reader.GetBytes(4)!; + ResponderEphPubKey = reader.GetBytes(3, false, 65, 65)!; + InitiatorEphPubKey = reader.GetBytes(4, false, 65, 65)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, ResponderNOC); if (ResponderICAC != null) writer.WriteBytes(2, ResponderICAC); - writer.WriteBytes(3, ResponderEphPubKey); - writer.WriteBytes(4, InitiatorEphPubKey); + writer.WriteBytes(3, ResponderEphPubKey, 65, 65); + writer.WriteBytes(4, InitiatorEphPubKey, 65, 65); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/CASE/Sigma3.cs b/MatterDotNet/Messages/CASE/Sigma3.cs index 5463909..57416bd 100644 --- a/MatterDotNet/Messages/CASE/Sigma3.cs +++ b/MatterDotNet/Messages/CASE/Sigma3.cs @@ -31,14 +31,14 @@ public Sigma3(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma3(TLVReader reader, long structNumber = -1) { + internal Sigma3(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Encrypted3 = reader.GetBytes(1)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, Encrypted3); writer.EndContainer(); diff --git a/MatterDotNet/Messages/CASE/Sigma3Tbedata.cs b/MatterDotNet/Messages/CASE/Sigma3Tbedata.cs index d52b7a6..133a314 100644 --- a/MatterDotNet/Messages/CASE/Sigma3Tbedata.cs +++ b/MatterDotNet/Messages/CASE/Sigma3Tbedata.cs @@ -33,22 +33,22 @@ public Sigma3Tbedata(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma3Tbedata(TLVReader reader, long structNumber = -1) { + internal Sigma3Tbedata(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); InitiatorNOC = reader.GetBytes(1)!; if (reader.IsTag(2)) InitiatorICAC = reader.GetBytes(2); - Signature = reader.GetBytes(3)!; + Signature = reader.GetBytes(3, false, 64, 64)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, InitiatorNOC); if (InitiatorICAC != null) writer.WriteBytes(2, InitiatorICAC); - writer.WriteBytes(3, Signature); + writer.WriteBytes(3, Signature, 64, 64); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/CASE/Sigma3Tbsdata.cs b/MatterDotNet/Messages/CASE/Sigma3Tbsdata.cs index 766430c..73e8f31 100644 --- a/MatterDotNet/Messages/CASE/Sigma3Tbsdata.cs +++ b/MatterDotNet/Messages/CASE/Sigma3Tbsdata.cs @@ -34,24 +34,24 @@ public Sigma3Tbsdata(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Sigma3Tbsdata(TLVReader reader, long structNumber = -1) { + internal Sigma3Tbsdata(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); InitiatorNOC = reader.GetBytes(1)!; if (reader.IsTag(2)) InitiatorICAC = reader.GetBytes(2); - InitiatorEphPubKey = reader.GetBytes(3)!; - ResponderEphPubKey = reader.GetBytes(4)!; + InitiatorEphPubKey = reader.GetBytes(3, false, 65, 65)!; + ResponderEphPubKey = reader.GetBytes(4, false, 65, 65)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, InitiatorNOC); if (InitiatorICAC != null) writer.WriteBytes(2, InitiatorICAC); - writer.WriteBytes(3, InitiatorEphPubKey); - writer.WriteBytes(4, ResponderEphPubKey); + writer.WriteBytes(3, InitiatorEphPubKey, 65, 65); + writer.WriteBytes(4, ResponderEphPubKey, 65, 65); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/Certificates/AttestationElements.cs b/MatterDotNet/Messages/Certificates/AttestationElements.cs index dbdf9d7..362b73a 100644 --- a/MatterDotNet/Messages/Certificates/AttestationElements.cs +++ b/MatterDotNet/Messages/Certificates/AttestationElements.cs @@ -37,7 +37,7 @@ public AttestationElements(Memory data) : this(new TLVReader(data)) {} public AttestationElements(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Certification_declaration = reader.GetBytes(1)!; - Attestation_nonce = reader.GetBytes(2)!; + Attestation_nonce = reader.GetBytes(2, false, 32, 32)!; Timestamp = reader.GetUInt(3)!.Value; if (reader.IsTag(4)) Firmware_information = reader.GetBytes(4); @@ -45,10 +45,10 @@ public AttestationElements(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, Certification_declaration); - writer.WriteBytes(2, Attestation_nonce); + writer.WriteBytes(2, Attestation_nonce, 32, 32); writer.WriteUInt(3, Timestamp); if (Firmware_information != null) writer.WriteBytes(4, Firmware_information); diff --git a/MatterDotNet/Messages/Certificates/BasicConstraints.cs b/MatterDotNet/Messages/Certificates/BasicConstraints.cs index a287a4a..7054cf2 100644 --- a/MatterDotNet/Messages/Certificates/BasicConstraints.cs +++ b/MatterDotNet/Messages/Certificates/BasicConstraints.cs @@ -32,7 +32,7 @@ public BasicConstraints(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public BasicConstraints(TLVReader reader, long structNumber = -1) { + internal BasicConstraints(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); IsCa = reader.GetBool(1)!.Value; if (reader.IsTag(2)) @@ -41,7 +41,7 @@ public BasicConstraints(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBool(1, IsCa); if (PathLenConstraint != null) diff --git a/MatterDotNet/Messages/Certificates/CertificationElements.cs b/MatterDotNet/Messages/Certificates/CertificationElements.cs index c3dfc86..d3aeab1 100644 --- a/MatterDotNet/Messages/Certificates/CertificationElements.cs +++ b/MatterDotNet/Messages/Certificates/CertificationElements.cs @@ -42,7 +42,7 @@ public CertificationElements(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public CertificationElements(TLVReader reader, long structNumber = -1) { + internal CertificationElements(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Format_version = reader.GetUShort(0)!.Value; Vendor_id = reader.GetUShort(1)!.Value; @@ -56,7 +56,7 @@ public CertificationElements(TLVReader reader, long structNumber = -1) { Product_id_array = items.ToArray(); } Device_type_id = reader.GetUInt(3)!.Value; - Certificate_id = reader.GetString(4)!; + Certificate_id = reader.GetString(4, false, 19, 19)!; Security_level = reader.GetByte(5)!.Value; Security_information = reader.GetUShort(6)!.Value; Version_number = reader.GetUShort(7)!.Value; @@ -79,11 +79,12 @@ public CertificationElements(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, Format_version); writer.WriteUShort(1, Vendor_id); { + Constrain(Product_id_array, 1, 100); writer.StartArray(2); foreach (var item in Product_id_array) { writer.WriteUInt(-1, item); @@ -91,7 +92,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { writer.EndContainer(); } writer.WriteUInt(3, Device_type_id); - writer.WriteString(4, Certificate_id); + writer.WriteString(4, Certificate_id, 19, 19); writer.WriteByte(5, Security_level); writer.WriteUShort(6, Security_information); writer.WriteUShort(7, Version_number); @@ -102,6 +103,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { writer.WriteUShort(10, Dac_origin_product_id); if (Authorized_paa_list != null) { + Constrain(Authorized_paa_list, 1, 10); writer.StartArray(11); foreach (var item in Authorized_paa_list) { writer.WriteBytes(-1, item); diff --git a/MatterDotNet/Messages/Certificates/DnAttribute.cs b/MatterDotNet/Messages/Certificates/DnAttribute.cs index 1951f85..f2c42df 100644 --- a/MatterDotNet/Messages/Certificates/DnAttribute.cs +++ b/MatterDotNet/Messages/Certificates/DnAttribute.cs @@ -67,7 +67,7 @@ public DnAttribute(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public DnAttribute(TLVReader reader, long structNumber = -1) { + internal DnAttribute(TLVReader reader, long structNumber = -1) { if (reader.IsTag(1)) CommonName = reader.GetString(1); else if (reader.IsTag(2)) @@ -145,7 +145,7 @@ public DnAttribute(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { if (CommonName != null) writer.WriteString(1, CommonName); else if (Surname != null) diff --git a/MatterDotNet/Messages/Certificates/Extension.cs b/MatterDotNet/Messages/Certificates/Extension.cs index 49a5331..6589db2 100644 --- a/MatterDotNet/Messages/Certificates/Extension.cs +++ b/MatterDotNet/Messages/Certificates/Extension.cs @@ -36,7 +36,7 @@ public Extension(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Extension(TLVReader reader, long structNumber = -1) { + internal Extension(TLVReader reader, long structNumber = -1) { if (reader.IsTag(1)) BasicCnstr = new BasicConstraints(reader, 1); else if (reader.IsTag(2)) @@ -52,21 +52,22 @@ public Extension(TLVReader reader, long structNumber = -1) { ExtendedKeyUsage = items.ToArray(); } else if (reader.IsTag(4)) - SubjectKeyId = reader.GetBytes(4); + SubjectKeyId = reader.GetBytes(4, false, 20, 20); else if (reader.IsTag(5)) - AuthorityKeyId = reader.GetBytes(5); + AuthorityKeyId = reader.GetBytes(5, false, 20, 20); else if (reader.IsTag(6)) FutureExtension = reader.GetBytes(6); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { if (BasicCnstr != null) BasicCnstr.Serialize(writer, 1); else if (KeyUsage != null) writer.WriteUShort(2, KeyUsage); else if (ExtendedKeyUsage != null) { + Constrain(ExtendedKeyUsage, 1); writer.StartArray(3); foreach (var item in ExtendedKeyUsage) { writer.WriteUInt(-1, item); @@ -74,9 +75,9 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { writer.EndContainer(); } else if (SubjectKeyId != null) - writer.WriteBytes(4, SubjectKeyId); + writer.WriteBytes(4, SubjectKeyId, 20, 20); else if (AuthorityKeyId != null) - writer.WriteBytes(5, AuthorityKeyId); + writer.WriteBytes(5, AuthorityKeyId, 20, 20); else if (FutureExtension != null) writer.WriteBytes(6, FutureExtension); } diff --git a/MatterDotNet/Messages/Certificates/MatterCertificate.cs b/MatterDotNet/Messages/Certificates/MatterCertificate.cs index ed6b5bd..55251e7 100644 --- a/MatterDotNet/Messages/Certificates/MatterCertificate.cs +++ b/MatterDotNet/Messages/Certificates/MatterCertificate.cs @@ -41,9 +41,9 @@ public MatterCertificate(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public MatterCertificate(TLVReader reader, long structNumber = -1) { + internal MatterCertificate(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - SerialNum = reader.GetBytes(1)!; + SerialNum = reader.GetBytes(1, false, 20)!; SigAlgo = reader.GetULong(2)!.Value; { reader.StartList(3); @@ -79,11 +79,12 @@ public MatterCertificate(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, SerialNum); + writer.WriteBytes(1, SerialNum, 20); writer.WriteULong(2, SigAlgo); { + Constrain(Issuer, 1); writer.StartList(3); foreach (var item in Issuer) { item.Serialize(writer, -1); @@ -93,6 +94,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { writer.WriteUInt(4, NotBefore); writer.WriteUInt(5, NotAfter); { + Constrain(Subject, 1); writer.StartList(6); foreach (var item in Subject) { item.Serialize(writer, -1); @@ -103,6 +105,7 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { writer.WriteULong(8, EcCurveId); writer.WriteBytes(9, EcPubKey); { + Constrain(Extensions, 1); writer.StartList(10); foreach (var item in Extensions) { item.Serialize(writer, -1); diff --git a/MatterDotNet/Messages/Certificates/NocsrElements.cs b/MatterDotNet/Messages/Certificates/NocsrElements.cs index 7fc18ae..6c64883 100644 --- a/MatterDotNet/Messages/Certificates/NocsrElements.cs +++ b/MatterDotNet/Messages/Certificates/NocsrElements.cs @@ -35,10 +35,10 @@ public NocsrElements(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public NocsrElements(TLVReader reader, long structNumber = -1) { + internal NocsrElements(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Csr = reader.GetBytes(1)!; - CSRNonce = reader.GetBytes(2)!; + CSRNonce = reader.GetBytes(2, false, 32, 32)!; if (reader.IsTag(3)) Vendor_reserved1 = reader.GetBytes(3); if (reader.IsTag(4)) @@ -49,10 +49,10 @@ public NocsrElements(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBytes(1, Csr); - writer.WriteBytes(2, CSRNonce); + writer.WriteBytes(2, CSRNonce, 32, 32); if (Vendor_reserved1 != null) writer.WriteBytes(3, Vendor_reserved1); if (Vendor_reserved2 != null) diff --git a/MatterDotNet/Messages/InteractionModel/AttributeDataIB.cs b/MatterDotNet/Messages/InteractionModel/AttributeDataIB.cs index 2b74f4d..bce0195 100644 --- a/MatterDotNet/Messages/InteractionModel/AttributeDataIB.cs +++ b/MatterDotNet/Messages/InteractionModel/AttributeDataIB.cs @@ -33,7 +33,7 @@ public AttributeDataIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public AttributeDataIB(TLVReader reader, long structNumber = -1) { + internal AttributeDataIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); DataVersion = reader.GetUInt(0)!.Value; Path = new AttributePathIB(reader, 1); @@ -42,7 +42,7 @@ public AttributeDataIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUInt(0, DataVersion); Path.Serialize(writer, 1); diff --git a/MatterDotNet/Messages/InteractionModel/AttributePathIB.cs b/MatterDotNet/Messages/InteractionModel/AttributePathIB.cs index 6254b92..5e3a106 100644 --- a/MatterDotNet/Messages/InteractionModel/AttributePathIB.cs +++ b/MatterDotNet/Messages/InteractionModel/AttributePathIB.cs @@ -37,7 +37,7 @@ public AttributePathIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public AttributePathIB(TLVReader reader, long structNumber = -1) { + internal AttributePathIB(TLVReader reader, long structNumber = -1) { reader.StartList(structNumber); if (reader.IsTag(0)) EnableTagCompression = reader.GetBool(0); @@ -57,7 +57,7 @@ public AttributePathIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartList(structNumber); if (EnableTagCompression != null) writer.WriteBool(0, EnableTagCompression); diff --git a/MatterDotNet/Messages/InteractionModel/AttributeReportIB.cs b/MatterDotNet/Messages/InteractionModel/AttributeReportIB.cs index 720cb17..5d737c7 100644 --- a/MatterDotNet/Messages/InteractionModel/AttributeReportIB.cs +++ b/MatterDotNet/Messages/InteractionModel/AttributeReportIB.cs @@ -32,7 +32,7 @@ public AttributeReportIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public AttributeReportIB(TLVReader reader, long structNumber = -1) { + internal AttributeReportIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(0)) AttributeStatus = new AttributeStatusIB(reader, 0); @@ -42,7 +42,7 @@ public AttributeReportIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (AttributeStatus != null) AttributeStatus.Serialize(writer, 0); diff --git a/MatterDotNet/Messages/InteractionModel/AttributeStatusIB.cs b/MatterDotNet/Messages/InteractionModel/AttributeStatusIB.cs index ecd16cf..cf3e897 100644 --- a/MatterDotNet/Messages/InteractionModel/AttributeStatusIB.cs +++ b/MatterDotNet/Messages/InteractionModel/AttributeStatusIB.cs @@ -32,7 +32,7 @@ public AttributeStatusIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public AttributeStatusIB(TLVReader reader, long structNumber = -1) { + internal AttributeStatusIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Path = new AttributePathIB(reader, 0); Status = new StatusIB(reader, 1); @@ -40,7 +40,7 @@ public AttributeStatusIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); Path.Serialize(writer, 0); Status.Serialize(writer, 1); diff --git a/MatterDotNet/Messages/InteractionModel/ClusterPathIB.cs b/MatterDotNet/Messages/InteractionModel/ClusterPathIB.cs index 035daeb..0576684 100644 --- a/MatterDotNet/Messages/InteractionModel/ClusterPathIB.cs +++ b/MatterDotNet/Messages/InteractionModel/ClusterPathIB.cs @@ -33,7 +33,7 @@ public ClusterPathIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public ClusterPathIB(TLVReader reader, long structNumber = -1) { + internal ClusterPathIB(TLVReader reader, long structNumber = -1) { reader.StartList(structNumber); if (reader.IsTag(0)) Node = reader.GetULong(0); @@ -45,7 +45,7 @@ public ClusterPathIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartList(structNumber); if (Node != null) writer.WriteULong(0, Node); diff --git a/MatterDotNet/Messages/InteractionModel/CommandDataIB.cs b/MatterDotNet/Messages/InteractionModel/CommandDataIB.cs index cbff4b3..6bb8355 100644 --- a/MatterDotNet/Messages/InteractionModel/CommandDataIB.cs +++ b/MatterDotNet/Messages/InteractionModel/CommandDataIB.cs @@ -33,7 +33,7 @@ public CommandDataIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public CommandDataIB(TLVReader reader, long structNumber = -1) { + internal CommandDataIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); CommandPath = new CommandPathIB(reader, 0); if (reader.IsTag(1)) @@ -44,7 +44,7 @@ public CommandDataIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); CommandPath.Serialize(writer, 0); if (CommandFields != null) diff --git a/MatterDotNet/Messages/InteractionModel/CommandPathIB.cs b/MatterDotNet/Messages/InteractionModel/CommandPathIB.cs index abd56ef..6616404 100644 --- a/MatterDotNet/Messages/InteractionModel/CommandPathIB.cs +++ b/MatterDotNet/Messages/InteractionModel/CommandPathIB.cs @@ -33,7 +33,7 @@ public CommandPathIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public CommandPathIB(TLVReader reader, long structNumber = -1) { + internal CommandPathIB(TLVReader reader, long structNumber = -1) { reader.StartList(structNumber); Endpoint = reader.GetUShort(0)!.Value; Cluster = reader.GetUInt(1)!.Value; @@ -42,7 +42,7 @@ public CommandPathIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartList(structNumber); writer.WriteUShort(0, Endpoint); writer.WriteUInt(1, Cluster); diff --git a/MatterDotNet/Messages/InteractionModel/CommandStatusIB.cs b/MatterDotNet/Messages/InteractionModel/CommandStatusIB.cs index 817256d..c328dc4 100644 --- a/MatterDotNet/Messages/InteractionModel/CommandStatusIB.cs +++ b/MatterDotNet/Messages/InteractionModel/CommandStatusIB.cs @@ -33,7 +33,7 @@ public CommandStatusIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public CommandStatusIB(TLVReader reader, long structNumber = -1) { + internal CommandStatusIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); CommandPath = new CommandPathIB(reader, 0); Status = new StatusIB(reader, 1); @@ -43,7 +43,7 @@ public CommandStatusIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); CommandPath.Serialize(writer, 0); Status.Serialize(writer, 1); diff --git a/MatterDotNet/Messages/InteractionModel/DataVersionFilterIB.cs b/MatterDotNet/Messages/InteractionModel/DataVersionFilterIB.cs index d0280c0..235abed 100644 --- a/MatterDotNet/Messages/InteractionModel/DataVersionFilterIB.cs +++ b/MatterDotNet/Messages/InteractionModel/DataVersionFilterIB.cs @@ -33,7 +33,7 @@ public DataVersionFilterIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public DataVersionFilterIB(TLVReader reader, long structNumber = -1) { + internal DataVersionFilterIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); DataVersion = reader.GetUInt(0)!.Value; Path = new AttributePathIB(reader, 1); @@ -42,7 +42,7 @@ public DataVersionFilterIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUInt(0, DataVersion); Path.Serialize(writer, 1); diff --git a/MatterDotNet/Messages/InteractionModel/EventDataIB.cs b/MatterDotNet/Messages/InteractionModel/EventDataIB.cs index 710beef..131ad27 100644 --- a/MatterDotNet/Messages/InteractionModel/EventDataIB.cs +++ b/MatterDotNet/Messages/InteractionModel/EventDataIB.cs @@ -30,37 +30,45 @@ public EventDataIB(Memory data) : this(new TLVReader(data)) {} public required EventPathIB Path { get; set; } public required ulong EventNumber { get; set; } public required byte Priority { get; set; } - public required ulong EpochTimestamp { get; set; } - public required ulong SystemTimestamp { get; set; } - public required ulong DeltaEpochTimestamp { get; set; } - public required ulong DeltaSystemTimestamp { get; set; } + public ulong? EpochTimestamp { get; set; } + public ulong? SystemTimestamp { get; set; } + public ulong? DeltaEpochTimestamp { get; set; } + public ulong? DeltaSystemTimestamp { get; set; } public required object Data { get; set; } /// [SetsRequiredMembers] - public EventDataIB(TLVReader reader, long structNumber = -1) { + internal EventDataIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Path = new EventPathIB(reader, 0); EventNumber = reader.GetULong(1)!.Value; Priority = reader.GetByte(2)!.Value; - EpochTimestamp = reader.GetULong(3)!.Value; - SystemTimestamp = reader.GetULong(4)!.Value; - DeltaEpochTimestamp = reader.GetULong(5)!.Value; - DeltaSystemTimestamp = reader.GetULong(6)!.Value; + if (reader.IsTag(3)) + EpochTimestamp = reader.GetULong(3); + if (reader.IsTag(4)) + SystemTimestamp = reader.GetULong(4); + if (reader.IsTag(5)) + DeltaEpochTimestamp = reader.GetULong(5); + if (reader.IsTag(6)) + DeltaSystemTimestamp = reader.GetULong(6); Data = reader.GetAny(7)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); Path.Serialize(writer, 0); writer.WriteULong(1, EventNumber); writer.WriteByte(2, Priority); - writer.WriteULong(3, EpochTimestamp); - writer.WriteULong(4, SystemTimestamp); - writer.WriteULong(5, DeltaEpochTimestamp); - writer.WriteULong(6, DeltaSystemTimestamp); + if (EpochTimestamp != null) + writer.WriteULong(3, EpochTimestamp); + if (SystemTimestamp != null) + writer.WriteULong(4, SystemTimestamp); + if (DeltaEpochTimestamp != null) + writer.WriteULong(5, DeltaEpochTimestamp); + if (DeltaSystemTimestamp != null) + writer.WriteULong(6, DeltaSystemTimestamp); writer.WriteAny(7, Data); writer.EndContainer(); } diff --git a/MatterDotNet/Messages/InteractionModel/EventFilterIB.cs b/MatterDotNet/Messages/InteractionModel/EventFilterIB.cs index 8f15452..40c7821 100644 --- a/MatterDotNet/Messages/InteractionModel/EventFilterIB.cs +++ b/MatterDotNet/Messages/InteractionModel/EventFilterIB.cs @@ -32,7 +32,7 @@ public EventFilterIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public EventFilterIB(TLVReader reader, long structNumber = -1) { + internal EventFilterIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Node = reader.GetULong(0)!.Value; EventMin = reader.GetULong(1)!.Value; @@ -40,7 +40,7 @@ public EventFilterIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteULong(0, Node); writer.WriteULong(1, EventMin); diff --git a/MatterDotNet/Messages/InteractionModel/EventPathIB.cs b/MatterDotNet/Messages/InteractionModel/EventPathIB.cs index f7c8a80..9ace0ad 100644 --- a/MatterDotNet/Messages/InteractionModel/EventPathIB.cs +++ b/MatterDotNet/Messages/InteractionModel/EventPathIB.cs @@ -35,7 +35,7 @@ public EventPathIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public EventPathIB(TLVReader reader, long structNumber = -1) { + internal EventPathIB(TLVReader reader, long structNumber = -1) { reader.StartList(structNumber); if (reader.IsTag(0)) Node = reader.GetULong(0); @@ -51,7 +51,7 @@ public EventPathIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartList(structNumber); if (Node != null) writer.WriteULong(0, Node); diff --git a/MatterDotNet/Messages/InteractionModel/EventReportIB.cs b/MatterDotNet/Messages/InteractionModel/EventReportIB.cs index a951fb4..485a529 100644 --- a/MatterDotNet/Messages/InteractionModel/EventReportIB.cs +++ b/MatterDotNet/Messages/InteractionModel/EventReportIB.cs @@ -32,7 +32,7 @@ public EventReportIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public EventReportIB(TLVReader reader, long structNumber = -1) { + internal EventReportIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(0)) EventStatus = new EventStatusIB(reader, 0); @@ -42,7 +42,7 @@ public EventReportIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (EventStatus != null) EventStatus.Serialize(writer, 0); diff --git a/MatterDotNet/Messages/InteractionModel/EventStatusIB.cs b/MatterDotNet/Messages/InteractionModel/EventStatusIB.cs index e82a2fc..932e68d 100644 --- a/MatterDotNet/Messages/InteractionModel/EventStatusIB.cs +++ b/MatterDotNet/Messages/InteractionModel/EventStatusIB.cs @@ -32,7 +32,7 @@ public EventStatusIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public EventStatusIB(TLVReader reader, long structNumber = -1) { + internal EventStatusIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Path = new EventPathIB(reader, 0); Status = new StatusIB(reader, 1); @@ -40,7 +40,7 @@ public EventStatusIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); Path.Serialize(writer, 0); Status.Serialize(writer, 1); diff --git a/MatterDotNet/Messages/InteractionModel/InvokeRequestMessage.cs b/MatterDotNet/Messages/InteractionModel/InvokeRequestMessage.cs index d31fc88..2460669 100644 --- a/MatterDotNet/Messages/InteractionModel/InvokeRequestMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/InvokeRequestMessage.cs @@ -34,7 +34,7 @@ public InvokeRequestMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public InvokeRequestMessage(TLVReader reader, long structNumber = -1) { + internal InvokeRequestMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); SuppressResponse = reader.GetBool(0)!.Value; TimedRequest = reader.GetBool(1)!.Value; @@ -52,7 +52,7 @@ public InvokeRequestMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBool(0, SuppressResponse); writer.WriteBool(1, TimedRequest); diff --git a/MatterDotNet/Messages/InteractionModel/InvokeResponseIB.cs b/MatterDotNet/Messages/InteractionModel/InvokeResponseIB.cs index 386bfeb..d490bdb 100644 --- a/MatterDotNet/Messages/InteractionModel/InvokeResponseIB.cs +++ b/MatterDotNet/Messages/InteractionModel/InvokeResponseIB.cs @@ -32,7 +32,7 @@ public InvokeResponseIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public InvokeResponseIB(TLVReader reader, long structNumber = -1) { + internal InvokeResponseIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(0)) Command = new CommandDataIB(reader, 0); @@ -42,7 +42,7 @@ public InvokeResponseIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (Command != null) Command.Serialize(writer, 0); diff --git a/MatterDotNet/Messages/InteractionModel/InvokeResponseMessage.cs b/MatterDotNet/Messages/InteractionModel/InvokeResponseMessage.cs index 772e1f0..ed2b83a 100644 --- a/MatterDotNet/Messages/InteractionModel/InvokeResponseMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/InvokeResponseMessage.cs @@ -34,7 +34,7 @@ public InvokeResponseMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public InvokeResponseMessage(TLVReader reader, long structNumber = -1) { + internal InvokeResponseMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); SuppressResponse = reader.GetBool(0)!.Value; { @@ -53,7 +53,7 @@ public InvokeResponseMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBool(0, SuppressResponse); { diff --git a/MatterDotNet/Messages/InteractionModel/ReadRequestMessage.cs b/MatterDotNet/Messages/InteractionModel/ReadRequestMessage.cs index ae48eb7..db5d3ac 100644 --- a/MatterDotNet/Messages/InteractionModel/ReadRequestMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/ReadRequestMessage.cs @@ -36,7 +36,7 @@ public ReadRequestMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public ReadRequestMessage(TLVReader reader, long structNumber = -1) { + internal ReadRequestMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(0)) { @@ -84,7 +84,7 @@ public ReadRequestMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (AttributeRequests != null) { diff --git a/MatterDotNet/Messages/InteractionModel/ReportDataMessage.cs b/MatterDotNet/Messages/InteractionModel/ReportDataMessage.cs index 94f57e7..263cd36 100644 --- a/MatterDotNet/Messages/InteractionModel/ReportDataMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/ReportDataMessage.cs @@ -36,7 +36,7 @@ public ReportDataMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public ReportDataMessage(TLVReader reader, long structNumber = -1) { + internal ReportDataMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(0)) SubscriptionID = reader.GetULong(0); @@ -69,7 +69,7 @@ public ReportDataMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (SubscriptionID != null) writer.WriteULong(0, SubscriptionID); diff --git a/MatterDotNet/Messages/InteractionModel/StatusIB.cs b/MatterDotNet/Messages/InteractionModel/StatusIB.cs index a5b6e18..6e62792 100644 --- a/MatterDotNet/Messages/InteractionModel/StatusIB.cs +++ b/MatterDotNet/Messages/InteractionModel/StatusIB.cs @@ -32,7 +32,7 @@ public StatusIB(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public StatusIB(TLVReader reader, long structNumber = -1) { + internal StatusIB(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Status = reader.GetByte(0)!.Value; if (reader.IsTag(1)) @@ -41,7 +41,7 @@ public StatusIB(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteByte(0, Status); if (ClusterStatus != null) diff --git a/MatterDotNet/Messages/InteractionModel/StatusResponseMessage.cs b/MatterDotNet/Messages/InteractionModel/StatusResponseMessage.cs index f74bf0b..4e51b0b 100644 --- a/MatterDotNet/Messages/InteractionModel/StatusResponseMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/StatusResponseMessage.cs @@ -32,7 +32,7 @@ public StatusResponseMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public StatusResponseMessage(TLVReader reader, long structNumber = -1) { + internal StatusResponseMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Status = reader.GetByte(0)!.Value; InteractionModelRevision = reader.GetByte(255)!.Value; @@ -40,7 +40,7 @@ public StatusResponseMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteByte(0, Status); writer.WriteByte(255, InteractionModelRevision); diff --git a/MatterDotNet/Messages/InteractionModel/SubscribeRequestMessage.cs b/MatterDotNet/Messages/InteractionModel/SubscribeRequestMessage.cs index d5d3e52..0e20a4f 100644 --- a/MatterDotNet/Messages/InteractionModel/SubscribeRequestMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/SubscribeRequestMessage.cs @@ -39,7 +39,7 @@ public SubscribeRequestMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public SubscribeRequestMessage(TLVReader reader, long structNumber = -1) { + internal SubscribeRequestMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); KeepSubscriptions = reader.GetBool(0)!.Value; MinIntervalFloor = reader.GetULong(1)!.Value; @@ -89,7 +89,7 @@ public SubscribeRequestMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteBool(0, KeepSubscriptions); writer.WriteULong(1, MinIntervalFloor); diff --git a/MatterDotNet/Messages/InteractionModel/SubscribeResponseMessage.cs b/MatterDotNet/Messages/InteractionModel/SubscribeResponseMessage.cs index fbe4849..23be443 100644 --- a/MatterDotNet/Messages/InteractionModel/SubscribeResponseMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/SubscribeResponseMessage.cs @@ -33,7 +33,7 @@ public SubscribeResponseMessage(Memory data) : this(new TLVReader(data)) { /// [SetsRequiredMembers] - public SubscribeResponseMessage(TLVReader reader, long structNumber = -1) { + internal SubscribeResponseMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); SubscriptionID = reader.GetUInt(0)!.Value; MaxInterval = reader.GetUShort(2)!.Value; @@ -42,7 +42,7 @@ public SubscribeResponseMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUInt(0, SubscriptionID); writer.WriteUShort(2, MaxInterval); diff --git a/MatterDotNet/Messages/InteractionModel/TimedRequestMessage.cs b/MatterDotNet/Messages/InteractionModel/TimedRequestMessage.cs index c028986..b67a26d 100644 --- a/MatterDotNet/Messages/InteractionModel/TimedRequestMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/TimedRequestMessage.cs @@ -32,7 +32,7 @@ public TimedRequestMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public TimedRequestMessage(TLVReader reader, long structNumber = -1) { + internal TimedRequestMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Timeout = reader.GetUShort(0)!.Value; InteractionModelRevision = reader.GetByte(255)!.Value; @@ -40,7 +40,7 @@ public TimedRequestMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUShort(0, Timeout); writer.WriteByte(255, InteractionModelRevision); diff --git a/MatterDotNet/Messages/InteractionModel/WriteRequestMessage.cs b/MatterDotNet/Messages/InteractionModel/WriteRequestMessage.cs index fe5bb07..20f958b 100644 --- a/MatterDotNet/Messages/InteractionModel/WriteRequestMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/WriteRequestMessage.cs @@ -35,7 +35,7 @@ public WriteRequestMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public WriteRequestMessage(TLVReader reader, long structNumber = -1) { + internal WriteRequestMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(0)) SuppressResponse = reader.GetBool(0); @@ -56,7 +56,7 @@ public WriteRequestMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (SuppressResponse != null) writer.WriteBool(0, SuppressResponse); diff --git a/MatterDotNet/Messages/InteractionModel/WriteResponseMessage.cs b/MatterDotNet/Messages/InteractionModel/WriteResponseMessage.cs index 597d529..6e04c6e 100644 --- a/MatterDotNet/Messages/InteractionModel/WriteResponseMessage.cs +++ b/MatterDotNet/Messages/InteractionModel/WriteResponseMessage.cs @@ -32,7 +32,7 @@ public WriteResponseMessage(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public WriteResponseMessage(TLVReader reader, long structNumber = -1) { + internal WriteResponseMessage(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); { reader.StartArray(0); @@ -48,7 +48,7 @@ public WriteResponseMessage(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); { writer.StartArray(0); diff --git a/MatterDotNet/Messages/PASE/Crypto_PBKDFParameterSet.cs b/MatterDotNet/Messages/PASE/Crypto_PBKDFParameterSet.cs index 779f806..eb1b55d 100644 --- a/MatterDotNet/Messages/PASE/Crypto_PBKDFParameterSet.cs +++ b/MatterDotNet/Messages/PASE/Crypto_PBKDFParameterSet.cs @@ -32,18 +32,18 @@ public Crypto_PBKDFParameterSet(Memory data) : this(new TLVReader(data)) { /// [SetsRequiredMembers] - public Crypto_PBKDFParameterSet(TLVReader reader, long structNumber = -1) { + internal Crypto_PBKDFParameterSet(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); Iterations = reader.GetUInt(1)!.Value; - Salt = reader.GetBytes(2)!; + Salt = reader.GetBytes(2, false, 32, 16)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); writer.WriteUInt(1, Iterations); - writer.WriteBytes(2, Salt); + writer.WriteBytes(2, Salt, 32, 16); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/PASE/PBKDFParamReq.cs b/MatterDotNet/Messages/PASE/PBKDFParamReq.cs index 58f042c..62da0ed 100644 --- a/MatterDotNet/Messages/PASE/PBKDFParamReq.cs +++ b/MatterDotNet/Messages/PASE/PBKDFParamReq.cs @@ -35,9 +35,9 @@ public PBKDFParamReq(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public PBKDFParamReq(TLVReader reader, long structNumber = -1) { + internal PBKDFParamReq(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - InitiatorRandom = reader.GetBytes(1)!; + InitiatorRandom = reader.GetBytes(1, false, 32, 32)!; InitiatorSessionId = reader.GetUShort(2)!.Value; PasscodeId = reader.GetUShort(3)!.Value; HasPBKDFParameters = reader.GetBool(4)!.Value; @@ -47,9 +47,9 @@ public PBKDFParamReq(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, InitiatorRandom); + writer.WriteBytes(1, InitiatorRandom, 32, 32); writer.WriteUShort(2, InitiatorSessionId); writer.WriteUShort(3, PasscodeId); writer.WriteBool(4, HasPBKDFParameters); diff --git a/MatterDotNet/Messages/PASE/PBKDFParamResp.cs b/MatterDotNet/Messages/PASE/PBKDFParamResp.cs index d5a55fa..20266e6 100644 --- a/MatterDotNet/Messages/PASE/PBKDFParamResp.cs +++ b/MatterDotNet/Messages/PASE/PBKDFParamResp.cs @@ -35,10 +35,10 @@ public PBKDFParamResp(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public PBKDFParamResp(TLVReader reader, long structNumber = -1) { + internal PBKDFParamResp(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - InitiatorRandom = reader.GetBytes(1)!; - ResponderRandom = reader.GetBytes(2)!; + InitiatorRandom = reader.GetBytes(1, false, 32, 32)!; + ResponderRandom = reader.GetBytes(2, false, 32, 32)!; ResponderSessionId = reader.GetUShort(3)!.Value; if (reader.IsTag(4)) Pbkdf_parameters = new Crypto_PBKDFParameterSet(reader, 4); @@ -48,10 +48,10 @@ public PBKDFParamResp(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, InitiatorRandom); - writer.WriteBytes(2, ResponderRandom); + writer.WriteBytes(1, InitiatorRandom, 32, 32); + writer.WriteBytes(2, ResponderRandom, 32, 32); writer.WriteUShort(3, ResponderSessionId); if (Pbkdf_parameters != null) Pbkdf_parameters.Serialize(writer, 4); diff --git a/MatterDotNet/Messages/PASE/Pake1.cs b/MatterDotNet/Messages/PASE/Pake1.cs index 6054020..3c9cd2e 100644 --- a/MatterDotNet/Messages/PASE/Pake1.cs +++ b/MatterDotNet/Messages/PASE/Pake1.cs @@ -31,16 +31,16 @@ public Pake1(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Pake1(TLVReader reader, long structNumber = -1) { + internal Pake1(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - PA = reader.GetBytes(1)!; + PA = reader.GetBytes(1, false, 65, 65)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, PA); + writer.WriteBytes(1, PA, 65, 65); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/PASE/Pake2.cs b/MatterDotNet/Messages/PASE/Pake2.cs index 2bde354..461e8d2 100644 --- a/MatterDotNet/Messages/PASE/Pake2.cs +++ b/MatterDotNet/Messages/PASE/Pake2.cs @@ -32,18 +32,18 @@ public Pake2(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Pake2(TLVReader reader, long structNumber = -1) { + internal Pake2(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - PB = reader.GetBytes(1)!; - CB = reader.GetBytes(2)!; + PB = reader.GetBytes(1, false, 65, 65)!; + CB = reader.GetBytes(2, false, 32, 32)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, PB); - writer.WriteBytes(2, CB); + writer.WriteBytes(1, PB, 65, 65); + writer.WriteBytes(2, CB, 32, 32); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/PASE/Pake3.cs b/MatterDotNet/Messages/PASE/Pake3.cs index 72a0ea7..15a3504 100644 --- a/MatterDotNet/Messages/PASE/Pake3.cs +++ b/MatterDotNet/Messages/PASE/Pake3.cs @@ -31,16 +31,16 @@ public Pake3(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public Pake3(TLVReader reader, long structNumber = -1) { + internal Pake3(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); - CA = reader.GetBytes(1)!; + CA = reader.GetBytes(1, false, 32, 32)!; reader.EndContainer(); } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); - writer.WriteBytes(1, CA); + writer.WriteBytes(1, CA, 32, 32); writer.EndContainer(); } } diff --git a/MatterDotNet/Messages/PASE/SessionParameter.cs b/MatterDotNet/Messages/PASE/SessionParameter.cs index 135760f..5fd8b27 100644 --- a/MatterDotNet/Messages/PASE/SessionParameter.cs +++ b/MatterDotNet/Messages/PASE/SessionParameter.cs @@ -37,7 +37,7 @@ public SessionParameter(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public SessionParameter(TLVReader reader, long structNumber = -1) { + internal SessionParameter(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(1)) SessionIdleInterval = reader.GetUInt(1); @@ -57,7 +57,7 @@ public SessionParameter(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (SessionIdleInterval != null) writer.WriteUInt(1, SessionIdleInterval); diff --git a/MatterDotNet/Messages/SemanticTag.cs b/MatterDotNet/Messages/SemanticTag.cs index 5d161e6..22561d4 100644 --- a/MatterDotNet/Messages/SemanticTag.cs +++ b/MatterDotNet/Messages/SemanticTag.cs @@ -34,7 +34,7 @@ public SemanticTag(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public SemanticTag(TLVReader reader, long structNumber = -1) { + internal SemanticTag(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(0)) MfgCode = reader.GetUShort(0, true); @@ -46,7 +46,7 @@ public SemanticTag(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (MfgCode != null) writer.WriteUShort(0, MfgCode); diff --git a/MatterDotNet/Messages/UserDirectedCommissioning/CommissionerDeclaration.cs b/MatterDotNet/Messages/UserDirectedCommissioning/CommissionerDeclaration.cs index f76ed15..455fe19 100644 --- a/MatterDotNet/Messages/UserDirectedCommissioning/CommissionerDeclaration.cs +++ b/MatterDotNet/Messages/UserDirectedCommissioning/CommissionerDeclaration.cs @@ -36,7 +36,7 @@ public CommissionerDeclaration(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public CommissionerDeclaration(TLVReader reader, long structNumber = -1) { + internal CommissionerDeclaration(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(1)) ErrorCode = reader.GetUShort(1); @@ -54,7 +54,7 @@ public CommissionerDeclaration(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (ErrorCode != null) writer.WriteUShort(1, ErrorCode); diff --git a/MatterDotNet/Messages/UserDirectedCommissioning/IdentificationDeclaration.cs b/MatterDotNet/Messages/UserDirectedCommissioning/IdentificationDeclaration.cs index 009ec1d..5b06fb2 100644 --- a/MatterDotNet/Messages/UserDirectedCommissioning/IdentificationDeclaration.cs +++ b/MatterDotNet/Messages/UserDirectedCommissioning/IdentificationDeclaration.cs @@ -41,7 +41,7 @@ public TargetApp(Memory data) : this(new TLVReader(data)) {} /// [SetsRequiredMembers] - public TargetApp(TLVReader reader, long structNumber = -1) { + internal TargetApp(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(11)) AppVendorId = reader.GetUShort(11); @@ -51,7 +51,7 @@ public TargetApp(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (AppVendorId != null) writer.WriteUShort(11, AppVendorId); @@ -77,22 +77,22 @@ public override void Serialize(TLVWriter writer, long structNumber = -1) { /// [SetsRequiredMembers] - public IdentificationDeclaration(TLVReader reader, long structNumber = -1) { + internal IdentificationDeclaration(TLVReader reader, long structNumber = -1) { reader.StartStructure(structNumber); if (reader.IsTag(1)) VendorId = reader.GetUShort(1); if (reader.IsTag(2)) ProductId = reader.GetUShort(2); if (reader.IsTag(3)) - DeviceName = reader.GetString(3); + DeviceName = reader.GetString(3, false, 32); if (reader.IsTag(4)) DeviceType = reader.GetUInt(4); if (reader.IsTag(5)) - PairingInstruction = reader.GetString(5); + PairingInstruction = reader.GetString(5, false, 32); if (reader.IsTag(6)) PairingHint = reader.GetUInt(6); if (reader.IsTag(7)) - RotatingDeviceId = reader.GetString(7); + RotatingDeviceId = reader.GetString(7, false, 100); if (reader.IsTag(8)) Port = reader.GetUShort(8); if (reader.IsTag(9)) @@ -119,22 +119,22 @@ public IdentificationDeclaration(TLVReader reader, long structNumber = -1) { } /// - public override void Serialize(TLVWriter writer, long structNumber = -1) { + internal override void Serialize(TLVWriter writer, long structNumber = -1) { writer.StartStructure(structNumber); if (VendorId != null) writer.WriteUShort(1, VendorId); if (ProductId != null) writer.WriteUShort(2, ProductId); if (DeviceName != null) - writer.WriteString(3, DeviceName); + writer.WriteString(3, DeviceName, 32); if (DeviceType != null) writer.WriteUInt(4, DeviceType); if (PairingInstruction != null) - writer.WriteString(5, PairingInstruction); + writer.WriteString(5, PairingInstruction, 32); if (PairingHint != null) writer.WriteUInt(6, PairingHint); if (RotatingDeviceId != null) - writer.WriteString(7, RotatingDeviceId); + writer.WriteString(7, RotatingDeviceId, 100); if (Port != null) writer.WriteUShort(8, Port); if (TargetAppList != null) diff --git a/MatterDotNet/PKI/Fabric.cs b/MatterDotNet/PKI/Fabric.cs index 772d065..1796941 100644 --- a/MatterDotNet/PKI/Fabric.cs +++ b/MatterDotNet/PKI/Fabric.cs @@ -111,9 +111,9 @@ public OperationalCertificate CreateCommissioner(byte[] publicKey, byte[] privat collection.Add(new Oid(OID_ServerAuth)); collection.Add(new Oid(OID_ClientAuth)); signingCSR.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(collection, true)); - signingCSR.CertificateExtensions.Add(new X509SubjectKeyIdentifierExtension(key.ExportSubjectPublicKeyInfo(), false)); + signingCSR.CertificateExtensions.Add(new X509SubjectKeyIdentifierExtension(SHA1.HashData(publicKey), false)); signingCSR.CertificateExtensions.Add(X509AuthorityKeyIdentifierExtension.CreateFromCertificate(cert, true, false)); - byte[] serial = new byte[20]; + byte[] serial = new byte[19]; Random.Shared.NextBytes(serial); OperationalCertificate ret = new OperationalCertificate(signingCSR.Create(cert, DateTime.Now.Subtract(TimeSpan.FromSeconds(30)), DateTime.Now.AddYears(1), serial).CopyWithPrivateKey(key)); nodes.Add(ret.NodeID, ret); diff --git a/MatterDotNet/Protocol/InteractionManager.cs b/MatterDotNet/Protocol/InteractionManager.cs index fe76f5c..2a32e5b 100644 --- a/MatterDotNet/Protocol/InteractionManager.cs +++ b/MatterDotNet/Protocol/InteractionManager.cs @@ -32,7 +32,7 @@ public static async Task> GetAttributes(SecureSession se { InteractionModelRevision = Constants.MATTER_13_REVISION, FabricFiltered = false, - AttributeRequests = paths + AttributeRequests = paths, }; Frame readFrame = new Frame(read, (byte)IMOpCodes.ReadRequest); readFrame.Flags |= MessageFlags.SourceNodeID; diff --git a/MatterDotNet/Protocol/Payloads/TLVPayload.cs b/MatterDotNet/Protocol/Payloads/TLVPayload.cs index 9be35f4..8f42331 100644 --- a/MatterDotNet/Protocol/Payloads/TLVPayload.cs +++ b/MatterDotNet/Protocol/Payloads/TLVPayload.cs @@ -27,21 +27,21 @@ public TLVPayload() { } /// Parse the TLVs from a frame into this message /// /// - public TLVPayload(Memory data) : this(new TLVReader(data)) {} + internal TLVPayload(Memory data) : this(new TLVReader(data)) {} /// /// Parse the TLVs from a frame into this message /// /// /// - public TLVPayload(TLVReader reader, long structureNumber = -1) { } + internal TLVPayload(TLVReader reader, long structureNumber = -1) { } /// /// Write the TLVs to an application payload /// /// /// - public abstract void Serialize(TLVWriter writer, long structureNumber = -1); + internal abstract void Serialize(TLVWriter writer, long structureNumber = -1); /// /// Write the TLVs to an application payload @@ -52,5 +52,37 @@ public void Serialize(PayloadWriter writer) { Serialize(new TLVWriter(writer)); } + + /// + /// Throw an error if the list does not fall within the valid size range + /// + /// + /// + /// + /// + /// + protected void Constrain(List list, int min, int max = int.MaxValue) + { + if (list.Count < min) + throw new InvalidDataException($"List must contain at least {min} element{(min == 1 ? "" : "s")} but contained {list.Count}"); + if (list.Count > max) + throw new InvalidDataException($"List may not contain more than {max} element{(min == 1 ? "" : "s")} but contained {list.Count}"); + } + + /// + /// Throw an error if the array does not fall within the valid size range + /// + /// + /// + /// + /// + /// + protected void Constrain(T[] array, int min, int max = int.MaxValue) + { + if (array.Length < min) + throw new InvalidDataException($"Array must contain at least {min} element{(min == 1 ? "" : "s")} but contained {array.Length}"); + if (array.Length > max) + throw new InvalidDataException($"Array may not contain more than {max} element{(min == 1 ? "" : "s")} but contained {array.Length}"); + } } } diff --git a/MatterDotNet/Protocol/TLV/TLVReader.cs b/MatterDotNet/Protocol/TLV/TLVReader.cs index f505a52..5e53b10 100644 --- a/MatterDotNet/Protocol/TLV/TLVReader.cs +++ b/MatterDotNet/Protocol/TLV/TLVReader.cs @@ -258,7 +258,7 @@ public void EndContainer() return val; } - public string? GetString(long tagNumber, bool nullable = false) + public string? GetString(long tagNumber, bool nullable = false, int max = int.MaxValue, int min = 0) { if (!IsTag(tagNumber)) throw new InvalidDataException("Tag " + tagNumber + " not present"); @@ -266,13 +266,17 @@ public void EndContainer() return null; if (type != ElementType.String8 && type != ElementType.String16 && type != ElementType.String32) throw new InvalidDataException($"Tag {tagNumber}: Expected type string but received {type}"); + if (length > max) + throw new InvalidDataException($"Constraint Violation! Max length is {max} but received {length}"); + if (length < min) + throw new InvalidDataException($"Constraint Violation! Min length is {min} but received {length}"); string val = Encoding.UTF8.GetString(data.Slice(offset, length).Span); offset += length; ReadTag(); return val; } - public byte[]? GetBytes(long tagNumber, bool nullable = false) + public byte[]? GetBytes(long tagNumber, bool nullable = false, int max = int.MaxValue, int min = 0) { if (!IsTag(tagNumber)) throw new InvalidDataException("Tag " + tagNumber + " not present. Current tag is " + this.tagNumber); @@ -280,6 +284,10 @@ public void EndContainer() return null; if (type != ElementType.Bytes8 && type != ElementType.Bytes16 && type != ElementType.Bytes32) throw new InvalidDataException($"Tag {tagNumber}: Expected type bytes but received {type}"); + if (length > max) + throw new InvalidDataException($"Constraint Violation! Max length is {max} but received {length}"); + if (length < min) + throw new InvalidDataException($"Constraint Violation! Min length is {min} but received {length}"); byte[] val = data.Slice(offset, length).ToArray(); offset += length; ReadTag(); diff --git a/MatterDotNet/Protocol/TLV/TLVWriter.cs b/MatterDotNet/Protocol/TLV/TLVWriter.cs index 78c9f6f..bce64a2 100644 --- a/MatterDotNet/Protocol/TLV/TLVWriter.cs +++ b/MatterDotNet/Protocol/TLV/TLVWriter.cs @@ -11,11 +11,13 @@ // along with this program. If not, see . using MatterDotNet.Protocol.Payloads; +using System.Runtime.CompilerServices; using System.Text; +[assembly: InternalsVisibleTo("Test")] namespace MatterDotNet.Protocol.Parsers { - public class TLVWriter + internal class TLVWriter { PayloadWriter writer; @@ -210,12 +212,16 @@ public void WriteBool(long tagNumber, bool? value) WriteTag(tagNumber, ElementType.False); } - public void WriteString(long tagNumber, string? value) + public void WriteString(long tagNumber, string? value, int maxLen = int.MaxValue, int minLen = 0) { if (value == null) WriteTag(tagNumber, ElementType.Null); else { + if (value.Length > maxLen) + throw new InvalidDataException("Constraint Violated! Maximum length: " + maxLen + ", Actual: " + value.Length); + if (value.Length < minLen) + throw new InvalidDataException("Constraint Violated! Minimum length: " + maxLen + ", Actual: " + value.Length); if (value.Length <= byte.MaxValue) { WriteTag(tagNumber, ElementType.String8); @@ -235,12 +241,16 @@ public void WriteString(long tagNumber, string? value) } } - public void WriteBytes(long tagNumber, byte[]? value) + public void WriteBytes(long tagNumber, byte[]? value, int maxLen = int.MaxValue, int minLen = 0) { if (value == null) WriteTag(tagNumber, ElementType.Null); else { + if (value.Length > maxLen) + throw new InvalidDataException("Constraint Violated! Maximum length: " + maxLen + ", Actual: " + value.Length); + if (value.Length < minLen) + throw new InvalidDataException("Constraint Violated! Minimum length: " + maxLen + ", Actual: " + value.Length); if (value.Length <= byte.MaxValue) { WriteTag(tagNumber, ElementType.Bytes8); diff --git a/MatterDotNet/Util/BigIntUtil.cs b/MatterDotNet/Util/BigIntUtil.cs index ad58451..cf27e27 100644 --- a/MatterDotNet/Util/BigIntUtil.cs +++ b/MatterDotNet/Util/BigIntUtil.cs @@ -1,6 +1,6 @@ /* * Copyright (c) Microsoft Corporation. All rights reserved. -* Licensed under the MIT License. See the LICENSE file in the project root for full license information. +* Licensed under the MIT License. */ using MatterDotNet.Protocol.Cryptography; @@ -8,6 +8,9 @@ namespace MatterDotNet.Security { + /// + /// Big Integer Math + /// public class BigIntUtil { private static BigIntegerPoint Mul(BigIntegerPoint a, BigIntegerPoint b, BigInteger p, BigInteger w2) diff --git a/Test/SpakeTests.cs b/Test/SpakeTests.cs index cbd89ac..d90f8a6 100644 --- a/Test/SpakeTests.cs +++ b/Test/SpakeTests.cs @@ -59,8 +59,9 @@ public void TestExchange() Assert.That(responderValidation.V.ToBytes(true).ToArray(), Is.EqualTo(ininiatorValidation.V.ToBytes(true).ToArray()).AsCollection); Assert.That(responderValidation.Z.ToBytes(true).ToArray(), Is.EqualTo(ininiatorValidation.Z.ToBytes(true).ToArray()).AsCollection); - PBKDFParamReq req = new PBKDFParamReq() { HasPBKDFParameters = false, InitiatorRandom = [], InitiatorSessionId = 23, PasscodeId = 0 }; - PBKDFParamResp resp = new PBKDFParamResp() { InitiatorRandom = [], ResponderRandom = [], ResponderSessionId = 23 }; + byte[] random = RandomNumberGenerator.GetBytes(32); + PBKDFParamReq req = new PBKDFParamReq() { HasPBKDFParameters = false, InitiatorRandom = random, InitiatorSessionId = 23, PasscodeId = 0 }; + PBKDFParamResp resp = new PBKDFParamResp() { InitiatorRandom = random, ResponderRandom = random, ResponderSessionId = 23 }; responder.Finish(req, resp, pA.ToBytes(false), pB.ToBytes(false)); } }