The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Typedefs | Functions | Variables
cbor.c File Reference

CBPR encoding and decoding. More...

#include <freeradius-devel/util/cbor.h>
+ Include dependency graph for cbor.c:

Go to the source code of this file.

Macros

#define CBOR_1_BYTE   ((uint8_t) 24)
 
#define CBOR_2_BYTE   ((uint8_t) 25)
 
#define CBOR_4_BYTE   ((uint8_t) 26)
 
#define CBOR_8_BYTE   ((uint8_t) 27)
 
#define CBOR_ARRAY   (4)
 
#define cbor_encode_array(_dbuff, _size)   cbor_encode_integer(_dbuff, CBOR_ARRAY, _size);
 
#define cbor_encode_key   cbor_encode_int64
 
#define cbor_encode_tag(_dbuff, _tag)   cbor_encode_integer(_dbuff, CBOR_TAG, _tag);
 
#define CBOR_FLOAT   (7)
 
#define CBOR_INTEGER   (0)
 
#define CBOR_MAP   (5)
 
#define CBOR_NEGATIVE   (1)
 
#define CBOR_OCTETS   (2)
 
#define CBOR_STRING   (3)
 
#define CBOR_TAG   (6)
 
#define return_slen   return slen - fr_dbuff_used(&work_dbuff)
 

Typedefs

typedef ssize_t(* cbor_decode_type_t) (TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 

Functions

static ssize_t cbor_decode_count (uint64_t *out, int expected, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_date (UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_ethernet (UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_int64 (int64_t *out, fr_dbuff_t *dbuff, fr_type_t type)
 
static ssize_t cbor_decode_integer (uint64_t *out, uint8_t info, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_ipv4_addr (UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_ipv4_prefix (UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_ipv6_addr (UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_ipv6_prefix (UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_octets_memcpy (uint8_t *dst, size_t dst_min, size_t dst_max, fr_dbuff_t *dbuff)
 
static ssize_t cbor_decode_time_delta (UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
 
static ssize_t cbor_encode_int64 (fr_dbuff_t *dbuff, int64_t neg)
 
static ssize_t cbor_encode_integer (fr_dbuff_t *dbuff, uint8_t type, uint64_t data)
 
static ssize_t cbor_encode_octets (fr_dbuff_t *dbuff, uint8_t const *data, size_t data_len)
 
static fr_type_t cbor_guess_type (fr_dbuff_t *dbuff, bool pair)
 Guess the data type of the CBOR data. More...
 
ssize_t fr_cbor_decode_pair (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dbuff_t *dbuff, fr_dict_attr_t const *parent, bool tainted)
 
ssize_t fr_cbor_decode_value_box (TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff, fr_type_t type, fr_dict_attr_t const *enumv, bool tainted)
 
ssize_t fr_cbor_encode_pair (fr_dbuff_t *dbuff, fr_pair_t *vp)
 Encode a pair. More...
 
ssize_t fr_cbor_encode_value_box (fr_dbuff_t *dbuff, fr_value_box_t *vb)
 Encode CBOR. More...
 

Variables

static cbor_decode_type_t cbor_decode_type [FR_TYPE_MAX]
 
static const char * cbor_type_to_str [8]
 
static const uint64_t cbor_type_to_tag [FR_TYPE_MAX+1]
 

Detailed Description

CBPR encoding and decoding.

Definition in file cbor.c.

Macro Definition Documentation

◆ CBOR_1_BYTE

#define CBOR_1_BYTE   ((uint8_t) 24)

Definition at line 36 of file cbor.c.

◆ CBOR_2_BYTE

#define CBOR_2_BYTE   ((uint8_t) 25)

Definition at line 37 of file cbor.c.

◆ CBOR_4_BYTE

#define CBOR_4_BYTE   ((uint8_t) 26)

Definition at line 38 of file cbor.c.

◆ CBOR_8_BYTE

#define CBOR_8_BYTE   ((uint8_t) 27)

Definition at line 39 of file cbor.c.

◆ CBOR_ARRAY

#define CBOR_ARRAY   (4)

Definition at line 31 of file cbor.c.

◆ cbor_encode_array

#define cbor_encode_array (   _dbuff,
  _size 
)    cbor_encode_integer(_dbuff, CBOR_ARRAY, _size);

Definition at line 116 of file cbor.c.

◆ cbor_encode_key

#define cbor_encode_key   cbor_encode_int64

Definition at line 160 of file cbor.c.

◆ cbor_encode_tag

#define cbor_encode_tag (   _dbuff,
  _tag 
)    cbor_encode_integer(_dbuff, CBOR_TAG, _tag);

Definition at line 118 of file cbor.c.

◆ CBOR_FLOAT

#define CBOR_FLOAT   (7)

Definition at line 34 of file cbor.c.

◆ CBOR_INTEGER

#define CBOR_INTEGER   (0)

Definition at line 27 of file cbor.c.

◆ CBOR_MAP

#define CBOR_MAP   (5)

Definition at line 32 of file cbor.c.

◆ CBOR_NEGATIVE

#define CBOR_NEGATIVE   (1)

Definition at line 28 of file cbor.c.

◆ CBOR_OCTETS

#define CBOR_OCTETS   (2)

Definition at line 29 of file cbor.c.

◆ CBOR_STRING

#define CBOR_STRING   (3)

Definition at line 30 of file cbor.c.

◆ CBOR_TAG

#define CBOR_TAG   (6)

Definition at line 33 of file cbor.c.

◆ return_slen

#define return_slen   return slen - fr_dbuff_used(&work_dbuff)

Definition at line 123 of file cbor.c.

Typedef Documentation

◆ cbor_decode_type_t

typedef ssize_t(* cbor_decode_type_t) (TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)

Definition at line 558 of file cbor.c.

Function Documentation

◆ cbor_decode_count()

static ssize_t cbor_decode_count ( uint64_t *  out,
int  expected,
fr_dbuff_t dbuff 
)
static

Definition at line 535 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cbor_decode_date()

static ssize_t cbor_decode_date ( UNUSED TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff 
)
static

Definition at line 871 of file cbor.c.

+ Here is the call graph for this function:

◆ cbor_decode_ethernet()

static ssize_t cbor_decode_ethernet ( UNUSED TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff 
)
static

Definition at line 613 of file cbor.c.

+ Here is the call graph for this function:

◆ cbor_decode_int64()

static ssize_t cbor_decode_int64 ( int64_t *  out,
fr_dbuff_t dbuff,
fr_type_t  type 
)
static

Definition at line 817 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cbor_decode_integer()

static ssize_t cbor_decode_integer ( uint64_t *  out,
uint8_t  info,
fr_dbuff_t dbuff 
)
static

Definition at line 486 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cbor_decode_ipv4_addr()

static ssize_t cbor_decode_ipv4_addr ( UNUSED TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff 
)
static

Definition at line 618 of file cbor.c.

+ Here is the call graph for this function:

◆ cbor_decode_ipv4_prefix()

static ssize_t cbor_decode_ipv4_prefix ( UNUSED TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff 
)
static

Definition at line 735 of file cbor.c.

+ Here is the call graph for this function:

◆ cbor_decode_ipv6_addr()

static ssize_t cbor_decode_ipv6_addr ( UNUSED TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff 
)
static

Definition at line 676 of file cbor.c.

+ Here is the call graph for this function:

◆ cbor_decode_ipv6_prefix()

static ssize_t cbor_decode_ipv6_prefix ( UNUSED TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff 
)
static

Definition at line 776 of file cbor.c.

+ Here is the call graph for this function:

◆ cbor_decode_octets_memcpy()

static ssize_t cbor_decode_octets_memcpy ( uint8_t dst,
size_t  dst_min,
size_t  dst_max,
fr_dbuff_t dbuff 
)
static

Definition at line 560 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cbor_decode_time_delta()

static ssize_t cbor_decode_time_delta ( UNUSED TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff 
)
static

Definition at line 890 of file cbor.c.

+ Here is the call graph for this function:

◆ cbor_encode_int64()

static ssize_t cbor_encode_int64 ( fr_dbuff_t dbuff,
int64_t  neg 
)
static

Definition at line 141 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cbor_encode_integer()

static ssize_t cbor_encode_integer ( fr_dbuff_t dbuff,
uint8_t  type,
uint64_t  data 
)
static

Definition at line 65 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cbor_encode_octets()

static ssize_t cbor_encode_octets ( fr_dbuff_t dbuff,
uint8_t const *  data,
size_t  data_len 
)
static

Definition at line 128 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cbor_guess_type()

static fr_type_t cbor_guess_type ( fr_dbuff_t dbuff,
bool  pair 
)
static

Guess the data type of the CBOR data.

We've parsed the attribute number, and found that we don't have a dictionary entry for it. But rather than create an attribute of type octets, we try to guess the data type.

Definition at line 1526 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_cbor_decode_pair()

ssize_t fr_cbor_decode_pair ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dbuff_t dbuff,
fr_dict_attr_t const *  parent,
bool  tainted 
)

Definition at line 1629 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_cbor_decode_value_box()

ssize_t fr_cbor_decode_value_box ( TALLOC_CTX *  ctx,
fr_value_box_t vb,
fr_dbuff_t dbuff,
fr_type_t  type,
fr_dict_attr_t const *  enumv,
bool  tainted 
)

Definition at line 989 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_cbor_encode_pair()

ssize_t fr_cbor_encode_pair ( fr_dbuff_t dbuff,
fr_pair_t vp 
)

Encode a pair.

Definition at line 1436 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_cbor_encode_value_box()

ssize_t fr_cbor_encode_value_box ( fr_dbuff_t dbuff,
fr_value_box_t vb 
)

Encode CBOR.

Values 0..23 can be encoded in place. Other values can be encoded using the closest smallest integer

Definition at line 166 of file cbor.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ cbor_decode_type

cbor_decode_type_t cbor_decode_type[FR_TYPE_MAX]
static
Initial value:
= {
}
static ssize_t cbor_decode_ipv4_addr(UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
Definition: cbor.c:618
static ssize_t cbor_decode_ipv6_addr(UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
Definition: cbor.c:676
static ssize_t cbor_decode_date(UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
Definition: cbor.c:871
static ssize_t cbor_decode_time_delta(UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
Definition: cbor.c:890
static ssize_t cbor_decode_ipv4_prefix(UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
Definition: cbor.c:735
static ssize_t cbor_decode_ethernet(UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
Definition: cbor.c:613
static ssize_t cbor_decode_ipv6_prefix(UNUSED TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t *dbuff)
Definition: cbor.c:776
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
Definition: merged_model.c:113
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
Definition: merged_model.c:86
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
Definition: merged_model.c:93
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
Definition: merged_model.c:89
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
Definition: merged_model.c:111
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
Definition: merged_model.c:88
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
Definition: merged_model.c:87

Definition at line 972 of file cbor.c.

◆ cbor_type_to_str

const char* cbor_type_to_str[8]
static
Initial value:
= {
"integer", "negative", "octets", "string",
"array", "map", "tag", "float"
}

Definition at line 41 of file cbor.c.

◆ cbor_type_to_tag

const uint64_t cbor_type_to_tag[FR_TYPE_MAX+1]
static
Initial value:

Definition at line 53 of file cbor.c.