From 306c1dec5eb20da03bc9569aab83ae97a2ca9e7a Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sat, 19 Nov 2016 21:16:52 -0500 Subject: Support queries for attribute length and presence. Calling hal_rpc_pkey_get_attributes() with attribute_buffer_len = 0 now changes the return behavior so that it reports the lengths of attributes listed in the query, with a length of zero for attributes not present at all. This is mostly to support C_GetAttributeValue() in PKCS #11, but we also use it to make the Python interface a bit kinder to the user. --- ks_flash.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ks_flash.c') diff --git a/ks_flash.c b/ks_flash.c index 5b38ec5..9b1bf7c 100644 --- a/ks_flash.c +++ b/ks_flash.c @@ -1579,7 +1579,7 @@ static hal_error_t ks_get_attributes(hal_ks_t *ks, const size_t attributes_buffer_len) { if (ks != &db.ks || slot == NULL || attributes == NULL || attributes_len == 0 || - attributes_buffer == NULL || attributes_buffer_len == 0) + attributes_buffer == NULL) return HAL_ERROR_BAD_ARGUMENTS; for (int i = 0; i < attributes_len; i++) { @@ -1626,7 +1626,7 @@ static hal_error_t ks_get_attributes(hal_ks_t *ks, for (int i = 0; i < attributes_len; i++) { - if (attributes[i].value != NULL) + if (attributes[i].length > 0) continue; int j = 0; @@ -1634,20 +1634,24 @@ static hal_error_t ks_get_attributes(hal_ks_t *ks, j++; if (j >= *attrs_len) continue; + found++; + + attributes[i].length = attrs[j].length; + + if (attributes_buffer_len == 0) + continue; if (attrs[j].length > attributes_buffer + attributes_buffer_len - abuf) return HAL_ERROR_RESULT_TOO_LONG; memcpy(abuf, attrs[j].value, attrs[j].length); attributes[i].value = abuf; - attributes[i].length = attrs[j].length; abuf += attrs[j].length; - found++; } } while (found < attributes_len && ++chunk < block->header.total_chunks); - if (found < attributes_len) + if (found < attributes_len && attributes_buffer_len > 0) return HAL_ERROR_ATTRIBUTE_NOT_FOUND; return HAL_OK; -- cgit v1.2.3