expose fido_blob_t as part of the official api

This commit is contained in:
Ludvig Michaelsson
2021-01-29 08:34:47 +01:00
committed by pedro martelletto
parent 1a76e9c8e1
commit 021ea11e9c
8 changed files with 90 additions and 16 deletions

View File

@@ -70,6 +70,13 @@
fido_bio_template_new;
fido_bio_template_set_id;
fido_bio_template_set_name;
fido_blob_new;
fido_blob_len;
fido_blob_ptr;
fido_blob_set;
fido_blob_free;
fido_blob_reset;
fido_blob_append;
fido_cbor_info_aaguid_len;
fido_cbor_info_aaguid_ptr;
fido_cbor_info_extensions_len;

View File

@@ -13,32 +13,77 @@ fido_blob_new(void)
return (calloc(1, sizeof(fido_blob_t)));
}
int
fido_blob_set(fido_blob_t *b, const unsigned char *ptr, size_t len)
const unsigned char *
fido_blob_ptr(const fido_blob_t *b)
{
return (b->ptr);
}
size_t
fido_blob_len(const fido_blob_t *b)
{
return (b->len);
}
void
fido_blob_reset(fido_blob_t *b)
{
if (b->ptr != NULL) {
explicit_bzero(b->ptr, b->len);
free(b->ptr);
b->ptr = NULL;
}
b->len = 0;
explicit_bzero(b, sizeof(*b));
}
int
fido_blob_set(fido_blob_t *b, const unsigned char *ptr, size_t len)
{
fido_blob_reset(b);
if (ptr == NULL || len == 0) {
fido_log_debug("%s: ptr=%p, len=%zu", __func__,
(const void *)ptr, len);
return (-1);
return (FIDO_ERR_INVALID_ARGUMENT);
}
if ((b->ptr = malloc(len)) == NULL) {
fido_log_debug("%s: malloc", __func__);
return (-1);
return (FIDO_ERR_INTERNAL);
}
memcpy(b->ptr, ptr, len);
b->len = len;
return (0);
return (FIDO_OK);
}
int
fido_blob_append(fido_blob_t *b, const unsigned char *ptr, size_t len)
{
unsigned char *tmp;
if (ptr == NULL || len == 0) {
fido_log_debug("%s: ptr=%p, len=%zu", __func__,
(const void *)ptr, len);
return (FIDO_ERR_INVALID_ARGUMENT);
}
if ((SIZE_MAX - b->len) < len) {
fido_log_debug("%s: overflow", __func__);
return (FIDO_ERR_INTERNAL);
}
if ((tmp = realloc(b->ptr, b->len + len)) == NULL) {
fido_log_debug("%s: realloc", __func__);
return (FIDO_ERR_INTERNAL);
}
b->ptr = tmp;
memcpy(&b->ptr[b->len], ptr, len);
b->len += len;
return (FIDO_OK);
}
void
@@ -49,12 +94,7 @@ fido_blob_free(fido_blob_t **bp)
if (bp == NULL || (b = *bp) == NULL)
return;
if (b->ptr) {
explicit_bzero(b->ptr, b->len);
free(b->ptr);
}
explicit_bzero(b, sizeof(*b));
fido_blob_reset(b);
free(b);
*bp = NULL;

View File

@@ -25,11 +25,9 @@ typedef struct fido_blob_array {
} fido_blob_array_t;
cbor_item_t *fido_blob_encode(const fido_blob_t *);
fido_blob_t *fido_blob_new(void);
int fido_blob_decode(const cbor_item_t *, fido_blob_t *);
int fido_blob_is_empty(const fido_blob_t *);
int fido_blob_set(fido_blob_t *, const unsigned char *, size_t);
void fido_blob_free(fido_blob_t **);
void fido_blob_reset(fido_blob_t *);
void fido_free_blob_array(fido_blob_array_t *);
#ifdef __cplusplus

View File

@@ -71,6 +71,13 @@
fido_bio_template_new;
fido_bio_template_set_id;
fido_bio_template_set_name;
fido_blob_new;
fido_blob_len;
fido_blob_ptr;
fido_blob_set;
fido_blob_free;
fido_blob_reset;
fido_blob_append;
fido_cbor_info_aaguid_len;
fido_cbor_info_aaguid_ptr;
fido_cbor_info_extensions_len;

View File

@@ -69,6 +69,13 @@ _fido_bio_template_name
_fido_bio_template_new
_fido_bio_template_set_id
_fido_bio_template_set_name
_fido_blob_new
_fido_blob_len
_fido_blob_ptr
_fido_blob_set
_fido_blob_free
_fido_blob_reset
_fido_blob_append
_fido_cbor_info_aaguid_len
_fido_cbor_info_aaguid_ptr
_fido_cbor_info_extensions_len

View File

@@ -70,6 +70,13 @@ fido_bio_template_name
fido_bio_template_new
fido_bio_template_set_id
fido_bio_template_set_name
fido_blob_new
fido_blob_len
fido_blob_ptr
fido_blob_set
fido_blob_free
fido_blob_reset
fido_blob_append
fido_cbor_info_aaguid_len
fido_cbor_info_aaguid_ptr
fido_cbor_info_extensions_len

View File

@@ -38,6 +38,7 @@ fido_dev_t *fido_dev_new(void);
fido_dev_t *fido_dev_new_with_info(const fido_dev_info_t *);
fido_dev_info_t *fido_dev_info_new(size_t);
fido_cbor_info_t *fido_cbor_info_new(void);
fido_blob_t *fido_blob_new(void);
void fido_assert_free(fido_assert_t **);
void fido_cbor_info_free(fido_cbor_info_t **);
@@ -46,6 +47,7 @@ void fido_dev_force_fido2(fido_dev_t *);
void fido_dev_force_u2f(fido_dev_t *);
void fido_dev_free(fido_dev_t **);
void fido_dev_info_free(fido_dev_info_t **, size_t);
void fido_blob_free(fido_blob_t **);
/* fido_init() flags. */
#define FIDO_DEBUG 0x01
@@ -191,6 +193,11 @@ bool fido_dev_supports_cred_prot(const fido_dev_t *);
bool fido_dev_supports_credman(const fido_dev_t *);
bool fido_dev_supports_uv(const fido_dev_t *);
size_t fido_blob_len(const fido_blob_t *);
const unsigned char *fido_blob_ptr(const fido_blob_t *);
int fido_blob_set(fido_blob_t *, const unsigned char *, size_t);
int fido_blob_append(fido_blob_t *, const unsigned char *, size_t);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */

View File

@@ -237,6 +237,7 @@ typedef struct fido_dev {
#else
typedef struct fido_assert fido_assert_t;
typedef struct fido_blob fido_blob_t;
typedef struct fido_cbor_info fido_cbor_info_t;
typedef struct fido_cred fido_cred_t;
typedef struct fido_dev fido_dev_t;