VirtualBox

Changeset 84287 in vbox for trunk


Ignore:
Timestamp:
May 13, 2020 1:59:34 PM (5 years ago)
Author:
vboxsync
Message:

Glue/Bstr: Adding a base64Encode method using the new UTF-16 base64 encoding functions in IPRT. bugref:9224

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/string.h

    r82968 r84287  
    661661
    662662
     663    /** @name BASE64 related methods
     664     * @{ */
     665    /**
     666     * Encodes the give data as BASE64.
     667     *
     668     * @returns S_OK or E_OUTOFMEMORY.
     669     * @param   pvData          Pointer to the data to encode.
     670     * @param   cbData          Number of bytes to encode.
     671     * @param   fLineBreaks     Whether to add line breaks (true) or just encode it
     672     *                          as a continuous string.
     673     */
     674    HRESULT base64Encode(const void *pvData, size_t cbData, bool fLineBreaks = false);
     675    /** @} */
     676
    663677#if defined(VBOX_WITH_XPCOM)
    664678    /**
  • trunk/src/VBox/Main/glue/string.cpp

    r83785 r84287  
    1818#include "VBox/com/string.h"
    1919
     20#include <iprt/base64.h>
    2021#include <iprt/err.h>
     22#include <iprt/log.h>
    2123#include <iprt/path.h>
    22 #include <iprt/log.h>
    2324#include <iprt/string.h>
    2425#include <iprt/uni.h>
     
    228229        return ucLeft < ucRight ? -1 : 1;
    229230    }
     231}
     232
     233HRESULT Bstr::base64Encode(const void *pvData, size_t cbData, bool fLineBreaks /*= false*/)
     234{
     235    uint32_t const fFlags     = fLineBreaks ? RTBASE64_FLAGS_EOL_LF : RTBASE64_FLAGS_NO_LINE_BREAKS;
     236    size_t         cwcEncoded = RTBase64EncodedUtf16LengthEx(cbData, fFlags);
     237    HRESULT hrc = reserveNoThrow(cwcEncoded + 1);
     238    if (SUCCEEDED(hrc))
     239    {
     240        int vrc = RTBase64EncodeUtf16Ex(pvData, cbData, fFlags, mutableRaw(), cwcEncoded, &cwcEncoded);
     241        AssertRCReturnStmt(vrc, setNull(), E_FAIL);
     242        hrc = joltNoThrow(cwcEncoded);
     243    }
     244    return hrc;
    230245}
    231246
Note: See TracChangeset for help on using the changeset viewer.

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