RtpCrypto
Handles RTP packet encryption and decryption for a voice connection. Owns the session secret key, encryption mode selection, and all sequence, timestamp, and nonce counters.
Summary
Properties
RtpCrypto.secretKey :: buffer?RtpCrypto.encryptionMode :: string?RtpCrypto.rtpSequence :: numberRtpCrypto.rtpTimestamp :: numberRtpCrypto.rtpNonceCounter :: numberMethods
RtpCrypto:encryptRtp(rtpPacket: buffer, daveEncryptor: dave.Encryptor?, ssrc: number, mediaProtocolVersion: number?, mediaReady: boolean?) → bufferRtpCrypto:decryptRtp(rtpPacket: buffer, ssrcToUserId: { [number]: string }, daveDecryptors: { [string]: dave.Decryptor }, mediaProtocolVersion: number?, downgradePending: boolean?) → buffer?RtpCrypto:reset()Functions
RtpCrypto.new() → RtpCryptoProperties
Section titled “Properties”secretKey
Section titled “secretKey”encryptionMode
Section titled “encryptionMode”rtpSequence
Section titled “rtpSequence”rtpTimestamp
Section titled “rtpTimestamp”rtpNonceCounter
Section titled “rtpNonceCounter”The next packet's nonce, sent big-endian as the packet's last four bytes. It starts at 0 with each session's new
key, and encryptRtp raises instead of using 0xFFFFFFFF.
Methods
Section titled “Methods”encryptRtp
Section titled “encryptRtp”RtpCrypto : encryptRtp ( rtpPacket , daveEncryptor , ssrc , mediaProtocolVersion , mediaReady ) -> buffer
Encrypts an RTP packet with the session cipher, and returns it with whether its Opus payload was replaced by
silence. Under DAVE (mediaProtocolVersion above 0) the payload is DAVE-encrypted first when mediaReady and an
encryptor are both there; otherwise the 3-byte Opus silence frame F8 FF FE goes in its place, which libdave
documents as the substitute while no key is active, so audio never leaves without DAVE. A payload that is exactly
that silence frame is never DAVE-encrypted, as discord.js and DAVEY send it, and libdave's decryptors pass it
through. Without DAVE the payload goes as it is. Raises RTP nonce exhausted; the session needs a new key, before
touching the encryptor, once the nonce counter reaches 0xFFFFFFFF.
Parameters
| rtpPacket: buffer | |
| daveEncryptor: Encryptor? | |
| ssrc: number | |
| mediaProtocolVersion: number? | |
| mediaReady: boolean? |
Returns
| buffer | |
| boolean |
decryptRtp
Section titled “decryptRtp”RtpCrypto : decryptRtp ( rtpPacket , ssrcToUserId , daveDecryptors , mediaProtocolVersion , downgradePending ) -> buffer?
Decrypts an RTP packet using the session cipher. Handles RTP header extensions and padding, then
optionally DAVE-decrypts the Opus payload using the per-user decryptor for the sender's SSRC. The packet it returns
has a plain 12-byte header: the CSRC list and the extension are dropped, so the first byte keeps only the version.
Returns nil and the reason for a packet it drops: one too short for its header, tag and nonce, one whose header
extension claims more than the plaintext holds, a DAVE frame from a sender with no decryptor yet, which happens
until their keys arrive, and, while media is under DAVE (mediaProtocolVersion above 0) and no move to version 0
is pending, any other frame from such a sender except the 3-byte Opus silence frame.
Parameters
| rtpPacket: buffer | |
| ssrcToUserId: { { [number]: string } } | |
| daveDecryptors: { { [string]: dave.Decryptor } } | |
| mediaProtocolVersion: number? | |
| downgradePending: boolean? |
Returns
| buffer? | |
| string? |
RtpCrypto : reset ( ) -> ()
Clears the secret key and encryption mode, and resets all sequence, timestamp, and nonce counters to zero.
Functions
Section titled “Functions”RtpCrypto . new ( ) -> RtpCrypto
Responsible for constructing this class.
Returns
| RtpCrypto |