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 <stdint.h>
13 #include <string.h>
14 
15 #include "common/oscore_edhoc_error.h"
16 #include "common/memcpy_s.h"
17 
check_buffer_size(uint32_t is_size,uint32_t required_size)18 enum err check_buffer_size(uint32_t is_size, uint32_t required_size)
19 {
20 	if (is_size < required_size) {
21 		return buffer_to_small;
22 	} else {
23 		return ok;
24 	}
25 }
26 
_memcpy_s(uint8_t * dest,uint32_t dest_len,const uint8_t * source,uint32_t source_len)27 enum err _memcpy_s(uint8_t *dest, uint32_t dest_len, const uint8_t *source,
28 		   uint32_t source_len)
29 {
30 	if (source_len == 0) {
31 		return ok;
32 	}
33 	if ((NULL == dest) || (NULL == source)) {
34 		return wrong_parameter;
35 	}
36 
37 	TRY(check_buffer_size(dest_len, source_len));
38 	memcpy(dest, source, source_len);
39 	return ok;
40 }
41