Skip to content

Decryptor

Decrypts incoming media frames using the DAVE protocol.

A Decryptor is created per remote participant stream. When the MLS group transitions to a new epoch, call transitionToKeyRatchet with the ratchet derived for that participant; the decryptor will maintain both the old and new ratchets for a short overlap window to absorb in-flight frames. Before the group is ready, call transitionToPassthroughMode(true) so frames pass through without attempting decryption.

local dec = Dave.Decryptor.new()
dec:transitionToKeyRatchet(session:getKeyRatchet(remoteUserId))
local plaintext = dec:decrypt(Dave.sys.mediaType.audio, encryptedFrame)
Decryptor.handle  :: DecryptorHandle
Decryptor : transitionToKeyRatchet ( keyRatchet )  -> ()

Transitions the decryptor to use a new key ratchet, typically called after each MLS epoch change. The library retains both the old and new ratchets for a short overlap window so in-flight frames encrypted under the previous epoch are still accepted. Obtain a ratchet from Session:getKeyRatchet(remoteUserId).

Parameters

keyRatchet: KeyRatchet
Decryptor : transitionToPassthroughMode ( enabled )  -> ()

Transitions the decryptor into or out of passthrough mode. When enabled, frames are returned from decrypt unchanged without any key material being consumed. Use this while the MLS group is not yet established.

Parameters

enabled: boolean
Decryptor : getMaxPlaintextByteSize ( mediaType encryptedFrameSize )  -> number

Returns the maximum number of plaintext bytes that decrypt may produce for an encrypted frame of encryptedFrameSize bytes on mediaType. Useful for pre-allocating receive buffers.

Parameters

mediaType: number
encryptedFrameSize: number

Returns

number
Decryptor : decrypt ( mediaType encryptedFrame )  -> buffer

Decrypts encryptedFrame and returns the plaintext as a new buffer. Logs an error and halts the calling coroutine on any non-success result code (missing ratchet, invalid nonce, etc.).

Parameters

mediaType: number
encryptedFrame: buffer

Returns

buffer
Decryptor : getStats ( mediaType )  -> DecryptorStats

Returns a snapshot of decryption statistics for mediaType. Statistics are cumulative since the decryptor was created. mediaType should be a value from Dave.sys.mediaType.

Parameters

mediaType: number

Returns

DecryptorStats
Decryptor : destroy ( )  -> ()

Destroys the decryptor and frees all associated libdave resources. The decryptor must not be used after this call.

Decryptor . new ( )  -> Decryptor

Constructs a new Decryptor.

Returns

Decryptor