Software APIs
hexstr.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_HEXSTR_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_HEXSTR_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/lib/base/status.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif // __cplusplus
15 
16 /**
17  * Encode binary data as a hexadecimal string.
18  *
19  * @param dst The destination string buffer.
20  * @param dst_size The maximum size of the destination buffer (including the nul
21  * terminator).
22  * @param src The source data to encode.
23  * @param src_size The size of the source data.
24  * @return status_t Success or error code.
25  */
26 status_t hexstr_encode(char *dst, size_t dst_size, const void *src,
27  size_t src_size);
28 
29 /**
30  * Decode binary data from a hexadecimal string.
31  *
32  * @param dst The destination binary buffer.
33  * @param dst_size The size of the destination buffer.
34  * @param src The source string to decode.
35  * @return status_t Success or error code.
36  */
37 status_t hexstr_decode(void *dst, size_t dst_size, const char *src);
38 
39 #ifdef __cplusplus
40 } // extern "C"
41 #endif // __cplusplus
42 
43 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_HEXSTR_H_