Skip to content

Commit

Permalink
net: lib: tls_credentials: return size required
Browse files Browse the repository at this point in the history
If either no buffer is provided or the size of it
is too small, return the required length.

Signed-off-by: Pete Skeggs <[email protected]>
  • Loading branch information
plskeggs committed Nov 23, 2024
1 parent 4ba4768 commit 0d1e456
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/zephyr/net/tls_credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ int tls_credential_add(sec_tag_t tag, enum tls_credential_type type,
* @retval -EACCES Access to the TLS credential subsystem was denied.
* @retval -ENOENT Requested TLS credential was not found.
* @retval -EFBIG Requested TLS credential does not fit in the buffer provided.
* Check *credlen for size required.
*/
int tls_credential_get(sec_tag_t tag, enum tls_credential_type type,
void *cred, size_t *credlen);
Expand Down
2 changes: 2 additions & 0 deletions subsys/net/lib/tls_credentials/tls_credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ int tls_credential_get(sec_tag_t tag, enum tls_credential_type type,
credential = credential_get(tag, type);
if (credential == NULL) {
ret = -ENOENT;
*credlen = 0;
goto exit;
}

if (credential->len > *credlen) {
ret = -EFBIG;
*credlen = credential->len;
goto exit;
}

Expand Down

0 comments on commit 0d1e456

Please sign in to comment.