aboutsummaryrefslogtreecommitdiff
path: root/ks_attribute.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2017-02-13 23:16:21 -0500
committerPaul Selkirk <paul@psgd.org>2017-02-13 23:16:21 -0500
commit33c843ad457f8341b8a277e6d9481937d3925951 (patch)
tree037073788166eadb5b9fb04fee824c1976ff1afe /ks_attribute.c
parent6a6cc04dda8f613134ae5b30b702de3f1a4dff95 (diff)
Add some comments for things I figured out while reviewing code.
Diffstat (limited to 'ks_attribute.c')
-rw-r--r--ks_attribute.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/ks_attribute.c b/ks_attribute.c
index 92e450d..ec674f5 100644
--- a/ks_attribute.c
+++ b/ks_attribute.c
@@ -120,11 +120,18 @@ hal_error_t hal_ks_attribute_delete(uint8_t *bytes, const size_t bytes_len,
if (bytes == NULL || attributes == NULL || attributes_len == NULL || total_len == NULL)
return HAL_ERROR_BAD_ARGUMENTS;
+ /*
+ * Search for attribute by type. Note that there can be only one
+ * attribute of any given type.
+ */
+
int i = 0;
while (i < *attributes_len && attributes[i].type != type)
i++;
+ /* If not found, great, it's already deleted from the key. */
+
if (i == *attributes_len)
return HAL_OK;
@@ -152,6 +159,8 @@ hal_error_t hal_ks_attribute_insert(uint8_t *bytes, const size_t bytes_len,
total_len == NULL || value == NULL)
return HAL_ERROR_BAD_ARGUMENTS;
+ /* Delete the existing attribute value (if present), then write the new value. */
+
hal_error_t err
= hal_ks_attribute_delete(bytes, bytes_len, attributes, attributes_len, total_len, type);