blob: b945def59a8b0a5b74745f52b74208bf165de5c3 [file] [log] [blame]
Benjamin Wright84583f62018-10-04 14:22:34 -07001/*
2 * Copyright 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_TEST_FAKE_FRAME_DECRYPTOR_H_
12#define API_TEST_FAKE_FRAME_DECRYPTOR_H_
13
14#include <vector>
15
16#include "api/crypto/framedecryptorinterface.h"
17#include "rtc_base/refcountedobject.h"
18
19namespace webrtc {
20
21// The FakeFrameDecryptor is a TEST ONLY fake implementation of the
22// FrameDecryptorInterface. It is constructed with a simple single digit key and
23// a fixed postfix byte. This is just to validate that the core code works
24// as expected.
25class FakeFrameDecryptor
26 : public rtc::RefCountedObject<FrameDecryptorInterface> {
27 public:
28 // Provide a key (0,255) and some postfix byte (0,255) this should match the
29 // byte you expect from the FakeFrameEncryptor.
30 explicit FakeFrameDecryptor(uint8_t fake_key = 1,
31 uint8_t expected_postfix_byte = 255);
32
33 // FrameDecryptorInterface implementation
34 int Decrypt(cricket::MediaType media_type,
35 const std::vector<uint32_t>& csrcs,
36 rtc::ArrayView<const uint8_t> additional_data,
37 rtc::ArrayView<const uint8_t> encrypted_frame,
38 rtc::ArrayView<uint8_t> frame,
39 size_t* bytes_written) override;
40
41 size_t GetMaxPlaintextByteSize(cricket::MediaType media_type,
42 size_t encrypted_frame_size) override;
43
44 void SetFakeKey(uint8_t fake_key);
45
46 uint8_t GetFakeKey() const;
47
48 void SetExpectedPostfixByte(uint8_t expected_postfix_byte);
49
50 uint8_t GetExpectedPostfixByte() const;
51
52 void SetFailDecryption(bool fail_decryption);
53
54 private:
55 uint8_t fake_key_ = 0;
56 uint8_t expected_postfix_byte_ = 0;
57 bool fail_decryption_ = false;
58};
59
60} // namespace webrtc
61
62#endif // API_TEST_FAKE_FRAME_DECRYPTOR_H_