]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/dnssec_v2/utilities/base_encoding/base_n.h
mDNSResponder-1310.80.1.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / dnssec_v2 / utilities / base_encoding / base_n.h
1 //
2 // base_n.h
3 // mDNSResponder
4 //
5 // Copyright (c) 2020 Apple Inc. All rights reserved.
6 //
7
8 #ifndef base_n_h
9 #define base_n_h
10
11 #pragma mark - Includes
12 #include "mDNSEmbeddedAPI.h"
13 #include <stdlib.h>
14 #if MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)
15
16 #pragma mark base_n_t
17 typedef enum base_n {
18 DNSSEC_BASE_64,
19 DNSSEC_BASE_32_HEX
20 } base_n_t;
21
22 #pragma mark base_n_encode
23 /*!
24 * @brief
25 * Gets the Base N encoding for the binary data
26 *
27 * @param base_n
28 * The base we would like to convert, currently it could be Base 64 or Base 32.
29 *
30 * @param data
31 * The data that needs to be encoded.
32 *
33 * @param data_len
34 * The length of the data that needs to be encoded..
35 *
36 * @return
37 * This function returns a malloced string that needs to be freed by the caller.
38 */
39 char * _Nullable
40 base_n_encode(base_n_t base_n, const unsigned char * _Nonnull data, size_t data_len);
41
42 #pragma mark base_n_encode_ex
43 /*!
44 * @brief
45 * Gets the Base N encoding for the binary data, and return the length of the encoding string.
46 *
47 * @param base_n
48 * The base we would like to convert, currently it could be Base 64 or Base 32.
49 *
50 * @param data
51 * The data that needs to be encoded.
52 *
53 * @param data_len
54 * The length of the data that needs to be encoded.
55 *
56 * @param out_str_len
57 * The output pointer to the length of the encoded string.
58 *
59 * @returns
60 * This function returns a malloced string that needs to be freed by the caller, and also the length of encoded string.
61 */
62 char * _Nullable
63 base_n_encode_ex(base_n_t base_n, const unsigned char * _Nonnull data, size_t data_len, size_t * const _Nullable out_str_len);
64
65 #pragma mark get_base_n_encoded_str_length
66 /*!
67 * @brief
68 * Gets the length of the encoded string after Base N encoding
69 *
70 * @param base_n
71 * The base we would like to convert, currently it could be DNSSEC_BASE_64 or DNSSEC_BASE_32_HEX.
72 *
73 * @param data_len
74 * The length of the data that needs to be encoded.
75 *
76 * @discussion
77 * The length does not include the '\0'.
78 */
79 size_t
80 get_base_n_encoded_str_length(base_n_t base_n, size_t data_len) ;
81
82 #endif // MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)
83
84 #endif /* base_n_h */