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/. */ 6 7 #ifndef mozilla_dom_quota_DummyCipherStrategy_h 8 #define mozilla_dom_quota_DummyCipherStrategy_h 9 10 #include <algorithm> 11 #include <array> 12 #include <cstddef> 13 #include <cstdint> 14 #include <utility> 15 #include "ErrorList.h" 16 #include "mozilla/Result.h" 17 #include "mozilla/Span.h" 18 #include "mozilla/dom/quota/CipherStrategy.h" 19 20 namespace mozilla::dom::quota { 21 22 struct DummyCipherStrategy { 23 struct KeyType {}; 24 25 static constexpr size_t BlockPrefixLength = 8; 26 static constexpr size_t BasicBlockSize = 4; 27 DummyTransformDummyCipherStrategy28 static void DummyTransform(Span<const uint8_t> aIn, Span<uint8_t> aOut) { 29 std::transform(aIn.cbegin(), aIn.cend(), aOut.begin(), 30 [](const uint8_t byte) { return byte ^ 42; }); 31 } 32 GenerateKeyDummyCipherStrategy33 static Result<KeyType, nsresult> GenerateKey() { return KeyType{}; } 34 35 nsresult Init(CipherMode aCipherMode, Span<const uint8_t> aKey, 36 Span<const uint8_t> aInitialIv = Span<const uint8_t>{}) { 37 return NS_OK; 38 } 39 CipherDummyCipherStrategy40 nsresult Cipher(Span<uint8_t> aIv, Span<const uint8_t> aIn, 41 Span<uint8_t> aOut) { 42 DummyTransform(aIn, aOut); 43 return NS_OK; 44 } 45 MakeBlockPrefixDummyCipherStrategy46 static std::array<uint8_t, BlockPrefixLength> MakeBlockPrefix() { 47 return {{42, 43, 44, 45}}; 48 } 49 SerializeKeyDummyCipherStrategy50 static Span<const uint8_t> SerializeKey(const KeyType&) { return {}; } 51 DeserializeKeyDummyCipherStrategy52 static KeyType DeserializeKey(const Span<const uint8_t>&) { return {}; } 53 }; 54 } // namespace mozilla::dom::quota 55 56 #endif 57