blob: 1452b80189a85b898b456af32e63ba70f44ea6a3 [file] [log] [blame]
Benjamin Wrightea086912018-08-29 13:06:15 -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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef API_CRYPTO_FRAME_ENCRYPTOR_INTERFACE_H_
12#define API_CRYPTO_FRAME_ENCRYPTOR_INTERFACE_H_
Benjamin Wrightea086912018-08-29 13:06:15 -070013
14#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080015#include "api/media_types.h"
16#include "rtc_base/ref_count.h"
Benjamin Wrightea086912018-08-29 13:06:15 -070017
18namespace webrtc {
19
20// FrameEncryptorInterface allows users to provide a custom encryption
21// implementation to encrypt all outgoing audio and video frames. The user must
22// also provide a FrameDecryptorInterface to be able to decrypt the frames on
23// the receiving device. Note this is an additional layer of encryption in
24// addition to the standard SRTP mechanism and is not intended to be used
25// without it. Implementations of this interface will have the same lifetime as
Benjamin Wright1f87ec62018-09-12 13:29:08 -070026// the RTPSenders it is attached to. Additional data may be null.
Benjamin Wrightea086912018-08-29 13:06:15 -070027class FrameEncryptorInterface : public rtc::RefCountInterface {
28 public:
Benjamin Wrightd81ac952018-08-29 17:02:10 -070029 ~FrameEncryptorInterface() override {}
Benjamin Wrightea086912018-08-29 13:06:15 -070030
31 // Attempts to encrypt the provided frame. You may assume the encrypted_frame
Benjamin Wright88e3e3f2018-09-06 13:20:14 -070032 // will match the size returned by GetMaxCiphertextByteSize for a give frame.
33 // You may assume that the frames will arrive in order if SRTP is enabled.
34 // The ssrc will simply identify which stream the frame is travelling on. You
35 // must set bytes_written to the number of bytes you wrote in the
36 // encrypted_frame. 0 must be returned if successful all other numbers can be
37 // selected by the implementer to represent error codes.
38 virtual int Encrypt(cricket::MediaType media_type,
39 uint32_t ssrc,
Benjamin Wright1f87ec62018-09-12 13:29:08 -070040 rtc::ArrayView<const uint8_t> additional_data,
Benjamin Wright88e3e3f2018-09-06 13:20:14 -070041 rtc::ArrayView<const uint8_t> frame,
42 rtc::ArrayView<uint8_t> encrypted_frame,
43 size_t* bytes_written) = 0;
Benjamin Wrightea086912018-08-29 13:06:15 -070044
45 // Returns the total required length in bytes for the output of the
Benjamin Wright88e3e3f2018-09-06 13:20:14 -070046 // encryption. This can be larger than the actual number of bytes you need but
47 // must never be smaller as it informs the size of the encrypted_frame buffer.
48 virtual size_t GetMaxCiphertextByteSize(cricket::MediaType media_type,
49 size_t frame_size) = 0;
Benjamin Wrightea086912018-08-29 13:06:15 -070050};
51
52} // namespace webrtc
53
Steve Anton10542f22019-01-11 09:11:00 -080054#endif // API_CRYPTO_FRAME_ENCRYPTOR_INTERFACE_H_