mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1864123 - Optimize flushing to base stream; r=dom-storage-reviewers,asuth,hsingh
Differential Revision: https://phabricator.services.mozilla.com/D193286
This commit is contained in:
parent
d886bade84
commit
d26ddce442
@ -24,6 +24,7 @@
|
||||
#include "nscore.h"
|
||||
|
||||
class nsIInputStream;
|
||||
class nsIRandomGenerator;
|
||||
|
||||
namespace mozilla::dom::quota {
|
||||
class EncryptingOutputStreamBase : public nsIOutputStream {
|
||||
@ -83,6 +84,8 @@ class EncryptingOutputStream final : public EncryptingOutputStreamBase {
|
||||
// effective block size at a block boundary.
|
||||
nsTArray<uint8_t> mBuffer;
|
||||
|
||||
nsCOMPtr<nsIRandomGenerator> mRandomGenerator;
|
||||
|
||||
// The next byte in the plain data to copy incoming data to.
|
||||
size_t mNextByte = 0;
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIAsyncOutputStream.h"
|
||||
#include "nsIRandomGenerator.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
namespace mozilla::dom::quota {
|
||||
template <typename CipherStrategy>
|
||||
@ -207,6 +209,26 @@ nsresult EncryptingOutputStream<CipherStrategy>::FlushToBaseStream() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mNextByte < mEncryptedBlock->MaxPayloadLength()) {
|
||||
if (!mRandomGenerator) {
|
||||
mRandomGenerator =
|
||||
do_GetService("@mozilla.org/security/random-generator;1");
|
||||
if (NS_WARN_IF(!mRandomGenerator)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
const auto payload = mEncryptedBlock->MutablePayload();
|
||||
|
||||
const auto unusedPayload = payload.From(mNextByte);
|
||||
|
||||
nsresult rv = mRandomGenerator->GenerateRandomBytesInto(
|
||||
unusedPayload.Elements(), unusedPayload.Length());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX The compressing stream implementation this was based on wrote a stream
|
||||
// identifier, containing e.g. the block size. Should we do something like
|
||||
// that as well? At the moment, we don't need it, but maybe this were
|
||||
|
Loading…
Reference in New Issue
Block a user