Skip to content

Commit 22441bc

Browse files
plskeggsnordicjm
authored andcommitted
lib: modem_key_mgmt: Return size of key
In modem_key_mgmt_read(), if *len parameter is too small to fit the certificate read, return -ENOMEM and set *len to the size needed. This is helpful to check the size of a certificate without actually needing the contents. Signed-off-by: Pete Skeggs <[email protected]>
1 parent 4911109 commit 22441bc

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

include/modem/modem_key_mgmt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ int modem_key_mgmt_clear(nrf_sec_tag_t sec_tag);
106106
*
107107
* @retval 0 On success.
108108
* @retval -ENOBUFS Internal buffer is too small.
109-
* @retval -ENOMEM Credential does not fit in @p buf.
109+
* @retval -ENOMEM Credential does not fit in @p buf. Check *len for
110+
* required size.
110111
* @retval -ENOENT No credential associated with the given
111112
* @p sec_tag and @p cred_type.
112113
* @retval -EACCES Access to credential not allowed.

lib/modem_key_mgmt/modem_key_mgmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ int modem_key_mgmt_read(nrf_sec_tag_t sec_tag,
179179
}
180180

181181
if (end - begin > *len) {
182+
*len = end - begin; /* Let caller know how large their buffer should be. */
182183
err = -ENOMEM;
183184
goto end;
184185
}

0 commit comments

Comments
 (0)