aboutsummaryrefslogtreecommitdiff
path: root/ks_attribute.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-02-14 18:42:49 -0500
committerRob Austein <sra@hactrn.net>2017-02-14 18:42:49 -0500
commitc05eb9f25182bf0db349d943855bebeccca0c691 (patch)
treea1a8fe5cf1ac8df387eee0b623768dc36a4aaf57 /ks_attribute.c
parentf205126b79558e73bbd856d55bc8bb2ee98f31a8 (diff)
parent33c843ad457f8341b8a277e6d9481937d3925951 (diff)
Merge branch 'pymux' of git.cryptech.is:sw/libhal into pymux
Merge Paul's review comments.
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);