1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "EncryptingOutputStream.h"
8 #include "EncryptingOutputStream_impl.h"
10 #include <type_traits>
11 #include "mozilla/MacroForEach.h"
12 #include "nsStreamUtils.h"
14 namespace mozilla::dom::quota
{
16 NS_IMPL_ISUPPORTS(EncryptingOutputStreamBase
, nsIOutputStream
);
18 EncryptingOutputStreamBase::EncryptingOutputStreamBase(
19 nsCOMPtr
<nsIOutputStream
> aBaseStream
, size_t aBlockSize
)
20 : mBaseStream(WrapNotNull(std::move(aBaseStream
))),
21 mBlockSize(aBlockSize
) {}
23 NS_IMETHODIMP
EncryptingOutputStreamBase::Write(const char* aBuf
,
25 uint32_t* aResultOut
) {
26 return WriteSegments(NS_CopyBufferToSegment
, const_cast<char*>(aBuf
), aCount
,
30 NS_IMETHODIMP
EncryptingOutputStreamBase::WriteFrom(nsIInputStream
*, uint32_t,
32 return NS_ERROR_NOT_IMPLEMENTED
;
35 NS_IMETHODIMP
EncryptingOutputStreamBase::IsNonBlocking(bool* aNonBlockingOut
) {
36 *aNonBlockingOut
= false;
40 nsresult
EncryptingOutputStreamBase::WriteAll(const char* aBuf
, uint32_t aCount
,
41 uint32_t* aBytesWrittenOut
) {
42 *aBytesWrittenOut
= 0;
45 return NS_BASE_STREAM_CLOSED
;
50 uint32_t numWritten
= 0;
51 nsresult rv
= (*mBaseStream
)->Write(aBuf
+ offset
, aCount
, &numWritten
);
52 if (NS_WARN_IF(NS_FAILED(rv
))) {
58 *aBytesWrittenOut
+= numWritten
;
64 } // namespace mozilla::dom::quota