ProvisioningLibrary
Atmel Security Provisioning Library
atcaprov_bson.h File Reference

Declarations and constants for working with BSON data. More...

#include <stdint.h>
#include <string.h>

Go to the source code of this file.

Macros

#define BSON_TYPE_DOUBLE   (0x01)
 
#define BSON_TYPE_STRING   (0x02)
 
#define BSON_TYPE_DOCUMENT   (0x03)
 
#define BSON_TYPE_ARRAY   (0x04)
 
#define BSON_TYPE_BINARY   (0x05)
 
#define BSON_TYPE_OBJID   (0x07)
 
#define BSON_TYPE_BOOL   (0x08)
 
#define BSON_TYPE_DATETIME   (0x09)
 
#define BSON_TYPE_NULL   (0x0A)
 
#define BSON_TYPE_REGEX   (0x0B)
 
#define BSON_TYPE_DBPTR   (0x0C)
 
#define BSON_TYPE_JAVASCRIPT   (0x0D)
 
#define BSON_TYPE_JAVASCRIPTWS   (0x0F)
 
#define BSON_TYPE_INT32   (0x10)
 
#define BSON_TYPE_TIMESTAMP   (0x11)
 
#define BSON_TYPE_INT64   (0x12)
 
#define BSON_TYPE_MINKEY   (0xFF)
 
#define BSON_TYPE_MAXKEY   (0x7F)
 

Functions

const uint8_t * bson_memfind (const uint8_t *area, size_t area_size, const uint8_t *data, size_t data_size)
 Find binary data within a search area. More...
 
int32_t bson_dec_int32 (const uint8_t *data)
 Decode a BSON int32 value. More...
 
void bson_enc_int32 (uint8_t *data, int32_t value)
 Encode a BSON int32 value. More...
 
void bson_enc_bool (uint8_t *data, int value)
 Encode a BSON boolean value. More...
 
const uint8_t * bson_find_field (const uint8_t *area, size_t area_size, uint8_t type, const char *name, uint32_t *size, int index)
 Simple routine to find fields in BSON data. More...
 

Detailed Description

Declarations and constants for working with BSON data.

Macro Definition Documentation

#define BSON_TYPE_ARRAY   (0x04)
#define BSON_TYPE_BINARY   (0x05)
#define BSON_TYPE_BOOL   (0x08)
#define BSON_TYPE_DATETIME   (0x09)
#define BSON_TYPE_DBPTR   (0x0C)
#define BSON_TYPE_DOCUMENT   (0x03)
#define BSON_TYPE_DOUBLE   (0x01)
#define BSON_TYPE_INT32   (0x10)
#define BSON_TYPE_INT64   (0x12)
#define BSON_TYPE_JAVASCRIPT   (0x0D)
#define BSON_TYPE_JAVASCRIPTWS   (0x0F)
#define BSON_TYPE_MAXKEY   (0x7F)
#define BSON_TYPE_MINKEY   (0xFF)
#define BSON_TYPE_NULL   (0x0A)
#define BSON_TYPE_OBJID   (0x07)
#define BSON_TYPE_REGEX   (0x0B)
#define BSON_TYPE_STRING   (0x02)
#define BSON_TYPE_TIMESTAMP   (0x11)

Function Documentation

int32_t bson_dec_int32 ( const uint8_t *  data)

Decode a BSON int32 value.

void bson_enc_bool ( uint8_t *  data,
int  value 
)

Encode a BSON boolean value.

void bson_enc_int32 ( uint8_t *  data,
int32_t  value 
)

Encode a BSON int32 value.

const uint8_t* bson_find_field ( const uint8_t *  area,
size_t  area_size,
uint8_t  type,
const char *  name,
uint32_t *  size,
int  index 
)

Simple routine to find fields in BSON data.

This is a simple routine that works for the simple BSON we're dealing with. It won't work for all possible BSON data. Notes that when searching for binary data (type=0x05), the returned pointer points to the binary type flag. The actual binary data starts at the next byte.

Parameters
[in]areaPointer to the BSON data to search.
[in]area_sizeSize of the BSON data in bytes.
[in]typeField type to search for.
[in]nameFiled name to search for.
[out]sizeSize of the found field data returned here. Can be set to NULL if not needed.
[in]indexIf the field type and name appears multiple times, find this instance. 0 is the first one.
Returns
Pointer to the field data in area, if found. NULL otherwise.
const uint8_t* bson_memfind ( const uint8_t *  area,
size_t  area_size,
const uint8_t *  data,
size_t  data_size 
)

Find binary data within a search area.