netwerk/base/src/nsBase64Encoder.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "nsBase64Encoder.h"
     7 #include "plbase64.h"
     8 #include "prmem.h"
    10 NS_IMPL_ISUPPORTS(nsBase64Encoder, nsIOutputStream)
    12 NS_IMETHODIMP
    13 nsBase64Encoder::Close()
    14 {
    15   return NS_OK;
    16 }
    18 NS_IMETHODIMP
    19 nsBase64Encoder::Flush()
    20 {
    21   return NS_OK;
    22 }
    24 NS_IMETHODIMP
    25 nsBase64Encoder::Write(const char* aBuf, uint32_t aCount, uint32_t* _retval)
    26 {
    27   mData.Append(aBuf, aCount);
    28   *_retval = aCount;
    29   return NS_OK;
    30 }
    32 NS_IMETHODIMP
    33 nsBase64Encoder::WriteFrom(nsIInputStream* aStream, uint32_t aCount,
    34                            uint32_t* _retval)
    35 {
    36   return NS_ERROR_NOT_IMPLEMENTED;
    37 }
    39 NS_IMETHODIMP
    40 nsBase64Encoder::WriteSegments(nsReadSegmentFun aReader,
    41                                void* aClosure,
    42                                uint32_t aCount,
    43                                uint32_t* _retval)
    44 {
    45   return NS_ERROR_NOT_IMPLEMENTED;
    46 }
    48 NS_IMETHODIMP
    49 nsBase64Encoder::IsNonBlocking(bool* aNonBlocking)
    50 {
    51   *aNonBlocking = false;
    52   return NS_OK;
    53 }
    55 nsresult
    56 nsBase64Encoder::Finish(nsCSubstring& result)
    57 {
    58   char* b64 = PL_Base64Encode(mData.get(), mData.Length(), nullptr);
    59   if (!b64)
    60     return NS_ERROR_OUT_OF_MEMORY;
    62   result.Assign(b64);
    63   PR_Free(b64);
    64   // Free unneeded memory and allow reusing the object
    65   mData.Truncate();
    66   return NS_OK;
    67 }

mercurial