Skip to content

Commit

Permalink
add fido_cred_add_type() to allow adding credential types one by one
Browse files Browse the repository at this point in the history
  • Loading branch information
bobomb committed Jan 11, 2024
1 parent aef9540 commit 6149e5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fido_dev_make_cred_tx(fido_dev_t *dev, fido_cred_t *cred, const char *pin,

if (cred->cdh.ptr == NULL || fido_int_array_is_empty(&cred->type)) {
fido_log_debug("%s: cdh=%p, type=%d", __func__,
(void *)cred->cdh.ptr, fido_cred_type(&cred));
(void *)cred->cdh.ptr, fido_cred_type((const fido_cred_t *) & cred));
r = FIDO_ERR_INVALID_ARGUMENT;
goto fail;
}
Expand Down Expand Up @@ -1009,6 +1009,24 @@ fido_cred_set_type_array(fido_cred_t* cred, int *cose_alg_array, size_t count)
return (FIDO_OK);
}

int fido_cred_add_type(fido_cred_t *cred, int cose_alg)
{
if (cose_alg != COSE_ES256 && cose_alg != COSE_ES384 &&
cose_alg != COSE_RS256 && cose_alg != COSE_EDDSA)
return (FIDO_ERR_INVALID_ARGUMENT);

if (cred->type.ptr == NULL || cred->type.count == 0) {
if (fido_int_array_set(&cred->type, &cose_alg, 1) != 0)
return (FIDO_ERR_INTERNAL);
}
else {
if (fido_int_array_append(&cred->type, &cose_alg, 1) != 0)
return (FIDO_ERR_INTERNAL);
}

return (FIDO_OK);
}

int
fido_cred_type(const fido_cred_t *cred)
{
Expand Down
1 change: 1 addition & 0 deletions src/fido.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ int fido_cred_set_rp(fido_cred_t *, const char *, const char *);
int fido_cred_set_sig(fido_cred_t *, const unsigned char *, size_t);
int fido_cred_set_type(fido_cred_t *, int);
int fido_cred_set_type_array(fido_cred_t* cred, int* cose_alg_array, size_t count);
int fido_cred_add_type(fido_cred_t*, int);
int fido_cred_set_uv(fido_cred_t *, fido_opt_t);
int fido_cred_type(const fido_cred_t *);
int fido_cred_set_user(fido_cred_t *, const unsigned char *, size_t,
Expand Down

0 comments on commit 6149e5e

Please sign in to comment.