[dataset] add ValidateTlvs(), helper methods, and unit test (#10111)

This commit enhances dataset handling:

- Adds `ValidateTlvs()` which parses and validates all known TLVs
  within the `Dataset` and checks for any duplicates.
- Introduces a set of `SetFrom()` methods for constructing a `Dataset`
  from various types of inputs, e.g., other `Dataset`, TLV sequences,
  `DatasetInfo` structures, bytes read from `Message`. Now they
  consistently clear the `Dataset` before setting it.
- Adds `WriteTlvsFrom()` to update a `Dataset` replacing/appending a
  set of TLVs.
- Adds `AppendTlvsFrom()` to append an already encoded sequence of
  TLVs without validating/checking the format.
- Renames `Get/SetSize()` to `Get/SetLength()` for consistency.
- Adds `test_dataset.cpp` unit test for basic `Dataset` validation.
This commit is contained in:
Abtin Keshavarzian
2024-05-02 14:40:11 -07:00
committed by GitHub
parent b8f036a570
commit 485cb18ea4
19 changed files with 562 additions and 194 deletions
+2 -2
View File
@@ -612,7 +612,7 @@ template <> otError Dataset::Process<Cmd("init")>(Arg aArgs[])
otOperationalDataset dataset;
SuccessOrExit(error = otDatasetCreateNewNetwork(GetInstancePtr(), &dataset));
SuccessOrExit(error = otDatasetConvertToTlvs(&dataset, &sDatasetTlvs));
otDatasetConvertToTlvs(&dataset, &sDatasetTlvs);
}
#endif
else if (aArgs[0] == "tlvs")
@@ -1105,7 +1105,7 @@ template <> otError Dataset::Process<Cmd("set")>(Arg aArgs[])
{
otOperationalDataset dataset;
otOperationalDatasetTlvs datasetTlvs;
uint16_t tlvsLength = MeshCoP::Dataset::kMaxSize;
uint16_t tlvsLength = OT_OPERATIONAL_DATASET_MAX_LENGTH;
SuccessOrExit(error = aArgs[1].ParseAsHexString(tlvsLength, datasetTlvs.mTlvs));
datasetTlvs.mLength = static_cast<uint8_t>(tlvsLength);