1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/nsBase64Encoder.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsBase64Encoder.h" 1.9 + 1.10 +#include "plbase64.h" 1.11 +#include "prmem.h" 1.12 + 1.13 +NS_IMPL_ISUPPORTS(nsBase64Encoder, nsIOutputStream) 1.14 + 1.15 +NS_IMETHODIMP 1.16 +nsBase64Encoder::Close() 1.17 +{ 1.18 + return NS_OK; 1.19 +} 1.20 + 1.21 +NS_IMETHODIMP 1.22 +nsBase64Encoder::Flush() 1.23 +{ 1.24 + return NS_OK; 1.25 +} 1.26 + 1.27 +NS_IMETHODIMP 1.28 +nsBase64Encoder::Write(const char* aBuf, uint32_t aCount, uint32_t* _retval) 1.29 +{ 1.30 + mData.Append(aBuf, aCount); 1.31 + *_retval = aCount; 1.32 + return NS_OK; 1.33 +} 1.34 + 1.35 +NS_IMETHODIMP 1.36 +nsBase64Encoder::WriteFrom(nsIInputStream* aStream, uint32_t aCount, 1.37 + uint32_t* _retval) 1.38 +{ 1.39 + return NS_ERROR_NOT_IMPLEMENTED; 1.40 +} 1.41 + 1.42 +NS_IMETHODIMP 1.43 +nsBase64Encoder::WriteSegments(nsReadSegmentFun aReader, 1.44 + void* aClosure, 1.45 + uint32_t aCount, 1.46 + uint32_t* _retval) 1.47 +{ 1.48 + return NS_ERROR_NOT_IMPLEMENTED; 1.49 +} 1.50 + 1.51 +NS_IMETHODIMP 1.52 +nsBase64Encoder::IsNonBlocking(bool* aNonBlocking) 1.53 +{ 1.54 + *aNonBlocking = false; 1.55 + return NS_OK; 1.56 +} 1.57 + 1.58 +nsresult 1.59 +nsBase64Encoder::Finish(nsCSubstring& result) 1.60 +{ 1.61 + char* b64 = PL_Base64Encode(mData.get(), mData.Length(), nullptr); 1.62 + if (!b64) 1.63 + return NS_ERROR_OUT_OF_MEMORY; 1.64 + 1.65 + result.Assign(b64); 1.66 + PR_Free(b64); 1.67 + // Free unneeded memory and allow reusing the object 1.68 + mData.Truncate(); 1.69 + return NS_OK; 1.70 +}