VirtualBox

source: vbox/trunk/src/VBox/Main/glue/string-base64.cpp

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
RevLine 
[6076]1/* $Id: string-base64.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
[1]2/** @file
[84339]3 * MS COM / XPCOM Abstraction Layer - UTF-8 and UTF-16 string classes, BASE64 bits.
[1]4 */
5
6/*
[98103]7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
[1]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
[1]26 */
27
28#include "VBox/com/string.h"
29
[84287]30#include <iprt/base64.h>
[84339]31#include <iprt/errcore.h>
[6076]32
[84339]33
[1]34namespace com
35{
36
[84287]37HRESULT Bstr::base64Encode(const void *pvData, size_t cbData, bool fLineBreaks /*= false*/)
38{
39 uint32_t const fFlags = fLineBreaks ? RTBASE64_FLAGS_EOL_LF : RTBASE64_FLAGS_NO_LINE_BREAKS;
40 size_t cwcEncoded = RTBase64EncodedUtf16LengthEx(cbData, fFlags);
41 HRESULT hrc = reserveNoThrow(cwcEncoded + 1);
42 if (SUCCEEDED(hrc))
43 {
[87434]44 int vrc = RTBase64EncodeUtf16Ex(pvData, cbData, fFlags, mutableRaw(), cwcEncoded + 1, &cwcEncoded);
[84287]45 AssertRCReturnStmt(vrc, setNull(), E_FAIL);
46 hrc = joltNoThrow(cwcEncoded);
47 }
48 return hrc;
49}
[60409]50
[84339]51int Bstr::base64Decode(void *pvData, size_t cbData, size_t *pcbActual /*= NULL*/, PRTUTF16 *ppwszEnd /*= NULL*/)
[80835]52{
[84339]53 return RTBase64DecodeUtf16Ex(raw(), RTSTR_MAX, pvData, cbData, pcbActual, ppwszEnd);
[80835]54}
55
[84339]56ssize_t Bstr::base64DecodedSize(PRTUTF16 *ppwszEnd /*= NULL*/)
[80835]57{
[84339]58 return RTBase64DecodedUtf16SizeEx(raw(), RTSTR_MAX, ppwszEnd);
[80835]59}
60
[5658]61} /* namespace com */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use