Skip to content

Commit 4a3f02d

Browse files
committed
Fix exchange tear-down. Generate certificate structs.
1 parent 3bb1fcc commit 4a3f02d

File tree

17 files changed

+724
-53
lines changed

17 files changed

+724
-53
lines changed

Generator/ClassGenerator.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer)
6363
writer.WriteLine($"{totalIndent} reader.StartArray({child.TagNumber});");
6464
writer.WriteLine($"{totalIndent} List<{GetEnumerationType(child)}> items = new();");
6565
writer.WriteLine($"{totalIndent} while (!reader.IsEndContainer()) {{");
66-
writer.WriteLine($"{totalIndent} items.Add({GetReader(GetEnumerationType(child), GetEnumerationIndex(child))});");
66+
writer.WriteLine($"{totalIndent} items.Add({GetReader(GetEnumerationType(child), GetEnumerationIndex(child), GetEnumerationNullable(child))});");
6767
writer.WriteLine($"{totalIndent} }}");
6868
writer.WriteLine($"{totalIndent} reader.EndContainer();");
6969
writer.WriteLine($"{totalIndent} {child.Name} = items.ToArray();");
@@ -74,7 +74,7 @@ private static void WriteTag(string indent, Tag tag, StreamWriter writer)
7474
writer.WriteLine($"{totalIndent} reader.StartList({child.TagNumber});");
7575
writer.WriteLine($"{totalIndent} {child.Name} = new();");
7676
writer.WriteLine($"{totalIndent} while (!reader.IsEndContainer()) {{");
77-
writer.WriteLine($"{totalIndent} {child.Name}.Add({GetReader(GetEnumerationType(child), GetEnumerationIndex(child))});");
77+
writer.WriteLine($"{totalIndent} {child.Name}.Add({GetReader(GetEnumerationType(child), GetEnumerationIndex(child), GetEnumerationNullable(child))});");
7878
writer.WriteLine($"{totalIndent} }}");
7979
writer.WriteLine($"{totalIndent} reader.EndContainer();");
8080
writer.WriteLine($"{totalIndent}}}");
@@ -232,24 +232,24 @@ private static object GetWriter(string? referenceName, string tagNumber)
232232
}
233233
}
234234

235-
private static object GetReader(string? referenceName, string tagNumber)
235+
private static object GetReader(string? referenceName, string tagNumber, bool nullAllowed)
236236
{
237237
switch (referenceName)
238238
{
239239
case "bool":
240-
return $"reader.GetBool({tagNumber})";
240+
return $"reader.GetBool({tagNumber}){(nullAllowed ? "" : "!.Value")}";
241241
case "byte[]":
242-
return $"reader.GetBytes({tagNumber})";
242+
return $"reader.GetBytes({tagNumber}){(nullAllowed ? "" : "!")}";
243243
case "float":
244-
return $"reader.GetFloat({tagNumber})";
244+
return $"reader.GetFloat({tagNumber}){(nullAllowed ? "" : "!.Value")}";
245245
case "double":
246-
return $"reader.GetDouble({tagNumber})";
246+
return $"reader.GetDouble({tagNumber}){(nullAllowed ? "" : "!.Value")}";
247247
case "int":
248-
return $"reader.GetInt({tagNumber})";
248+
return $"reader.GetInt({tagNumber}){(nullAllowed ? "" : "!.Value")}";
249249
case "string":
250-
return $"reader.GetString({tagNumber})";
250+
return $"reader.GetString({tagNumber}){(nullAllowed ? "" : "!")}";
251251
case "uint":
252-
return $"reader.GetUInt({tagNumber})";
252+
return $"reader.GetUInt({tagNumber}){(nullAllowed ? "" : "!.Value")}";
253253
default:
254254
return $"new {referenceName}(reader, {tagNumber})";
255255
}
@@ -318,6 +318,13 @@ private static string GetType(Tag tag)
318318
}
319319
}
320320

321+
private static bool GetEnumerationNullable(Tag tag)
322+
{
323+
if (tag.Children.Count == 0)
324+
return tag.Nullable;
325+
return tag.Children[0].Nullable!;
326+
}
327+
321328
private static string GetEnumerationType(Tag tag)
322329
{
323330
if (tag.Children.Count == 0)

Generator/GeneratorUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class GeneratorUtil
1919
public static string SanitizeName(string name)
2020
{
2121
if (name.EndsWith("struct", StringComparison.InvariantCultureIgnoreCase))
22-
return name.Substring(0, name.Length - 6);
22+
name = name.Substring(0, name.Length - 6);
2323
bool cap = true;
2424
StringBuilder ret = new StringBuilder(name.Length);
2525
foreach (char c in name)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// MatterDotNet Copyright (C) 2024
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or any later version.
6+
// This program is distributed in the hope that it will be useful,
7+
// but WITHOUT ANY WARRANTY, without even the implied warranty of
8+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
// See the GNU Affero General Public License for more details.
10+
// You should have received a copy of the GNU Affero General Public License
11+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
12+
//
13+
// WARNING: This file was auto-generated. Do not edit.
14+
15+
using MatterDotNet.Protocol.Parsers;
16+
using MatterDotNet.Protocol.Payloads;
17+
using System.Diagnostics.CodeAnalysis;
18+
19+
namespace MatterDotNet.Messages.Certificates
20+
{
21+
public record AttestationElements : TLVPayload
22+
{
23+
/// <inheritdoc />
24+
public AttestationElements() {}
25+
26+
/// <inheritdoc />
27+
[SetsRequiredMembers]
28+
public AttestationElements(Memory<byte> data) : this(new TLVReader(data)) {}
29+
30+
public required byte[] Certification_declaration { get; set; }
31+
public required byte[] Attestation_nonce { get; set; }
32+
public required uint Timestamp { get; set; }
33+
public byte[]? Firmware_information { get; set; }
34+
35+
/// <inheritdoc />
36+
[SetsRequiredMembers]
37+
public AttestationElements(TLVReader reader, uint structNumber = 0) {
38+
reader.StartStructure(structNumber);
39+
Certification_declaration = reader.GetBytes(1)!;
40+
Attestation_nonce = reader.GetBytes(2)!;
41+
Timestamp = reader.GetUInt(3)!.Value;
42+
if (reader.IsTag(4))
43+
Firmware_information = reader.GetBytes(4);
44+
reader.EndContainer();
45+
}
46+
47+
/// <inheritdoc />
48+
public override void Serialize(TLVWriter writer, uint structNumber = 0) {
49+
writer.StartStructure(structNumber);
50+
writer.WriteBytes(1, Certification_declaration);
51+
writer.WriteBytes(2, Attestation_nonce);
52+
writer.WriteUInt(3, Timestamp);
53+
if (Firmware_information != null)
54+
writer.WriteBytes(4, Firmware_information);
55+
writer.EndContainer();
56+
}
57+
}
58+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// MatterDotNet Copyright (C) 2024
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or any later version.
6+
// This program is distributed in the hope that it will be useful,
7+
// but WITHOUT ANY WARRANTY, without even the implied warranty of
8+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
// See the GNU Affero General Public License for more details.
10+
// You should have received a copy of the GNU Affero General Public License
11+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
12+
//
13+
// WARNING: This file was auto-generated. Do not edit.
14+
15+
using MatterDotNet.Protocol.Parsers;
16+
using MatterDotNet.Protocol.Payloads;
17+
using System.Diagnostics.CodeAnalysis;
18+
19+
namespace MatterDotNet.Messages.Certificates
20+
{
21+
public record BasicConstraints : TLVPayload
22+
{
23+
/// <inheritdoc />
24+
public BasicConstraints() {}
25+
26+
/// <inheritdoc />
27+
[SetsRequiredMembers]
28+
public BasicConstraints(Memory<byte> data) : this(new TLVReader(data)) {}
29+
30+
public required bool IsCa { get; set; }
31+
public byte? PathLenConstraint { get; set; }
32+
33+
/// <inheritdoc />
34+
[SetsRequiredMembers]
35+
public BasicConstraints(TLVReader reader, uint structNumber = 0) {
36+
reader.StartStructure(structNumber);
37+
IsCa = reader.GetBool(1)!.Value;
38+
if (reader.IsTag(2))
39+
PathLenConstraint = reader.GetByte(2);
40+
reader.EndContainer();
41+
}
42+
43+
/// <inheritdoc />
44+
public override void Serialize(TLVWriter writer, uint structNumber = 0) {
45+
writer.StartStructure(structNumber);
46+
writer.WriteBool(1, IsCa);
47+
if (PathLenConstraint != null)
48+
writer.WriteByte(2, PathLenConstraint);
49+
writer.EndContainer();
50+
}
51+
}
52+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// MatterDotNet Copyright (C) 2024
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or any later version.
6+
// This program is distributed in the hope that it will be useful,
7+
// but WITHOUT ANY WARRANTY, without even the implied warranty of
8+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
// See the GNU Affero General Public License for more details.
10+
// You should have received a copy of the GNU Affero General Public License
11+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
12+
//
13+
// WARNING: This file was auto-generated. Do not edit.
14+
15+
using MatterDotNet.Protocol.Parsers;
16+
using MatterDotNet.Protocol.Payloads;
17+
using System.Diagnostics.CodeAnalysis;
18+
19+
namespace MatterDotNet.Messages.Certificates
20+
{
21+
public record CertificationElements : TLVPayload
22+
{
23+
/// <inheritdoc />
24+
public CertificationElements() {}
25+
26+
/// <inheritdoc />
27+
[SetsRequiredMembers]
28+
public CertificationElements(Memory<byte> data) : this(new TLVReader(data)) {}
29+
30+
public required ushort Format_version { get; set; }
31+
public required ushort Vendor_id { get; set; }
32+
public required uint[] Product_id_array { get; set; }
33+
public required uint Device_type_id { get; set; }
34+
public required string Certificate_id { get; set; }
35+
public required byte Security_level { get; set; }
36+
public required ushort Security_information { get; set; }
37+
public required ushort Version_number { get; set; }
38+
public required byte Certification_type { get; set; }
39+
public ushort? Dac_origin_vendor_id { get; set; }
40+
public ushort? Dac_origin_product_id { get; set; }
41+
public byte[][]? Authorized_paa_list { get; set; }
42+
43+
/// <inheritdoc />
44+
[SetsRequiredMembers]
45+
public CertificationElements(TLVReader reader, uint structNumber = 0) {
46+
reader.StartStructure(structNumber);
47+
Format_version = reader.GetUShort(0)!.Value;
48+
Vendor_id = reader.GetUShort(1)!.Value;
49+
{
50+
reader.StartArray(2);
51+
List<uint> items = new();
52+
while (!reader.IsEndContainer()) {
53+
items.Add(reader.GetUInt(0)!.Value);
54+
}
55+
reader.EndContainer();
56+
Product_id_array = items.ToArray();
57+
}
58+
Device_type_id = reader.GetUInt(3)!.Value;
59+
Certificate_id = reader.GetString(4)!;
60+
Security_level = reader.GetByte(5)!.Value;
61+
Security_information = reader.GetUShort(6)!.Value;
62+
Version_number = reader.GetUShort(7)!.Value;
63+
Certification_type = reader.GetByte(8)!.Value;
64+
if (reader.IsTag(9))
65+
Dac_origin_vendor_id = reader.GetUShort(9);
66+
if (reader.IsTag(10))
67+
Dac_origin_product_id = reader.GetUShort(10);
68+
if (reader.IsTag(11))
69+
{
70+
reader.StartArray(11);
71+
List<byte[]> items = new();
72+
while (!reader.IsEndContainer()) {
73+
items.Add(reader.GetBytes(0)!);
74+
}
75+
reader.EndContainer();
76+
Authorized_paa_list = items.ToArray();
77+
}
78+
reader.EndContainer();
79+
}
80+
81+
/// <inheritdoc />
82+
public override void Serialize(TLVWriter writer, uint structNumber = 0) {
83+
writer.StartStructure(structNumber);
84+
writer.WriteUShort(0, Format_version);
85+
writer.WriteUShort(1, Vendor_id);
86+
{
87+
writer.StartArray(2);
88+
foreach (var item in Product_id_array) {
89+
writer.WriteUInt(0, item);
90+
}
91+
writer.EndContainer();
92+
}
93+
writer.WriteUInt(3, Device_type_id);
94+
writer.WriteString(4, Certificate_id);
95+
writer.WriteByte(5, Security_level);
96+
writer.WriteUShort(6, Security_information);
97+
writer.WriteUShort(7, Version_number);
98+
writer.WriteByte(8, Certification_type);
99+
if (Dac_origin_vendor_id != null)
100+
writer.WriteUShort(9, Dac_origin_vendor_id);
101+
if (Dac_origin_product_id != null)
102+
writer.WriteUShort(10, Dac_origin_product_id);
103+
if (Authorized_paa_list != null)
104+
{
105+
writer.StartArray(11);
106+
foreach (var item in Authorized_paa_list) {
107+
writer.WriteBytes(0, item);
108+
}
109+
writer.EndContainer();
110+
}
111+
writer.EndContainer();
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)