tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fake_frame_encryptor.h (2482B)


      1 /*
      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_ENCRYPTOR_H_
     12 #define API_TEST_FAKE_FRAME_ENCRYPTOR_H_
     13 
     14 #include <stddef.h>
     15 #include <stdint.h>
     16 
     17 #include "api/array_view.h"
     18 #include "api/crypto/frame_encryptor_interface.h"
     19 #include "api/media_types.h"
     20 #include "rtc_base/ref_counted_object.h"
     21 
     22 namespace webrtc {
     23 
     24 // The FakeFrameEncryptor is a TEST ONLY fake implementation of the
     25 // FrameEncryptorInterface. It is constructed with a simple single digit key and
     26 // a fixed postfix byte. This is just to validate that the core code works
     27 // as expected.
     28 class FakeFrameEncryptor : public RefCountedObject<FrameEncryptorInterface> {
     29 public:
     30  // Provide a key (0,255) and some postfix byte (0,255).
     31  explicit FakeFrameEncryptor(uint8_t fake_key = 0xAA,
     32                              uint8_t postfix_byte = 255);
     33  // Simply xors each payload with the provided fake key and adds the postfix
     34  // bit to the end. This will always fail if fail_encryption_ is set to true.
     35  int Encrypt(MediaType media_type,
     36              uint32_t ssrc,
     37              ArrayView<const uint8_t> additional_data,
     38              ArrayView<const uint8_t> frame,
     39              ArrayView<uint8_t> encrypted_frame,
     40              size_t* bytes_written) override;
     41  // Always returns 1 more than the size of the frame.
     42  size_t GetMaxCiphertextByteSize(MediaType media_type,
     43                                  size_t frame_size) override;
     44  // Sets the fake key to use during encryption.
     45  void SetFakeKey(uint8_t fake_key);
     46  // Returns the fake key used during encryption.
     47  uint8_t GetFakeKey() const;
     48  // Set the postfix byte to use.
     49  void SetPostfixByte(uint8_t expected_postfix_byte);
     50  // Return a postfix byte added to each outgoing payload.
     51  uint8_t GetPostfixByte() const;
     52  // Force all encryptions to fail.
     53  void SetFailEncryption(bool fail_encryption);
     54 
     55  enum class FakeEncryptionStatus : int {
     56    OK = 0,
     57    FORCED_FAILURE = 1,
     58  };
     59 
     60 private:
     61  uint8_t fake_key_ = 0;
     62  uint8_t postfix_byte_ = 0;
     63  bool fail_encryption_ = false;
     64 };
     65 
     66 }  // namespace webrtc
     67 
     68 #endif  // API_TEST_FAKE_FRAME_ENCRYPTOR_H_