base64.h revision b0ab7e3ff45cca3c9755432dde464562cdde61f0
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * IPRT - Base64, MIME content transfer encoding.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * available from http://www.virtualbox.org. This file is free software;
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * General Public License (GPL) as published by the Free Software
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * The contents of this file may alternatively be used under the terms
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * of the Common Development and Distribution License Version 1.0
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * VirtualBox OSE distribution, in which case the provisions of the
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * CDDL are applicable instead of those of the GPL.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * You may elect to license modified versions of this file under the
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * terms and conditions of either the GPL or the CDDL or both.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * additional information or have any questions.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync/** @defgroup grp_rt_base64 RTBase64 - Base64, MIME content transfer encoding.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @ingroup grp_rt
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync/** @def RTBASE64_EOL_SIZE
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * The size of the end-of-line marker. */
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Calculates the decoded data size for a Base64 encoded string.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @returns The length in bytes. -1 if the encoding is bad.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param pszString The Base64 encoded string.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param ppszEnd If not NULL, this will point to the first char
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * following the Base64 encoded text block. If
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * NULL the entire string is assumed to be Base64.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsyncRTDECL(ssize_t) RTBase64DecodedSize(const char *pszString, char **ppszEnd);
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Decodes a Base64 encoded string into the buffer supplied by the caller.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @returns IPRT status code.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @retval VERR_BUFFER_OVERFLOW if the buffer is too small. pcbActual will not
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * be set, nor will ppszEnd.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @retval VERR_INVALID_BASE64_ENCODING if the encoding is wrong.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param pszString The Base64 string. Whether the entire string or
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * just the start of the string is in Base64 depends
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * on wther ppszEnd is specified or not.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param pvData Where to store the decoded data.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param cbData The size of the output buffer that pvData points to.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param pcbActual Where to store the actual number of bytes returned.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Optional.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param ppszEnd Indicats that the string may contain other stuff
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * after the Base64 encoded data when not NULL. Will
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * be set to point to the first char that's not part of
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * the encoding. If NULL the entire string must be part
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * of the Base64 encoded data.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsyncRTDECL(int) RTBase64Decode(const char *pszString, void *pvData, size_t cbData, size_t *pcbActual, char **ppszEnd);
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Calculates the length of the Base64 encoding of a given number of bytes of
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * This will assume line breaks every 64 chars. A RTBase64EncodedLengthEx
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * function can be added if closer control over the output is found to be
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * required.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @returns The Base64 string length.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param cbData The number of bytes to encode.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsyncRTDECL(size_t) RTBase64EncodedLength(size_t cbData);
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * Encodes the specifed data into a Base64 string, the caller supplies the
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * output buffer.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * This will make the same assumptions about line breaks and EOL size as
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * RTBase64EncodedLength() does. A RTBase64EncodeEx function can be added if
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * more strict control over the output formatting is found necessary.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @returns IRPT status code.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @retval VERR_BUFFER_OVERFLOW if the output buffer is too small. The buffer
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * may contain an invalid Base64 string.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param pszBuf Where to put the Base64 string.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param cbBuf The size of the output buffer, including the terminator.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param pvData The data to encode.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsync * @param cbData The number of bytes to encode.
b0ab7e3ff45cca3c9755432dde464562cdde61f0vboxsyncRTDECL(int) RTBase64Encode(char *pszBuf, size_t cbBuf, const void *pvData, size_t cbData);