VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/string/base64.h@ 84296

Last change on this file since 84296 was 84296, checked in by vboxsync, 5 years ago

IPRT/base64: Optimize '\0' handling a little and unify the two versions a little more. Try to address cranky linux build boxes wrt mangling. bugref:9224

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: base64.h 84296 2020-05-13 16:46:27Z vboxsync $ */
2/** @file
3 * IPRT - Base64, MIME content transfer encoding, internal header.
4 */
5
6/*
7 * Copyright (C) 2009-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Defined Constants And Macros *
30*********************************************************************************************************************************/
31/** The line length used for encoding. */
32#define RTBASE64_LINE_LEN 64
33
34/** @name Special g_au8rtBase64CharToVal values
35 * @{ */
36#define BASE64_SPACE 0xc0
37#define BASE64_PAD 0xe0
38#define BASE64_NULL 0xfe
39#define BASE64_INVALID 0xff
40/** @} */
41
42
43/*********************************************************************************************************************************
44* Global Variables *
45*********************************************************************************************************************************/
46extern DECLHIDDEN(const uint8_t) g_au8rtBase64CharToVal[256];
47extern DECLHIDDEN(const char) g_szrtBase64ValToChar[64+1];
48extern DECLHIDDEN(const size_t) g_acchrtBase64EolStyles[RTBASE64_FLAGS_EOL_STYLE_MASK + 1];
49extern DECLHIDDEN(const char) g_aachrtBase64EolStyles[RTBASE64_FLAGS_EOL_STYLE_MASK + 1][2];
50
51
52/*********************************************************************************************************************************
53* Internal Functions *
54*********************************************************************************************************************************/
55#ifdef RT_STRICT
56DECLHIDDEN(void) rtBase64Sanity(void);
57#endif
58
59
60/**
61 * Recalcs 6-bit to 8-bit and adjust for padding.
62 */
63DECLINLINE(ssize_t) rtBase64DecodedSizeRecalc(uint32_t c6Bits, unsigned cbPad)
64{
65 size_t cb;
66 if (c6Bits * 3 / 3 == c6Bits)
67 {
68 if ((c6Bits * 3 % 4) != 0)
69 return -1;
70 cb = c6Bits * 3 / 4;
71 }
72 else
73 {
74 if ((c6Bits * (uint64_t)3 % 4) != 0)
75 return -1;
76 cb = c6Bits * (uint64_t)3 / 4;
77 }
78
79 if (cb < cbPad)
80 return -1;
81 cb -= cbPad;
82 return cb;
83}
84
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette