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 "DecryptingInputStream.h"
8 #include "DecryptingInputStream_impl.h"
10 #include "nsStreamUtils.h"
12 namespace mozilla::dom::quota
{
14 NS_IMPL_ADDREF(DecryptingInputStreamBase
);
15 NS_IMPL_RELEASE(DecryptingInputStreamBase
);
17 NS_INTERFACE_MAP_BEGIN(DecryptingInputStreamBase
)
18 NS_INTERFACE_MAP_ENTRY(nsIInputStream
)
19 NS_INTERFACE_MAP_ENTRY(nsISeekableStream
)
20 NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICloneableInputStream
,
21 mBaseCloneableInputStream
|| !mBaseStream
)
22 NS_INTERFACE_MAP_ENTRY_CONDITIONAL(
23 nsIIPCSerializableInputStream
,
24 mBaseIPCSerializableInputStream
|| !mBaseStream
)
25 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIInputStream
)
28 DecryptingInputStreamBase::DecryptingInputStreamBase(
29 MovingNotNull
<nsCOMPtr
<nsIInputStream
>> aBaseStream
, size_t aBlockSize
) {
30 Init(std::move(aBaseStream
), aBlockSize
);
33 void DecryptingInputStreamBase::Init(
34 MovingNotNull
<nsCOMPtr
<nsIInputStream
>> aBaseStream
, size_t aBlockSize
) {
35 mBlockSize
.init(aBlockSize
);
36 mBaseStream
.init(std::move(aBaseStream
));
38 const nsCOMPtr
<nsISeekableStream
> seekableStream
=
39 do_QueryInterface(mBaseStream
->get());
40 MOZ_ASSERT(seekableStream
&&
41 SameCOMIdentity(mBaseStream
->get(), seekableStream
));
42 mBaseSeekableStream
.init(WrapNotNullUnchecked(seekableStream
));
44 const nsCOMPtr
<nsICloneableInputStream
> cloneableInputStream
=
45 do_QueryInterface(mBaseStream
->get());
46 if (cloneableInputStream
&&
47 SameCOMIdentity(mBaseStream
->get(), cloneableInputStream
)) {
48 mBaseCloneableInputStream
.init(WrapNotNullUnchecked(cloneableInputStream
));
51 const nsCOMPtr
<nsIIPCSerializableInputStream
> ipcSerializeInputStream
=
52 do_QueryInterface(mBaseStream
->get());
53 if (ipcSerializeInputStream
&&
54 SameCOMIdentity(mBaseStream
->get(), ipcSerializeInputStream
)) {
55 mBaseIPCSerializableInputStream
.init(
56 WrapNotNullUnchecked(ipcSerializeInputStream
));
60 NS_IMETHODIMP
DecryptingInputStreamBase::Read(char* aBuf
, uint32_t aCount
,
61 uint32_t* aBytesReadOut
) {
62 return ReadSegments(NS_CopySegmentToBuffer
, aBuf
, aCount
, aBytesReadOut
);
65 NS_IMETHODIMP
DecryptingInputStreamBase::IsNonBlocking(bool* aNonBlockingOut
) {
66 *aNonBlockingOut
= false;
70 NS_IMETHODIMP
DecryptingInputStreamBase::SetEOF() {
71 // Cannot truncate a read-only stream.
73 return NS_ERROR_NOT_IMPLEMENTED
;
76 NS_IMETHODIMP
DecryptingInputStreamBase::GetCloneable(bool* aCloneable
) {
81 void DecryptingInputStreamBase::Serialize(
82 mozilla::ipc::InputStreamParams
& aParams
,
83 FileDescriptorArray
& aFileDescriptors
, bool aDelayedStart
,
84 uint32_t aMaxSize
, uint32_t* aSizeUsed
,
85 mozilla::ipc::ChildToParentStreamActorManager
* aManager
) {
86 MOZ_CRASH("Not implemented");
89 size_t DecryptingInputStreamBase::PlainLength() const {
90 MOZ_ASSERT(mNextByte
<= mPlainBytes
);
91 return mPlainBytes
- mNextByte
;
94 size_t DecryptingInputStreamBase::EncryptedBufferLength() const {
98 } // namespace mozilla::dom::quota