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 33 /** 34 * @file oscore_cbor.h 35 * @brief An implementation of the Concise Binary Object Representation (RFC). 36 * 37 * \author 38 * Martin Gunnarsson <martin.gunnarsson@ri.se> 39 * extended for libcoap by: 40 * Peter van der Stok <consultancy@vanderstok.org> 41 * on request of Fairhair alliance 42 * adapted for libcoap integration 43 * Jon Shallow <supjps-libcoap@jpshallow.com> 44 * 45 */ 46 47 #ifndef _OSCORE_CBOR_H 48 #define _OSCORE_CBOR_H 49 #include <stddef.h> 50 #include <stdint.h> 51 52 /** 53 * @ingroup internal_api 54 * @defgroup oscore_cbor_internal OSCORE CBOR Support 55 * Internal API for interfacing with OSCORE CBOR 56 * @{ 57 */ 58 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 74 size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size); 75 76 size_t oscore_cbor_put_true(uint8_t **buffer, size_t *buf_size); 77 78 size_t oscore_cbor_put_false(uint8_t **buffer, size_t *buf_size); 79 80 size_t oscore_cbor_put_text(uint8_t **buffer, 81 size_t *buf_size, 82 const char *text, 83 size_t text_len); 84 85 size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements); 86 87 size_t oscore_cbor_put_bytes(uint8_t **buffer, 88 size_t *buf_size, 89 const uint8_t *bytes, 90 size_t bytes_len); 91 92 size_t oscore_cbor_put_map(uint8_t **buffer, size_t *buf_size, size_t elements); 93 94 size_t oscore_cbor_put_number(uint8_t **buffer, size_t *buf_size, int64_t value); 95 96 size_t oscore_cbor_put_simple_value(uint8_t **buffer, size_t *buf_size, uint8_t value); 97 98 size_t oscore_cbor_put_unsigned(uint8_t **buffer, size_t *buf_size, uint64_t value); 99 100 size_t oscore_cbor_put_tag(uint8_t **buffer, size_t *buf_size, uint64_t value); 101 102 size_t oscore_cbor_put_negative(uint8_t **buffer, size_t *buf_size, int64_t value); 103 104 uint8_t oscore_cbor_get_next_element(const uint8_t **buffer, size_t *buf_size); 105 106 size_t oscore_cbor_get_element_size(const uint8_t **buffer, size_t *buf_size); 107 108 uint8_t oscore_cbor_elem_contained(const uint8_t *data, size_t *buf_size, 109 uint8_t *end); 110 111 uint8_t oscore_cbor_get_number(const uint8_t **data, size_t *buf_size, 112 int64_t *value); 113 114 uint8_t oscore_cbor_get_simple_value(const uint8_t **data, size_t *buf_size, 115 uint8_t *value); 116 117 int64_t oscore_cbor_get_negative_integer(const uint8_t **buffer, 118 size_t *buf_size); 119 120 uint64_t oscore_cbor_get_unsigned_integer(const uint8_t **buffer, 121 size_t *buf_size); 122 123 void oscore_cbor_get_string(const uint8_t **buffer, size_t *buf_size, 124 char *str, size_t size); 125 126 void 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 */ 132 uint8_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 */ 139 uint8_t oscore_cbor_strip_value(const uint8_t **data, size_t *buf_size, 140 uint8_t **result, size_t *len); 141 142 /** @} */ 143 144 #endif /* _OSCORE_CBOR_H */ 145