Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 Intel Corporation |
| 4 | ** |
| 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | ** of this software and associated documentation files (the "Software"), to deal |
| 7 | ** in the Software without restriction, including without limitation the rights |
| 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | ** copies of the Software, and to permit persons to whom the Software is |
| 10 | ** furnished to do so, subject to the following conditions: |
| 11 | ** |
| 12 | ** The above copyright notice and this permission notice shall be included in |
| 13 | ** all copies or substantial portions of the Software. |
| 14 | ** |
| 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | ** THE SOFTWARE. |
| 22 | ** |
| 23 | ****************************************************************************/ |
| 24 | |
| 25 | #define _BSD_SOURCE |
| 26 | #include "cbor.h" |
| 27 | #include "cborconstants_p.h" |
| 28 | #include "compilersupport_p.h" |
| 29 | |
| 30 | #include <assert.h> |
| 31 | #include <endian.h> |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 32 | #include <stdlib.h> |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 33 | #include <string.h> |
| 34 | |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 35 | #ifdef NDEBUG |
| 36 | # undef assert |
| 37 | # define assert(cond) do { if (!(cond)) unreachable(); } while (0) |
| 38 | #endif |
| 39 | |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 40 | #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) && \ |
| 41 | (__GNUC__ * 100 + __GNUC_MINOR__ >= 404) |
| 42 | # pragma GCC optimize("-ffunction-sections") |
| 43 | #endif |
| 44 | |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 45 | /** |
| 46 | * \typedef CborValue |
| 47 | * This type contains one value parsed from the CBOR stream. |
| 48 | * |
| 49 | * To get the actual type, use cbor_value_get_type(). Then extract the value |
| 50 | * using one of the corresponding functions: cbor_value_get_boolean(), cbor_value_get_int64(), |
| 51 | * cbor_value_get_int(), cbor_value_copy_string(), cbor_value_get_array(), cbor_value_get_map(), |
| 52 | * cbor_value_get_double(), cbor_value_get_float(). |
| 53 | * |
| 54 | * In C++ and C11 modes, you can additionally use the cbor_value_get_integer() |
| 55 | * and cbor_value_get_floating_point() generic functions. |
| 56 | * |
| 57 | * \omit |
| 58 | * Implementation details: the CborValue contains these fields: |
| 59 | * \list |
| 60 | * \li ptr: pointer to the actual data |
| 61 | * \li flags: flags from the decoder |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 62 | * \li extra: partially decoded integer value (0, 1 or 2 bytes) |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 63 | * \li remaining: remaining items in this collection after this item or UINT32_MAX if length is unknown |
| 64 | * \endlist |
| 65 | * \endomit |
| 66 | */ |
| 67 | |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 68 | static inline uint16_t get16(const char *ptr) |
| 69 | { |
| 70 | uint16_t result; |
| 71 | memcpy(&result, ptr, sizeof(result)); |
| 72 | return be16toh(result); |
| 73 | } |
| 74 | |
| 75 | static inline uint32_t get32(const char *ptr) |
| 76 | { |
| 77 | uint32_t result; |
| 78 | memcpy(&result, ptr, sizeof(result)); |
| 79 | return be32toh(result); |
| 80 | } |
| 81 | |
| 82 | static inline uint64_t get64(const char *ptr) |
| 83 | { |
| 84 | uint64_t result; |
| 85 | memcpy(&result, ptr, sizeof(result)); |
| 86 | return be64toh(result); |
| 87 | } |
| 88 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 89 | static inline CborError extract_number(const CborParser *parser, const char **ptr, uint64_t *len) |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 90 | { |
| 91 | uint8_t additional_information = **ptr & SmallValueMask; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 92 | ++*ptr; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 93 | if (additional_information < Value8Bit) { |
| 94 | *len = additional_information; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 95 | return CborNoError; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 96 | } |
| 97 | if (unlikely(additional_information > Value64Bit)) |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 98 | return CborErrorIllegalNumber; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 99 | |
| 100 | size_t bytesNeeded = 1 << (additional_information - Value8Bit); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 101 | if (unlikely(*ptr + bytesNeeded > parser->end)) { |
| 102 | return CborErrorUnexpectedEOF; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 103 | } else if (bytesNeeded == 1) { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 104 | *len = (uint8_t)(*ptr)[0]; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 105 | } else if (bytesNeeded == 2) { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 106 | *len = get16(*ptr); |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 107 | } else if (bytesNeeded == 4) { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 108 | *len = get32(*ptr); |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 109 | } else { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 110 | *len = get64(*ptr); |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 111 | } |
| 112 | *ptr += bytesNeeded; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 113 | return CborNoError; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 116 | static inline CborError extract_length(const CborParser *parser, const char **ptr, size_t *len) |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 117 | { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 118 | uint64_t v; |
| 119 | CborError err = extract_number(parser, ptr, &v); |
| 120 | if (err) |
| 121 | return err; |
| 122 | |
| 123 | *len = v; |
| 124 | if (v != *len) |
| 125 | return CborErrorDataTooLarge; |
| 126 | return CborNoError; |
| 127 | } |
| 128 | |
| 129 | static bool is_fixed_type(uint8_t type) |
| 130 | { |
| 131 | return type != CborTextStringType && type != CborByteStringType && type != CborArrayType && |
| 132 | type != CborMapType; |
| 133 | } |
| 134 | |
| 135 | static CborError preparse_value(CborValue *it) |
| 136 | { |
| 137 | const CborParser *parser = it->parser; |
Thiago Macieira | 11e913f | 2015-05-07 13:01:18 -0700 | [diff] [blame] | 138 | it->type = CborInvalidType; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 139 | |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 140 | // are we at the end? |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 141 | if (it->ptr == parser->end) |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 142 | return CborErrorUnexpectedEOF; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 143 | |
| 144 | uint8_t descriptor = *it->ptr; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 145 | uint8_t type = descriptor & MajorTypeMask; |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 146 | it->type = type; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 147 | it->flags = 0; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 148 | it->extra = (descriptor &= SmallValueMask); |
| 149 | |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 150 | if (descriptor > Value64Bit) { |
| 151 | if (unlikely(descriptor != IndefiniteLength)) |
| 152 | return CborErrorIllegalNumber; |
| 153 | if (likely(!is_fixed_type(type))) { |
| 154 | // special case |
| 155 | it->flags |= CborIteratorFlag_UnknownLength; |
| 156 | it->type = type; |
| 157 | return CborNoError; |
| 158 | } |
| 159 | return type == CborSimpleType ? CborErrorUnexpectedBreak : CborErrorIllegalNumber; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 160 | } |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 161 | |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 162 | size_t bytesNeeded = descriptor < Value8Bit ? 0 : (1 << (descriptor - Value8Bit)); |
| 163 | if (it->ptr + 1 + bytesNeeded > parser->end) |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 164 | return CborErrorUnexpectedEOF; |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 165 | |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 166 | uint8_t majortype = type >> MajorTypeShift; |
| 167 | if (majortype == NegativeIntegerType) { |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 168 | it->flags |= CborIteratorFlag_NegativeInteger; |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 169 | it->type = CborIntegerType; |
| 170 | } else if (majortype == SimpleTypesType) { |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 171 | switch (descriptor) { |
| 172 | case FalseValue: |
| 173 | it->extra = false; |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 174 | it->type = CborBooleanType; |
Thiago Macieira | 991dd92 | 2015-05-07 11:57:59 -0700 | [diff] [blame] | 175 | break; |
| 176 | |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 177 | case SinglePrecisionFloat: |
| 178 | case DoublePrecisionFloat: |
| 179 | it->flags |= CborIteratorFlag_IntegerValueTooLarge; |
| 180 | // fall through |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 181 | case TrueValue: |
| 182 | case NullValue: |
| 183 | case UndefinedValue: |
| 184 | case HalfPrecisionFloat: |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 185 | it->type = *it->ptr; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 186 | break; |
| 187 | |
| 188 | case SimpleTypeInNextByte: |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 189 | it->extra = (uint8_t)it->ptr[1]; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 190 | #ifndef CBOR_PARSER_NO_STRICT_CHECKS |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 191 | if (unlikely(it->extra < 32)) { |
| 192 | it->type = CborInvalidType; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 193 | return CborErrorIllegalSimpleType; |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 194 | } |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 195 | #endif |
Thiago Macieira | 991dd92 | 2015-05-07 11:57:59 -0700 | [diff] [blame] | 196 | break; |
| 197 | |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 198 | case 28: |
| 199 | case 29: |
| 200 | case 30: |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 201 | case Break: |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 202 | assert(false); // these conditions can't be reached |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 203 | return CborErrorUnexpectedBreak; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 204 | } |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 205 | return CborNoError; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | // try to decode up to 16 bits |
| 209 | if (descriptor < Value8Bit) |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 210 | return CborNoError; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 211 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 212 | if (descriptor == Value8Bit) |
| 213 | it->extra = (uint8_t)it->ptr[1]; |
| 214 | else if (descriptor == Value16Bit) |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 215 | it->extra = get16(it->ptr + 1); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 216 | else |
| 217 | it->flags |= CborIteratorFlag_IntegerValueTooLarge; // Value32Bit or Value64Bit |
| 218 | return CborNoError; |
| 219 | } |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 220 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 221 | static CborError preparse_next_value(CborValue *it) |
| 222 | { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 223 | if (it->remaining != UINT32_MAX) { |
Thiago Macieira | 11e913f | 2015-05-07 13:01:18 -0700 | [diff] [blame] | 224 | // don't decrement the item count if the current item is tag: they don't count |
| 225 | if (it->type != CborTagType && !--it->remaining) { |
| 226 | it->type = CborInvalidType; |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 227 | return CborNoError; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 228 | } |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 229 | } else if (it->remaining == UINT32_MAX && it->ptr != it->parser->end && *it->ptr == (char)BreakByte) { |
| 230 | // end of map or array |
| 231 | ++it->ptr; |
| 232 | it->type = CborInvalidType; |
| 233 | it->remaining = 0; |
| 234 | return CborNoError; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 235 | } |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 236 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 237 | return preparse_value(it); |
| 238 | } |
| 239 | |
| 240 | static CborError advance_internal(CborValue *it) |
| 241 | { |
| 242 | uint64_t length; |
| 243 | CborError err = extract_number(it->parser, &it->ptr, &length); |
| 244 | assert(err == CborNoError); |
| 245 | |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 246 | if (it->type == CborByteStringType || it->type == CborTextStringType) { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 247 | assert(length == (size_t)length); |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 248 | assert((it->flags & CborIteratorFlag_UnknownLength) == 0); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 249 | it->ptr += length; |
| 250 | } |
| 251 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 252 | return preparse_next_value(it); |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 255 | /** \internal |
| 256 | * |
| 257 | * Decodes the CBOR integer value when it is larger than the 16 bits available |
| 258 | * in value->extra. This function requires that value->flags have the |
| 259 | * CborIteratorFlag_IntegerValueTooLarge flag set. |
| 260 | * |
| 261 | * This function is also used to extract single- and double-precision floating |
| 262 | * point values (SinglePrecisionFloat == Value32Bit and DoublePrecisionFloat == |
| 263 | * Value64Bit). |
| 264 | */ |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 265 | uint64_t _cbor_value_decode_int64_internal(const CborValue *value) |
| 266 | { |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 267 | assert(value->flags & CborIteratorFlag_IntegerValueTooLarge || |
| 268 | value->type == CborFloatType || value->type == CborDoubleType); |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 269 | |
| 270 | // since the additional information can only be Value32Bit or Value64Bit, |
| 271 | // we just need to test for the one bit those two options differ |
| 272 | assert((*value->ptr & SmallValueMask) == Value32Bit || (*value->ptr & SmallValueMask) == Value64Bit); |
| 273 | if ((*value->ptr & 1) == (Value32Bit & 1)) |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 274 | return get32(value->ptr + 1); |
| 275 | |
| 276 | assert((*value->ptr & SmallValueMask) == Value64Bit); |
| 277 | return get64(value->ptr + 1); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Initializes the CBOR parser for parsing \a size bytes beginning at \a |
| 282 | * buffer. Parsing will use flags set in \a flags. The iterator to the first |
| 283 | * element is returned in \a it. |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 284 | * |
| 285 | * The \a parser structure needs to remain valid throughout the decoding |
| 286 | * process. It is not thread-safe to share one CborParser among multiple |
| 287 | * threads iterating at the same time, but the object can be copied so multiple |
| 288 | * threads can iterate. |
| 289 | * |
| 290 | * ### Write how to determine the end pointer |
| 291 | * ### Write how to do limited-buffer windowed decoding |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 292 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 293 | CborError cbor_parser_init(const char *buffer, size_t size, int flags, CborParser *parser, CborValue *it) |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 294 | { |
| 295 | memset(parser, 0, sizeof(*parser)); |
| 296 | parser->end = buffer + size; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 297 | parser->flags = flags; |
| 298 | it->parser = parser; |
| 299 | it->ptr = buffer; |
| 300 | it->remaining = 1; // there's one type altogether, usually an array or map |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 301 | return preparse_value(it); |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Advances the CBOR value \a it by one fixed-size position. Fixed-size types |
| 306 | * are: integers, tags, simple types (including boolean, null and undefined |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 307 | * values) and floating point types. |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 308 | * |
| 309 | * \sa cbor_value_at_end(), cbor_value_advance(), cbor_value_begin_recurse(), cbor_value_end_recurse() |
| 310 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 311 | CborError cbor_value_advance_fixed(CborValue *it) |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 312 | { |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 313 | assert(it->type != CborInvalidType); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 314 | assert(is_fixed_type(it->type)); |
| 315 | if (!it->remaining) |
| 316 | return CborErrorAdvancePastEOF; |
| 317 | return advance_internal(it); |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 320 | /** |
| 321 | * Advances the CBOR value \a it by one element, skipping over containers. |
| 322 | * Unlike cbor_value_advance_fixed(), this function can be called on a CBOR |
| 323 | * value of any type. However, if the type is a container (map or array) or a |
| 324 | * string with a chunked payload, this function will not run in constant time |
| 325 | * and will recurse into itself (it will run on O(n) time for the number of |
| 326 | * elements or chunks and will use O(n) memory for the number of nested |
| 327 | * containers). |
| 328 | * |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 329 | * \sa cbor_value_at_end(), cbor_value_advance_fixed(), cbor_value_begin_recurse(), cbor_value_end_recurse() |
| 330 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 331 | CborError cbor_value_advance(CborValue *it) |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 332 | { |
| 333 | assert(it->type != CborInvalidType); |
| 334 | if (!it->remaining) |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 335 | return CborErrorAdvancePastEOF; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 336 | if (is_fixed_type(it->type)) |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 337 | return advance_internal(it); |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 338 | |
Thiago Macieira | 9ae0581 | 2015-05-11 15:09:09 +0900 | [diff] [blame^] | 339 | if (!cbor_value_is_container(it)) { |
| 340 | size_t len = SIZE_MAX; |
| 341 | return cbor_value_copy_string(it, NULL, &len, it); |
| 342 | } |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 343 | |
| 344 | // map or array |
| 345 | CborError err; |
| 346 | CborValue recursed; |
| 347 | err = cbor_value_enter_container(it, &recursed); |
| 348 | if (err) |
| 349 | return err; |
| 350 | while (!cbor_value_at_end(&recursed)) { |
| 351 | err = cbor_value_advance(&recursed); |
| 352 | if (err) |
| 353 | return err; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 354 | } |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 355 | return cbor_value_leave_container(it, &recursed); |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /** |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 359 | * \fn bool cbor_value_is_container(const CborValue *it) |
| 360 | * |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 361 | * Returns true if the \a it value is a container and requires recursion in |
| 362 | * order to decode (maps and arrays), false otherwise. |
| 363 | */ |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 364 | |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 365 | /** |
| 366 | * Creates a CborValue iterator pointing to the first element of the container |
| 367 | * represented by \a it and saves it in \a recursed. The \a it container object |
| 368 | * needs to be kept and passed again to cbor_value_leave_container() in order |
| 369 | * to continue iterating past this container. |
| 370 | * |
| 371 | * \sa cbor_value_is_container(), cbor_value_leave_container(), cbor_value_advance() |
| 372 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 373 | CborError cbor_value_enter_container(const CborValue *it, CborValue *recursed) |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 374 | { |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 375 | CborError err; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 376 | assert(cbor_value_is_container(it)); |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 377 | *recursed = *it; |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 378 | |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 379 | if (it->flags & CborIteratorFlag_UnknownLength) { |
| 380 | recursed->remaining = UINT32_MAX; |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 381 | ++recursed->ptr; |
| 382 | err = preparse_value(recursed); |
| 383 | if (err != CborErrorUnexpectedBreak) |
| 384 | return err; |
| 385 | // actually, break was expected here |
| 386 | // it's just an empty container |
| 387 | ++recursed->ptr; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 388 | } else { |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 389 | uint64_t len; |
| 390 | err = extract_number(recursed->parser, &recursed->ptr, &len); |
| 391 | assert(err == CborNoError); |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 392 | |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 393 | recursed->remaining = len; |
| 394 | if (recursed->remaining != len || len == UINT32_MAX) |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 395 | return CborErrorDataTooLarge; |
Thiago Macieira | ce16f05 | 2015-05-07 23:14:25 -0700 | [diff] [blame] | 396 | if (recursed->type == CborMapType) { |
| 397 | // maps have keys and values, so we need to multiply by 2 |
| 398 | if (recursed->remaining > UINT32_MAX / 2) |
| 399 | return CborErrorDataTooLarge; |
| 400 | recursed->remaining *= 2; |
| 401 | } |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 402 | if (len != 0) |
| 403 | return preparse_value(recursed); |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 404 | } |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 405 | |
| 406 | // the case of the empty container |
| 407 | recursed->type = CborInvalidType; |
| 408 | recursed->remaining = 0; |
| 409 | return CborNoError; |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 412 | /** |
| 413 | * Updates \a it to point to the next element after the container. The \a |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 414 | * recursed object needs to point to the element obtained either by advancing |
| 415 | * the last element of the container (via cbor_value_advance(), |
| 416 | * cbor_value_advance_fixed(), a nested cbor_value_leave_container(), or the \c |
| 417 | * next pointer from cbor_value_copy_string() or cbor_value_dup_string()). |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 418 | * |
| 419 | * \sa cbor_value_enter_container(), cbor_value_at_end() |
| 420 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 421 | CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed) |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 422 | { |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 423 | assert(cbor_value_is_container(it)); |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 424 | assert(recursed->type == CborInvalidType); |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 425 | it->ptr = recursed->ptr; |
Thiago Macieira | 56d9983 | 2015-05-07 14:34:27 -0700 | [diff] [blame] | 426 | return preparse_next_value(it); |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 429 | /** |
| 430 | * Calculates the length of the string in \a value and stores the result in \a |
| 431 | * len. This function is different from cbor_value_get_string_length() in that |
| 432 | * it calculates the length even for strings sent in chunks. For that reason, |
| 433 | * this function may not run in constant time (it will run in O(n) time on the |
| 434 | * number of chunks). |
| 435 | * |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 436 | * \note On 32-bit platforms, this function will return error condition of \ref |
| 437 | * CborErrorDataTooLarge if the stream indicates a length that is too big to |
| 438 | * fit in 32-bit. |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 439 | * |
| 440 | * \sa cbor_value_get_string_length(), cbor_value_copy_string(), cbor_value_is_length_known() |
| 441 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 442 | CborError cbor_value_calculate_string_length(const CborValue *value, size_t *len) |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 443 | { |
Thiago Macieira | 9ae0581 | 2015-05-11 15:09:09 +0900 | [diff] [blame^] | 444 | *len = SIZE_MAX; |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 445 | return cbor_value_copy_string(value, NULL, len, NULL); |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 448 | /** |
| 449 | * Allocates memory for the string pointed by \a value and copies it into this |
| 450 | * buffer. The pointer to the buffer is stored in \a buffer and the number of |
| 451 | * bytes copied is stored in \a len (those variables must not be NULL). |
| 452 | * |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 453 | * If \c malloc returns a NULL pointer, this function will return error |
| 454 | * condition \ref CborErrorOutOfMemory. |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 455 | * |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 456 | * On success, \c{*buffer} will contain a valid pointer that must be freed by |
| 457 | * calling \c{free()}. This is the case even for zero-length strings. |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 458 | * |
| 459 | * The \a next pointer, if not null, will be updated to point to the next item |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 460 | * after this string. If \a value points to the last item, then \a next will be |
| 461 | * invalid. |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 462 | * |
| 463 | * \note This function does not perform UTF-8 validation on the incoming text |
| 464 | * string. |
| 465 | * |
| 466 | * \sa cbor_value_copy_string() |
| 467 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 468 | CborError cbor_value_dup_string(const CborValue *value, char **buffer, size_t *buflen, CborValue *next) |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 469 | { |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 470 | assert(buffer); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 471 | assert(buflen); |
Thiago Macieira | 851c481 | 2015-05-08 15:23:20 -0700 | [diff] [blame] | 472 | CborError err = cbor_value_copy_string(value, NULL, buflen, NULL); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 473 | if (err) |
| 474 | return err; |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 475 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 476 | ++*buflen; |
| 477 | *buffer = malloc(*buflen); |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 478 | if (!*buffer) { |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 479 | // out of memory |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 480 | return CborErrorOutOfMemory; |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 481 | } |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 482 | err = cbor_value_copy_string(value, *buffer, buflen, next); |
| 483 | if (err) { |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 484 | free(*buffer); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 485 | return err; |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 486 | } |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 487 | return CborNoError; |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Thiago Macieira | 9ae0581 | 2015-05-11 15:09:09 +0900 | [diff] [blame^] | 490 | // We return uintptr_t so that we can pass memcpy directly as the iteration |
| 491 | // function. The choice is to optimize for memcpy, which is used in the base |
| 492 | // parser API (cbor_value_copy_string), while memcmp is used in convenience API |
| 493 | // only. |
| 494 | typedef uintptr_t (*IterateFunction)(char *, const char *, size_t); |
| 495 | |
| 496 | static uintptr_t iterate_noop(char *dest, const char *src, size_t len) |
| 497 | { |
| 498 | (void)dest; |
| 499 | (void)src; |
| 500 | (void)len; |
| 501 | return true; |
| 502 | } |
| 503 | |
| 504 | static CborError iterate_string_chunks(const CborValue *value, char *buffer, size_t *buflen, |
| 505 | bool *result, CborValue *next, IterateFunction func) |
| 506 | { |
| 507 | assert(cbor_value_is_byte_string(value) || cbor_value_is_text_string(value)); |
| 508 | |
| 509 | size_t total; |
| 510 | CborError err; |
| 511 | const char *ptr = value->ptr; |
| 512 | if (cbor_value_is_length_known(value)) { |
| 513 | // easy case: fixed length |
| 514 | err = extract_length(value->parser, &ptr, &total); |
| 515 | if (err) |
| 516 | return err; |
| 517 | if (ptr + total > value->parser->end) |
| 518 | return CborErrorUnexpectedEOF; |
| 519 | if (total <= *buflen) |
| 520 | *result = func(buffer, ptr, total); |
| 521 | else |
| 522 | *result = false; |
| 523 | ptr += total; |
| 524 | } else { |
| 525 | // chunked |
| 526 | ++ptr; |
| 527 | total = 0; |
| 528 | *result = true; |
| 529 | while (true) { |
| 530 | size_t chunkLen; |
| 531 | size_t newTotal; |
| 532 | |
| 533 | if (ptr == value->parser->end) |
| 534 | return CborErrorUnexpectedEOF; |
| 535 | |
| 536 | if (*ptr == (char)BreakByte) { |
| 537 | ++ptr; |
| 538 | break; |
| 539 | } |
| 540 | |
| 541 | // is this the right type? |
| 542 | if ((*ptr & MajorTypeMask) != value->type) |
| 543 | return CborErrorIllegalType; |
| 544 | |
| 545 | err = extract_length(value->parser, &ptr, &chunkLen); |
| 546 | if (err) |
| 547 | return err; |
| 548 | |
| 549 | if (unlikely(!add_check_overflow(total, chunkLen, &newTotal))) |
| 550 | return CborErrorDataTooLarge; |
| 551 | |
| 552 | if (ptr + chunkLen > value->parser->end) |
| 553 | return CborErrorUnexpectedEOF; |
| 554 | |
| 555 | if (*result && *buflen >= newTotal) |
| 556 | *result = func(buffer + total, ptr, chunkLen); |
| 557 | else |
| 558 | *result = false; |
| 559 | |
| 560 | ptr += chunkLen; |
| 561 | total = newTotal; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | // is there enough room for the ending NUL byte? |
| 566 | if (*result && *buflen > total) |
| 567 | func(buffer + total, "", 1); |
| 568 | *buflen = total; |
| 569 | |
| 570 | if (next) { |
| 571 | *next = *value; |
| 572 | next->ptr = ptr; |
| 573 | return preparse_next_value(next); |
| 574 | } |
| 575 | return CborNoError; |
| 576 | } |
| 577 | |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 578 | /** |
| 579 | * Copies the string pointed by \a value into the buffer provided at \a buffer |
| 580 | * of \a buflen bytes. If \a buffer is a NULL pointer, this function will not |
| 581 | * copy anything and will only update the \a next value. |
| 582 | * |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 583 | * If the provided buffer length was too small, this function returns an error |
| 584 | * condition of \ref CborErrorOutOfMemory. If you need to calculate the length |
| 585 | * of the string in order to preallocate a buffer, use |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 586 | * cbor_value_calculate_string_length(). |
| 587 | * |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 588 | * On success, this function sets the number of bytes copied to \c{*buflen}. If |
| 589 | * the buffer is large enough, this function will insert a null byte after the |
| 590 | * last copied byte, to facilitate manipulation of text strings. That byte is |
| 591 | * not included in the returned value of \c{*buflen}. |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 592 | * |
| 593 | * The \a next pointer, if not null, will be updated to point to the next item |
| 594 | * after this string. If \a value points to the last item, then \a next will be |
| 595 | * invalid. |
| 596 | * |
| 597 | * \note This function does not perform UTF-8 validation on the incoming text |
| 598 | * string. |
| 599 | * |
| 600 | * \sa cbor_value_dup_string(), cbor_value_get_string_length(), cbor_value_calculate_string_length() |
| 601 | */ |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 602 | CborError cbor_value_copy_string(const CborValue *value, char *buffer, |
| 603 | size_t *buflen, CborValue *next) |
Thiago Macieira | 2312efd | 2015-05-06 16:07:48 -0700 | [diff] [blame] | 604 | { |
Thiago Macieira | 9ae0581 | 2015-05-11 15:09:09 +0900 | [diff] [blame^] | 605 | bool copied_all; |
| 606 | CborError err = iterate_string_chunks(value, buffer, buflen, &copied_all, next, |
| 607 | buffer ? (IterateFunction)memcpy : iterate_noop); |
| 608 | return err ? err : |
| 609 | copied_all ? CborNoError : CborErrorOutOfMemory; |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 612 | CborError cbor_value_get_half_float(const CborValue *value, void *result) |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 613 | { |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 614 | assert(value->type == CborHalfFloatType); |
Thiago Macieira | c70169f | 2015-05-06 07:49:44 -0700 | [diff] [blame] | 615 | |
| 616 | // size has been computed already |
| 617 | uint16_t v = get16(value->ptr + 1); |
| 618 | memcpy(result, &v, sizeof(v)); |
Thiago Macieira | a43a4ef | 2015-05-06 20:25:18 -0700 | [diff] [blame] | 619 | return CborNoError; |
Thiago Macieira | 54a0e10 | 2015-05-05 21:25:06 -0700 | [diff] [blame] | 620 | } |