tor-browser

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

fake_frame_encryptor.cc (2209B)


      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 #include "api/test/fake_frame_encryptor.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 
     16 #include "api/array_view.h"
     17 #include "api/media_types.h"
     18 #include "rtc_base/checks.h"
     19 
     20 namespace webrtc {
     21 FakeFrameEncryptor::FakeFrameEncryptor(uint8_t fake_key, uint8_t postfix_byte)
     22    : fake_key_(fake_key), postfix_byte_(postfix_byte) {}
     23 
     24 // FrameEncryptorInterface implementation
     25 int FakeFrameEncryptor::Encrypt(MediaType /* media_type */,
     26                                uint32_t /* ssrc */,
     27                                ArrayView<const uint8_t> /* additional_data */,
     28                                ArrayView<const uint8_t> frame,
     29                                ArrayView<uint8_t> encrypted_frame,
     30                                size_t* bytes_written) {
     31  if (fail_encryption_) {
     32    return static_cast<int>(FakeEncryptionStatus::FORCED_FAILURE);
     33  }
     34 
     35  RTC_CHECK_EQ(frame.size() + 1, encrypted_frame.size());
     36  for (size_t i = 0; i < frame.size(); i++) {
     37    encrypted_frame[i] = frame[i] ^ fake_key_;
     38  }
     39 
     40  encrypted_frame[frame.size()] = postfix_byte_;
     41  *bytes_written = encrypted_frame.size();
     42  return static_cast<int>(FakeEncryptionStatus::OK);
     43 }
     44 
     45 size_t FakeFrameEncryptor::GetMaxCiphertextByteSize(MediaType /* media_type */,
     46                                                    size_t frame_size) {
     47  return frame_size + 1;
     48 }
     49 
     50 void FakeFrameEncryptor::SetFakeKey(uint8_t fake_key) {
     51  fake_key_ = fake_key;
     52 }
     53 
     54 uint8_t FakeFrameEncryptor::GetFakeKey() const {
     55  return fake_key_;
     56 }
     57 
     58 void FakeFrameEncryptor::SetPostfixByte(uint8_t postfix_byte) {
     59  postfix_byte_ = postfix_byte;
     60 }
     61 
     62 uint8_t FakeFrameEncryptor::GetPostfixByte() const {
     63  return postfix_byte_;
     64 }
     65 
     66 void FakeFrameEncryptor::SetFailEncryption(bool fail_encryption) {
     67  fail_encryption_ = fail_encryption;
     68 }
     69 
     70 }  // namespace webrtc