1 /*
2 Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
3 file at the top-level directory of this distribution.
4
5 Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 option. This file may not be copied, modified, or distributed
9 except according to those terms.
10 */
11
12 #include "common/byte_array.h"
13 #include "common/memcpy_s.h"
14 #include "common/oscore_edhoc_error.h"
15
16 uint8_t EMPTY_STRING[] = { "" };
17 struct byte_array EMPTY_ARRAY = {
18 .len = 0,
19 .ptr = EMPTY_STRING,
20 };
21
22 struct byte_array NULL_ARRAY = {
23 .len = 0,
24 .ptr = NULL,
25 };
26
byte_array_cpy(struct byte_array * dest,const struct byte_array * src,const uint32_t dest_max_len)27 enum err byte_array_cpy(struct byte_array *dest, const struct byte_array *src,
28 const uint32_t dest_max_len)
29 {
30 TRY(_memcpy_s(dest->ptr, dest_max_len, src->ptr, src->len));
31 dest->len = src->len;
32 return ok;
33 }
34
array_equals(const struct byte_array * left,const struct byte_array * right)35 bool array_equals(const struct byte_array *left, const struct byte_array *right)
36 {
37 if (left->len != right->len) {
38 return false;
39 }
40 for (uint32_t i = 0; i < left->len; i++) {
41 if (left->ptr[i] != right->ptr[i]) {
42 return false;
43 }
44 }
45 return true;
46 }
47