Skip to content

Commit

Permalink
jwt_item_t: Remove ll list abstraction now that object is opaque
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Collins <[email protected]>
  • Loading branch information
benmcollins committed Jan 8, 2025
1 parent 0108e3d commit 7794f7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
37 changes: 11 additions & 26 deletions libjwt/jwks.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ static jwk_item_t *jwk_process_one(jwk_set_t *jwk_set, json_t *jwk)

const jwk_item_t *jwks_item_get(const jwk_set_t *jwk_set, size_t index)
{
struct jwk_list_item *item = NULL;
jwk_item_t *item = NULL;
int i = 0;

list_for_each_entry(item, &jwk_set->head, node) {
if (i == index)
return item->item;
return item;
i++;
}

Expand Down Expand Up @@ -272,34 +272,22 @@ void jwks_error_clear(jwk_set_t *jwk_set)

static int jwks_item_add(jwk_set_t *jwk_set, jwk_item_t *item)
{
struct jwk_list_item *new;

if (item == NULL || jwk_set == NULL)
return EINVAL;

new = jwt_malloc(sizeof(*new));
if (new == NULL)
return ENOMEM; // LCOV_EXCL_LINE

new->item = item;

list_add_tail(&new->node, &jwk_set->head);
list_add_tail(&item->node, &jwk_set->head);

return 0;
}

int jwks_item_free(jwk_set_t *jwk_set, const size_t index)
{
struct jwk_list_item *list_item = NULL, *todel = NULL;
jwk_item_t *item;
jwk_item_t *item = NULL, *todel = NULL;
int i = 0;

if (jwk_set == NULL)
return 0;

list_for_each_entry(list_item, &jwk_set->head, node) {
list_for_each_entry(item, &jwk_set->head, node) {
if (i == index) {
todel = list_item;
todel = item;
break;
}
i++;
Expand All @@ -308,20 +296,17 @@ int jwks_item_free(jwk_set_t *jwk_set, const size_t index)
if (todel == NULL)
return 0;

item = todel->item;

if (item->provider == JWT_CRYPTO_OPS_ANY)
jwt_freemem(item->oct.key);
if (todel->provider == JWT_CRYPTO_OPS_ANY)
jwt_freemem(todel->oct.key);
else
jwt_ops->process_item_free(item);
jwt_ops->process_item_free(todel);

/* A few non-crypto specific things. */
jwt_freemem(item->kid);
jwt_freemem(todel->kid);
list_del(&todel->node);

/* Free the container and the item itself. */
jwt_freemem(list_item);
jwt_freemem(item);
jwt_freemem(todel);

return 1;
}
Expand Down
9 changes: 1 addition & 8 deletions libjwt/jwt-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ struct jwt_valid {
jwt_valid_exception_t status;
};

/* Yes, this is a bit of overhead, but it keeps me from having to
* expose list.h in jwt.h.
* XXX We no longer need to abstract this. */
typedef struct jwk_list_item {
ll_t node;
jwk_item_t *item;
} jwk_list_item_t;

struct jwk_set {
ll_t head;
int error;
Expand All @@ -87,6 +79,7 @@ struct jwk_set {
* this. It's provided as a convenience.
*/
struct jwk_item {
ll_t node;
char *pem; /**< If not NULL, contains PEM string of this key */
jwt_crypto_provider_t provider; /**< Crypto provider that owns this key */
union {
Expand Down

0 comments on commit 7794f7d

Please sign in to comment.