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 
14 uint8_t EMPTY_STRING[] = { "" };
15 struct byte_array EMPTY_ARRAY = {
16 	.len = 0,
17 	.ptr = EMPTY_STRING,
18 };
19 
20 struct byte_array NULL_ARRAY = {
21 	.len = 0,
22 	.ptr = NULL,
23 };
24 
byte_array_init(uint8_t * buf,uint32_t buf_len,struct byte_array * byte_array)25 void byte_array_init(uint8_t *buf, uint32_t buf_len,
26 		     struct byte_array *byte_array)
27 {
28 	byte_array->len = buf_len;
29 	byte_array->ptr = buf;
30 }
31 
array_equals(const struct byte_array * left,const struct byte_array * right)32 bool array_equals(const struct byte_array *left, const struct byte_array *right)
33 {
34 	if (left->len != right->len) {
35 		return false;
36 	}
37 	for (uint32_t i = 0; i < left->len; i++) {
38 		if (left->ptr[i] != right->ptr[i]) {
39 			return false;
40 		}
41 	}
42 	return true;
43 }
44