tor-browser

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

frame_decryptor_interface.h (3488B)


      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_CRYPTO_FRAME_DECRYPTOR_INTERFACE_H_
     12 #define API_CRYPTO_FRAME_DECRYPTOR_INTERFACE_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <vector>
     17 
     18 #include "api/array_view.h"
     19 #include "api/media_types.h"
     20 #include "api/ref_count.h"
     21 
     22 namespace webrtc {
     23 
     24 // FrameDecryptorInterface allows users to provide a custom decryption
     25 // implementation for all incoming audio and video frames. The user must also
     26 // provide a FrameEncryptorInterface to be able to encrypt the frames being
     27 // sent out of the device. Note this is an additional layer of encyrption in
     28 // addition to the standard SRTP mechanism and is not intended to be used
     29 // without it. You may assume that this interface will have the same lifetime
     30 // as the RTPReceiver it is attached to. It must only be attached to one
     31 // RTPReceiver. Additional data may be null.
     32 class FrameDecryptorInterface : public RefCountInterface {
     33 public:
     34  // The Status enum represents all possible states that can be
     35  // returned when attempting to decrypt a frame. kRecoverable indicates that
     36  // there was an error with the given frame and so it should not be passed to
     37  // the decoder, however it hints that the receive stream is still decryptable
     38  // which is important for determining when to send key frame requests
     39  // kUnknown should never be returned by the implementor.
     40  enum class Status { kOk, kRecoverable, kFailedToDecrypt, kUnknown };
     41 
     42  struct Result {
     43    Result(Status status, size_t bytes_written)
     44        : status(status), bytes_written(bytes_written) {}
     45 
     46    bool IsOk() const { return status == Status::kOk; }
     47 
     48    const Status status;
     49    const size_t bytes_written;
     50  };
     51 
     52  ~FrameDecryptorInterface() override {}
     53 
     54  // Attempts to decrypt the encrypted frame. You may assume the frame size will
     55  // be allocated to the size returned from GetMaxPlaintextSize. You may assume
     56  // that the frames are in order if SRTP is enabled. The stream is not provided
     57  // here and it is up to the implementor to transport this information to the
     58  // receiver if they care about it. You must set bytes_written to how many
     59  // bytes you wrote to in the frame buffer. kOk must be returned if successful,
     60  // kRecoverable should be returned if the failure was due to something other
     61  // than a decryption failure. kFailedToDecrypt should be returned in all other
     62  // cases.
     63  virtual Result Decrypt(MediaType media_type,
     64                         const std::vector<uint32_t>& csrcs,
     65                         ArrayView<const uint8_t> additional_data,
     66                         ArrayView<const uint8_t> encrypted_frame,
     67                         ArrayView<uint8_t> frame) = 0;
     68 
     69  // Returns the total required length in bytes for the output of the
     70  // decryption. This can be larger than the actual number of bytes you need but
     71  // must never be smaller as it informs the size of the frame buffer.
     72  virtual size_t GetMaxPlaintextByteSize(MediaType media_type,
     73                                         size_t encrypted_frame_size) = 0;
     74 };
     75 
     76 }  // namespace webrtc
     77 
     78 #endif  // API_CRYPTO_FRAME_DECRYPTOR_INTERFACE_H_