VirtualBox

source: vbox/trunk/include/iprt/base64.h@ 73768

Last change on this file since 73768 was 73619, checked in by vboxsync, 6 years ago

iptr/base64: Fix doxygen nit in previous.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/** @file
2 * IPRT - Base64, MIME content transfer encoding.
3 */
4
5/*
6 * Copyright (C) 2009-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_base64_h
27#define ___iprt_base64_h
28
29#include <iprt/types.h>
30
31RT_C_DECLS_BEGIN
32
33/** @defgroup grp_rt_base64 RTBase64 - Base64, MIME content transfer encoding.
34 * @ingroup grp_rt
35 * @{
36 */
37
38/** @def RTBASE64_EOL_SIZE
39 * The size of the end-of-line marker. */
40#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
41# define RTBASE64_EOL_SIZE (sizeof("\r\n") - 1)
42#else
43# define RTBASE64_EOL_SIZE (sizeof("\n") - 1)
44#endif
45
46
47/** @name Flags for RTBase64EncodeEx() and RTBase64EncodedLengthEx().
48 * @{ */
49/** Insert line breaks into encoded string.
50 * The size of the end-of-line marker is that that of the host platform.
51 */
52#define RTBASE64_FLAGS_NO_LINE_BREAKS RT_BIT_32(0)
53/** @} */
54
55
56/**
57 * Calculates the decoded data size for a Base64 encoded string.
58 *
59 * @returns The length in bytes. -1 if the encoding is bad.
60 *
61 * @param pszString The Base64 encoded string.
62 * @param ppszEnd If not NULL, this will point to the first char
63 * following the Base64 encoded text block. If
64 * NULL the entire string is assumed to be Base64.
65 */
66RTDECL(ssize_t) RTBase64DecodedSize(const char *pszString, char **ppszEnd);
67
68/**
69 * Calculates the decoded data size for a Base64 encoded string.
70 *
71 * @returns The length in bytes. -1 if the encoding is bad.
72 *
73 * @param pszString The Base64 encoded string.
74 * @param cchStringMax The max length to decode, use RTSTR_MAX if the
75 * length of @a pszString is not known and it is
76 * really zero terminated.
77 * @param ppszEnd If not NULL, this will point to the first char
78 * following the Base64 encoded text block. If
79 * NULL the entire string is assumed to be Base64.
80 */
81RTDECL(ssize_t) RTBase64DecodedSizeEx(const char *pszString, size_t cchStringMax, char **ppszEnd);
82
83/**
84 * Decodes a Base64 encoded string into the buffer supplied by the caller.
85 *
86 * @returns IPRT status code.
87 * @retval VERR_BUFFER_OVERFLOW if the buffer is too small. pcbActual will not
88 * be set, nor will ppszEnd.
89 * @retval VERR_INVALID_BASE64_ENCODING if the encoding is wrong.
90 *
91 * @param pszString The Base64 string. Whether the entire string or
92 * just the start of the string is in Base64 depends
93 * on whether ppszEnd is specified or not.
94 * @param pvData Where to store the decoded data.
95 * @param cbData The size of the output buffer that pvData points to.
96 * @param pcbActual Where to store the actual number of bytes returned.
97 * Optional.
98 * @param ppszEnd Indicates that the string may contain other stuff
99 * after the Base64 encoded data when not NULL. Will
100 * be set to point to the first char that's not part of
101 * the encoding. If NULL the entire string must be part
102 * of the Base64 encoded data.
103 */
104RTDECL(int) RTBase64Decode(const char *pszString, void *pvData, size_t cbData, size_t *pcbActual, char **ppszEnd);
105
106/**
107 * Decodes a Base64 encoded string into the buffer supplied by the caller.
108 *
109 * @returns IPRT status code.
110 * @retval VERR_BUFFER_OVERFLOW if the buffer is too small. pcbActual will not
111 * be set, nor will ppszEnd.
112 * @retval VERR_INVALID_BASE64_ENCODING if the encoding is wrong.
113 *
114 * @param pszString The Base64 string. Whether the entire string or
115 * just the start of the string is in Base64 depends
116 * on whether ppszEnd is specified or not.
117 * @param cchStringMax The max length to decode, use RTSTR_MAX if the
118 * length of @a pszString is not known and it is
119 * really zero terminated.
120 * @param pvData Where to store the decoded data.
121 * @param cbData The size of the output buffer that pvData points to.
122 * @param pcbActual Where to store the actual number of bytes returned.
123 * Optional.
124 * @param ppszEnd Indicates that the string may contain other stuff
125 * after the Base64 encoded data when not NULL. Will
126 * be set to point to the first char that's not part of
127 * the encoding. If NULL the entire string must be part
128 * of the Base64 encoded data.
129 */
130RTDECL(int) RTBase64DecodeEx(const char *pszString, size_t cchStringMax, void *pvData, size_t cbData,
131 size_t *pcbActual, char **ppszEnd);
132
133
134/**
135 * Calculates the length of the Base64 encoding of a given number of bytes of
136 * data produced by RTBase64Encode().
137 *
138 * @returns The Base64 string length.
139 * @param cbData The number of bytes to encode.
140 */
141RTDECL(size_t) RTBase64EncodedLength(size_t cbData);
142
143/**
144 * Calculates the length of the Base64 encoding of a given number of bytes of
145 * data produced by RTBase64EncodeEx() with the same @a fFlags.
146 *
147 * @returns The Base64 string length.
148 * @param cbData The number of bytes to encode.
149 * @param fFlags Flags, any combination of the RTBASE64_FLAGS \#defines.
150 */
151RTDECL(size_t) RTBase64EncodedLengthEx(size_t cbData, uint32_t fFlags);
152
153/**
154 * Encodes the specifed data into a Base64 string, the caller supplies the
155 * output buffer.
156 *
157 * This is equivalent to calling RTBase64EncodeEx() with no flags.
158 *
159 * @returns IRPT status code.
160 * @retval VERR_BUFFER_OVERFLOW if the output buffer is too small. The buffer
161 * may contain an invalid Base64 string.
162 *
163 * @param pvData The data to encode.
164 * @param cbData The number of bytes to encode.
165 * @param pszBuf Where to put the Base64 string.
166 * @param cbBuf The size of the output buffer, including the terminator.
167 * @param pcchActual The actual number of characters returned.
168 */
169RTDECL(int) RTBase64Encode(const void *pvData, size_t cbData, char *pszBuf, size_t cbBuf, size_t *pcchActual);
170
171/**
172 * Encodes the specifed data into a Base64 string, the caller supplies the
173 * output buffer.
174 *
175 * @returns IRPT status code.
176 * @retval VERR_BUFFER_OVERFLOW if the output buffer is too small. The buffer
177 * may contain an invalid Base64 string.
178 *
179 * @param pvData The data to encode.
180 * @param cbData The number of bytes to encode.
181 * @param fFlags Flags, any combination of the RTBASE64_FLAGS \#defines.
182 * @param pszBuf Where to put the Base64 string.
183 * @param cbBuf The size of the output buffer, including the terminator.
184 * @param pcchActual The actual number of characters returned.
185 */
186RTDECL(int) RTBase64EncodeEx(const void *pvData, size_t cbData, uint32_t fFlags,
187 char *pszBuf, size_t cbBuf, size_t *pcchActual);
188
189/** @} */
190
191RT_C_DECLS_END
192
193#endif
194
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use