tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsBase64Encoder.cpp (1381B)


      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/. */
      4 
      5 #include "nsBase64Encoder.h"
      6 
      7 #include "mozilla/Base64.h"
      8 
      9 NS_IMPL_ISUPPORTS(nsBase64Encoder, nsIOutputStream)
     10 
     11 NS_IMETHODIMP
     12 nsBase64Encoder::Close() { return NS_OK; }
     13 
     14 NS_IMETHODIMP
     15 nsBase64Encoder::Flush() { return NS_OK; }
     16 
     17 NS_IMETHODIMP
     18 nsBase64Encoder::StreamStatus() { return NS_OK; }
     19 
     20 NS_IMETHODIMP
     21 nsBase64Encoder::Write(const char* aBuf, uint32_t aCount, uint32_t* _retval) {
     22  mData.Append(aBuf, aCount);
     23  *_retval = aCount;
     24  return NS_OK;
     25 }
     26 
     27 NS_IMETHODIMP
     28 nsBase64Encoder::WriteFrom(nsIInputStream* aStream, uint32_t aCount,
     29                           uint32_t* _retval) {
     30  return NS_ERROR_NOT_IMPLEMENTED;
     31 }
     32 
     33 NS_IMETHODIMP
     34 nsBase64Encoder::WriteSegments(nsReadSegmentFun aReader, void* aClosure,
     35                               uint32_t aCount, uint32_t* _retval) {
     36  return NS_ERROR_NOT_IMPLEMENTED;
     37 }
     38 
     39 NS_IMETHODIMP
     40 nsBase64Encoder::IsNonBlocking(bool* aNonBlocking) {
     41  *aNonBlocking = false;
     42  return NS_OK;
     43 }
     44 
     45 nsresult nsBase64Encoder::Finish(nsACString& result) {
     46  nsresult rv = mozilla::Base64Encode(mData, result);
     47  if (NS_FAILED(rv)) {
     48    return rv;
     49  }
     50 
     51  // Free unneeded memory and allow reusing the object
     52  mData.Truncate();
     53  return NS_OK;
     54 }