libcoap 4.3.5-develop-ea01661
Loading...
Searching...
No Matches
oscore_cbor.h
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3/*
4 * Copyright (c) 2018, SICS, RISE AB
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Institute nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
47#ifndef _OSCORE_CBOR_H
48#define _OSCORE_CBOR_H
49#include <stddef.h>
50#include <stdint.h>
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
63/* CBOR major types */
64#define CBOR_UNSIGNED_INTEGER 0
65#define CBOR_NEGATIVE_INTEGER 1
66#define CBOR_BYTE_STRING 2
67#define CBOR_TEXT_STRING 3
68#define CBOR_ARRAY 4
69#define CBOR_MAP 5
70#define CBOR_TAG 6
71#define CBOR_SIMPLE_VALUE 7
72#define CBOR_FLOATING_POINT 7
73
74#define CBOR_FALSE 20
75#define CBOR_TRUE 21
76#define CBOR_NULL 22
77
78size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size);
79
80size_t oscore_cbor_put_true(uint8_t **buffer, size_t *buf_size);
81
82size_t oscore_cbor_put_false(uint8_t **buffer, size_t *buf_size);
83
84size_t oscore_cbor_put_text(uint8_t **buffer,
85 size_t *buf_size,
86 const char *text,
87 size_t text_len);
88
89size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements);
90
91size_t oscore_cbor_put_bytes(uint8_t **buffer,
92 size_t *buf_size,
93 const uint8_t *bytes,
94 size_t bytes_len);
95
96size_t oscore_cbor_put_map(uint8_t **buffer, size_t *buf_size, size_t elements);
97
98size_t oscore_cbor_put_number(uint8_t **buffer, size_t *buf_size, int64_t value);
99
100size_t oscore_cbor_put_simple_value(uint8_t **buffer, size_t *buf_size, uint8_t value);
101
102size_t oscore_cbor_put_unsigned(uint8_t **buffer, size_t *buf_size, uint64_t value);
103
104size_t oscore_cbor_put_tag(uint8_t **buffer, size_t *buf_size, uint64_t value);
105
106size_t oscore_cbor_put_negative(uint8_t **buffer, size_t *buf_size, int64_t value);
107
108uint8_t oscore_cbor_get_next_element(const uint8_t **buffer, size_t *buf_size);
109
110size_t oscore_cbor_get_element_size(const uint8_t **buffer, size_t *buf_size);
111
112uint8_t oscore_cbor_elem_contained(const uint8_t *data, size_t *buf_size,
113 uint8_t *end);
114
115uint8_t oscore_cbor_get_number(const uint8_t **data, size_t *buf_size,
116 int64_t *value);
117
118uint8_t oscore_cbor_get_simple_value(const uint8_t **data, size_t *buf_size,
119 uint8_t *value);
120
121int64_t oscore_cbor_get_negative_integer(const uint8_t **buffer,
122 size_t *buf_size);
123
124uint64_t oscore_cbor_get_unsigned_integer(const uint8_t **buffer,
125 size_t *buf_size);
126
127void oscore_cbor_get_string(const uint8_t **buffer, size_t *buf_size,
128 char *str, size_t size);
129
130void oscore_cbor_get_array(const uint8_t **buffer, size_t *buf_size,
131 uint8_t *arr, size_t size);
132
133/* oscore_cbor_get_string_array
134 * fills the the size and the array from the cbor element
135 */
136uint8_t oscore_cbor_get_string_array(const uint8_t **data, size_t *buf_size,
137 uint8_t **result, size_t *len);
138
139/* oscore_cbor_strip value
140 * strips the value of the cbor element into result
141 * and returns size
142 */
143uint8_t oscore_cbor_strip_value(const uint8_t **data, size_t *buf_size,
144 uint8_t **result, size_t *len);
145
148#ifdef __cplusplus
149}
150#endif
151
152#endif /* _OSCORE_CBOR_H */
size_t oscore_cbor_put_text(uint8_t **buffer, size_t *buf_size, const char *text, size_t text_len)
Definition oscore_cbor.c:77
size_t oscore_cbor_get_element_size(const uint8_t **buffer, size_t *buf_size)
int64_t oscore_cbor_get_negative_integer(const uint8_t **buffer, size_t *buf_size)
size_t oscore_cbor_put_number(uint8_t **buffer, size_t *buf_size, int64_t value)
size_t oscore_cbor_put_simple_value(uint8_t **buffer, size_t *buf_size, uint8_t value)
uint8_t oscore_cbor_get_string_array(const uint8_t **data, size_t *buf_size, uint8_t **result, size_t *len)
uint8_t oscore_cbor_strip_value(const uint8_t **data, size_t *buf_size, uint8_t **result, size_t *len)
size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size)
Definition oscore_cbor.c:59
void oscore_cbor_get_string(const uint8_t **buffer, size_t *buf_size, char *str, size_t size)
uint8_t oscore_cbor_get_simple_value(const uint8_t **data, size_t *buf_size, uint8_t *value)
size_t oscore_cbor_put_false(uint8_t **buffer, size_t *buf_size)
Definition oscore_cbor.c:71
uint8_t oscore_cbor_get_next_element(const uint8_t **buffer, size_t *buf_size)
size_t oscore_cbor_put_negative(uint8_t **buffer, size_t *buf_size, int64_t value)
size_t oscore_cbor_put_true(uint8_t **buffer, size_t *buf_size)
Definition oscore_cbor.c:65
size_t oscore_cbor_put_unsigned(uint8_t **buffer, size_t *buf_size, uint64_t value)
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
void oscore_cbor_get_array(const uint8_t **buffer, size_t *buf_size, uint8_t *arr, size_t size)
uint64_t oscore_cbor_get_unsigned_integer(const uint8_t **buffer, size_t *buf_size)
uint8_t oscore_cbor_elem_contained(const uint8_t *data, size_t *buf_size, uint8_t *end)
uint8_t oscore_cbor_get_number(const uint8_t **data, size_t *buf_size, int64_t *value)
size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements)
Definition oscore_cbor.c:92
size_t oscore_cbor_put_map(uint8_t **buffer, size_t *buf_size, size_t elements)
size_t oscore_cbor_put_tag(uint8_t **buffer, size_t *buf_size, uint64_t value)