VirtualBox

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

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

Glue/Bstr: Added base64DecodedLength and base64Decode methods too. Put the implementation in a separate file for extpack and others who don't really need this code. bugref:9224

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1/* $Id: string-base64.cpp 84339 2020-05-18 17:35:01Z vboxsync $ */
2/** @file
3 * MS COM / XPCOM Abstraction Layer - UTF-8 and UTF-16 string classes, BASE64 bits.
4 */
5
6/*
7 * Copyright (C) 2006-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
18#include "VBox/com/string.h"
19
20#include <iprt/base64.h>
21#include <iprt/errcore.h>
22
23
24namespace com
25{
26
27HRESULT Bstr::base64Encode(const void *pvData, size_t cbData, bool fLineBreaks /*= false*/)
28{
29 uint32_t const fFlags = fLineBreaks ? RTBASE64_FLAGS_EOL_LF : RTBASE64_FLAGS_NO_LINE_BREAKS;
30 size_t cwcEncoded = RTBase64EncodedUtf16LengthEx(cbData, fFlags);
31 HRESULT hrc = reserveNoThrow(cwcEncoded + 1);
32 if (SUCCEEDED(hrc))
33 {
34 int vrc = RTBase64EncodeUtf16Ex(pvData, cbData, fFlags, mutableRaw(), cwcEncoded, &cwcEncoded);
35 AssertRCReturnStmt(vrc, setNull(), E_FAIL);
36 hrc = joltNoThrow(cwcEncoded);
37 }
38 return hrc;
39}
40
41int Bstr::base64Decode(void *pvData, size_t cbData, size_t *pcbActual /*= NULL*/, PRTUTF16 *ppwszEnd /*= NULL*/)
42{
43 return RTBase64DecodeUtf16Ex(raw(), RTSTR_MAX, pvData, cbData, pcbActual, ppwszEnd);
44}
45
46ssize_t Bstr::base64DecodedSize(PRTUTF16 *ppwszEnd /*= NULL*/)
47{
48 return RTBase64DecodedUtf16SizeEx(raw(), RTSTR_MAX, ppwszEnd);
49}
50
51} /* namespace com */
Note: See TracBrowser for help on using the repository browser.

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