Interface Encryptor

All Superinterfaces:
AutoCloseable
All Known Subinterfaces:
NettyEncryptor

public interface Encryptor extends AutoCloseable
Handles the encryption of outbound media frames using DAVE.

The Encryptor uses the local user's KeyRatchet to encrypt frames before they are sent.

  • Method Details

    • setKeyRatchet

      void setKeyRatchet(KeyRatchet keyRatchet)
      Sets the key ratchet to be used for encryption.

      This typically corresponds to the local user's ratchet derived from the session.

      Parameters:
      keyRatchet - The key ratchet.
    • setPassthroughMode

      void setPassthroughMode(boolean passthroughMode)
      Sets whether the encryptor should operate in passthrough mode.
      Parameters:
      passthroughMode - true to enable passthrough, false to disable.
    • assignSsrcToCodec

      void assignSsrcToCodec(int ssrc, Codec codec)
      Assigns an SSRC (Synchronization Source identifier) to a specific codec.

      This helps the encryptor understand how to parse and encrypt frames for a given stream.

      Parameters:
      ssrc - The SSRC identifier.
      codec - The codec used for this SSRC.
    • getProtocolVersion

      int getProtocolVersion()
      Gets the current protocol version used by the encryptor.
      Returns:
      The protocol version.
    • getMaxCiphertextByteSize

      default int getMaxCiphertextByteSize(MediaType mediaType, int frameSize)
      Calculates the maximum possible size of the ciphertext (encrypted) frame for a given plaintext frame size.
      Parameters:
      mediaType - The type of media.
      frameSize - The size of the plaintext frame.
      Returns:
      The maximum size of the encrypted frame in bytes.
    • encrypt

      int encrypt(MediaType mediaType, int ssrc, byte[] frame, byte[] encryptedFrame)
      Encrypts a media frame.
      Parameters:
      mediaType - The type of media.
      ssrc - The SSRC of the stream.
      frame - The input buffer containing the plaintext frame.
      encryptedFrame - The output buffer to write the encrypted frame into.
      Returns:
      The number of bytes written to encryptedFrame on success, or a negative error code (see EncryptorResultCode) on failure.
    • encrypt

      int encrypt(MediaType mediaType, int ssrc, ByteBuffer frame, ByteBuffer encryptedFrame)
      Encrypts a media frame into NIO ByteBuffer.
      Parameters:
      mediaType - The type of media.
      ssrc - The SSRC of the stream.
      frame - The input ByteBuffer containing the plaintext frame.
      encryptedFrame - The output ByteBuffer to write the encrypted frame into.
      Returns:
      The number of bytes written to encryptedFrame on success, or a negative error code on failure.
    • setProtocolVersionChangedCallback

      void setProtocolVersionChangedCallback(EncryptorProtocolVersionChangedCallback callback)
      Sets a callback to be notified when the protocol version changes.
      Parameters:
      callback - The callback listener.
    • close

      void close()
      Specified by:
      close in interface AutoCloseable