Skip to content

Commit

Permalink
jwks_item_key_oct: New function to retrieve octect data
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Collins <[email protected]>
  • Loading branch information
benmcollins committed Jan 14, 2025
1 parent 78d9107 commit 92b580a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/jwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,21 @@ jwk_key_op_t jwks_item_key_ops(const jwk_item_t *item);
JWT_EXPORT
const char *jwks_item_pem(const jwk_item_t *item);

/**
* @brief Retrieve binary octet data of a key
*
* Only valid for JWT_KEY_TYPE_OCT.
*
* @param item A JWK Item
* @param buf Pointer to a pointer buffer
* @param len Pointer to a length
* @return 0 on success. @p buf will point to data of @c len length. Non-zero on
* error.
*/
JWT_EXPORT
int jwks_item_key_oct(const jwk_item_t *item, const unsigned char **buf,
size_t *len);

/**
* @brief The number of bits in this JWK
*
Expand Down
12 changes: 12 additions & 0 deletions libjwt/jwks.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ int jwks_item_key_bits(const jwk_item_t *item)
return item->bits;
}

int jwks_item_key_oct(const jwk_item_t *item, const unsigned char **buf,
size_t *len)
{
if (!item->oct.key || !item->oct.len)
return 1;

*buf = item->oct.key;
*len = item->oct.len;

return 0;
}

int jwks_error(const jwk_set_t *jwk_set)
{
return jwk_set->error ? 1 : 0;
Expand Down

0 comments on commit 92b580a

Please sign in to comment.