Bug 1913377 - Comment and assert that `allowedScope` has a very limited set of values...
[gecko.git] / dom / quota / EncryptingOutputStream.cpp
blob80279eae2784a2adef272a6b110ed2b8357f9125
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,
24 uint32_t aCount,
25 uint32_t* aResultOut) {
26 return WriteSegments(NS_CopyBufferToSegment, const_cast<char*>(aBuf), aCount,
27 aResultOut);
30 NS_IMETHODIMP EncryptingOutputStreamBase::WriteFrom(nsIInputStream*, uint32_t,
31 uint32_t*) {
32 return NS_ERROR_NOT_IMPLEMENTED;
35 NS_IMETHODIMP EncryptingOutputStreamBase::IsNonBlocking(bool* aNonBlockingOut) {
36 *aNonBlockingOut = false;
37 return NS_OK;
40 nsresult EncryptingOutputStreamBase::WriteAll(const char* aBuf, uint32_t aCount,
41 uint32_t* aBytesWrittenOut) {
42 *aBytesWrittenOut = 0;
44 if (!mBaseStream) {
45 return NS_BASE_STREAM_CLOSED;
48 uint32_t offset = 0;
49 while (aCount > 0) {
50 uint32_t numWritten = 0;
51 nsresult rv = (*mBaseStream)->Write(aBuf + offset, aCount, &numWritten);
52 if (NS_WARN_IF(NS_FAILED(rv))) {
53 return rv;
56 offset += numWritten;
57 aCount -= numWritten;
58 *aBytesWrittenOut += numWritten;
61 return NS_OK;
64 } // namespace mozilla::dom::quota