Skip to content

Commit

Permalink
examples: consistent style; range syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
LDVG committed Aug 21, 2024
1 parent 71966bc commit 15468e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following examples are provided:
the device's PIN is changed from [oldpin] to <pin>.

- cred [-t es256|es384|rs256|eddsa] [-k pubkey] [-ei cred_id] [-P pin]
[-T seconds] [-b blobkey] [-hruv] [-c cred_protect] <device>
[-T seconds] [-b blobkey] [-hruv] [-c prot] <device>

Creates a new credential on <device> and verify that the credential
was signed by the authenticator. The device's attestation certificate
Expand Down
18 changes: 8 additions & 10 deletions examples/cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ static void
usage(void)
{
fprintf(stderr, "usage: cred [-t es256|es384|rs256|eddsa] [-k pubkey] "
"[-ei cred_id] [-P pin] [-T seconds] [-b blobkey] [-c cred_protect] [-hruv] "
"[-ei cred_id] [-P pin] [-T seconds] [-b blobkey] [-c prot] [-hruv] "
"<device>\n");
exit(EXIT_FAILURE);
}

static void
verify_cred(int type, const char *fmt, const unsigned char *authdata_ptr,
size_t authdata_len, const unsigned char *attstmt_ptr, size_t attstmt_len,
bool rk, bool uv, int ext, int cred_protect, const char *key_out,
bool rk, bool uv, int ext, int prot, const char *key_out,
const char *id_out)
{
fido_cred_t *cred;
Expand Down Expand Up @@ -87,8 +87,7 @@ verify_cred(int type, const char *fmt, const unsigned char *authdata_ptr,
errx(1, "fido_cred_set_uv: %s (0x%x)", fido_strerr(r), r);

/* credProt */
if (cred_protect != 0 && (r = fido_cred_set_prot(cred,
cred_protect)) != FIDO_OK)
if (prot != 0 && (r = fido_cred_set_prot(cred, prot)) != FIDO_OK)
errx(1, "fido_cred_set_prot: %s (0x%x)", fido_strerr(r), r);

/* fmt */
Expand Down Expand Up @@ -165,7 +164,7 @@ main(int argc, char **argv)
int ext = 0;
int ch;
int r;
long long cred_protect = 0;
long long prot = 0;

if ((cred = fido_cred_new()) == NULL)
errx(1, "fido_cred_new");
Expand Down Expand Up @@ -200,10 +199,10 @@ main(int argc, char **argv)
ext |= FIDO_EXT_HMAC_SECRET;
break;
case 'c':
if (base10(optarg, &cred_protect) < 0)
if (base10(optarg, &prot) < 0)
errx(1, "base10: %s", optarg);
if (cred_protect <= 0 || cred_protect > 3)
errx(1, "-c: %s must be in (1,3)", optarg);
if (prot <= 0 || prot > 3)
errx(1, "-c: %s must be in (0,3]", optarg);
ext |= FIDO_EXT_CRED_PROTECT;
break;
case 'i':
Expand Down Expand Up @@ -290,8 +289,7 @@ main(int argc, char **argv)
errx(1, "fido_cred_set_uv: %s (0x%x)", fido_strerr(r), r);

/* credProt */
if (cred_protect != 0 && (r = fido_cred_set_prot(cred,
(int)cred_protect)) != FIDO_OK)
if (prot != 0 && (r = fido_cred_set_prot(cred, (int)prot)) != FIDO_OK)
errx(1, "fido_cred_set_prot: %s (0x%x)", fido_strerr(r), r);

/* timeout */
Expand Down

0 comments on commit 15468e6

Please sign in to comment.