libcoap 4.3.5-develop-19cef11
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
59/* CBOR major types */
60#define CBOR_UNSIGNED_INTEGER 0
61#define CBOR_NEGATIVE_INTEGER 1
62#define CBOR_BYTE_STRING 2
63#define CBOR_TEXT_STRING 3
64#define CBOR_ARRAY 4
65#define CBOR_MAP 5
66#define CBOR_TAG 6
67#define CBOR_SIMPLE_VALUE 7
68#define CBOR_FLOATING_POINT 7
69
70#define CBOR_FALSE 20
71#define CBOR_TRUE 21
72#define CBOR_NULL 22
73
74size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size);
75
76size_t oscore_cbor_put_true(uint8_t **buffer, size_t *buf_size);
77
78size_t oscore_cbor_put_false(uint8_t **buffer, size_t *buf_size);
79
80size_t oscore_cbor_put_text(uint8_t **buffer,
81 size_t *buf_size,
82 const char *text,
83 size_t text_len);
84
85size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements);
86
87size_t oscore_cbor_put_bytes(uint8_t **buffer,
88 size_t *buf_size,
89 const uint8_t *bytes,
90 size_t bytes_len);
91
92size_t oscore_cbor_put_map(uint8_t **buffer, size_t *buf_size, size_t elements);
93
94size_t oscore_cbor_put_number(uint8_t **buffer, size_t *buf_size, int64_t value);
95
96size_t oscore_cbor_put_simple_value(uint8_t **buffer, size_t *buf_size, uint8_t value);
97
98size_t oscore_cbor_put_unsigned(uint8_t **buffer, size_t *buf_size, uint64_t value);
99
100size_t oscore_cbor_put_tag(uint8_t **buffer, size_t *buf_size, uint64_t value);
101
102size_t oscore_cbor_put_negative(uint8_t **buffer, size_t *buf_size, int64_t value);
103
104uint8_t oscore_cbor_get_next_element(const uint8_t **buffer, size_t *buf_size);
105
106size_t oscore_cbor_get_element_size(const uint8_t **buffer, size_t *buf_size);
107
108uint8_t oscore_cbor_elem_contained(const uint8_t *data, size_t *buf_size,
109 uint8_t *end);
110
111uint8_t oscore_cbor_get_number(const uint8_t **data, size_t *buf_size,
112 int64_t *value);
113
114uint8_t oscore_cbor_get_simple_value(const uint8_t **data, size_t *buf_size,
115 uint8_t *value);
116
117int64_t oscore_cbor_get_negative_integer(const uint8_t **buffer,
118 size_t *buf_size);
119
120uint64_t oscore_cbor_get_unsigned_integer(const uint8_t **buffer,
121 size_t *buf_size);
122
123void oscore_cbor_get_string(const uint8_t **buffer, size_t *buf_size,
124 char *str, size_t size);
125
126void oscore_cbor_get_array(const uint8_t **buffer, size_t *buf_size,
127 uint8_t *arr, size_t size);
128
129/* oscore_cbor_get_string_array
130 * fills the the size and the array from the cbor element
131 */
132uint8_t oscore_cbor_get_string_array(const uint8_t **data, size_t *buf_size,
133 uint8_t **result, size_t *len);
134
135/* oscore_cbor_strip value
136 * strips the value of the cbor element into result
137 * and returns size
138 */
139uint8_t oscore_cbor_strip_value(const uint8_t **data, size_t *buf_size,
140 uint8_t **result, size_t *len);
141
144#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)
Definition: oscore_cbor.c:240
int64_t oscore_cbor_get_negative_integer(const uint8_t **buffer, size_t *buf_size)
Definition: oscore_cbor.c:271
size_t oscore_cbor_put_number(uint8_t **buffer, size_t *buf_size, int64_t value)
Definition: oscore_cbor.c:123
size_t oscore_cbor_put_simple_value(uint8_t **buffer, size_t *buf_size, uint8_t value)
Definition: oscore_cbor.c:131
uint8_t oscore_cbor_get_string_array(const uint8_t **data, size_t *buf_size, uint8_t **result, size_t *len)
Definition: oscore_cbor.c:335
uint8_t oscore_cbor_strip_value(const uint8_t **data, size_t *buf_size, uint8_t **result, size_t *len)
Definition: oscore_cbor.c:421
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)
Definition: oscore_cbor.c:316
uint8_t oscore_cbor_get_simple_value(const uint8_t **data, size_t *buf_size, uint8_t *value)
Definition: oscore_cbor.c:306
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)
Definition: oscore_cbor.c:227
size_t oscore_cbor_put_negative(uint8_t **buffer, size_t *buf_size, int64_t value)
Definition: oscore_cbor.c:149
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)
Definition: oscore_cbor.c:168
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
Definition: oscore_cbor.c:100
void oscore_cbor_get_array(const uint8_t **buffer, size_t *buf_size, uint8_t *arr, size_t size)
Definition: oscore_cbor.c:324
uint64_t oscore_cbor_get_unsigned_integer(const uint8_t **buffer, size_t *buf_size)
Definition: oscore_cbor.c:276
uint8_t oscore_cbor_elem_contained(const uint8_t *data, size_t *buf_size, uint8_t *end)
Definition: oscore_cbor.c:260
uint8_t oscore_cbor_get_number(const uint8_t **data, size_t *buf_size, int64_t *value)
Definition: oscore_cbor.c:287
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)
Definition: oscore_cbor.c:115
size_t oscore_cbor_put_tag(uint8_t **buffer, size_t *buf_size, uint64_t value)
Definition: oscore_cbor.c:141