Fixed several audio stream issues
This commit is contained in:
@@ -7,16 +7,14 @@ namespace Discord.Audio.Streams
|
||||
///<summary> Encrypts an RTP frame using libsodium </summary>
|
||||
public class SodiumEncryptStream : AudioOutStream
|
||||
{
|
||||
private readonly AudioOutStream _next;
|
||||
private readonly byte[] _nonce, _secretKey;
|
||||
private readonly AudioClient _client;
|
||||
private readonly AudioStream _next;
|
||||
private readonly byte[] _nonce;
|
||||
|
||||
//protected readonly byte[] _buffer;
|
||||
|
||||
public SodiumEncryptStream(AudioOutStream next, byte[] secretKey/*, int bufferSize = 4000*/)
|
||||
public SodiumEncryptStream(AudioStream next, IAudioClient client)
|
||||
{
|
||||
_next = next;
|
||||
_secretKey = secretKey;
|
||||
//_buffer = new byte[bufferSize]; //TODO: Can Sodium do an in-place encrypt?
|
||||
_client = (AudioClient)client;
|
||||
_nonce = new byte[24];
|
||||
}
|
||||
|
||||
@@ -24,8 +22,11 @@ namespace Discord.Audio.Streams
|
||||
{
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (_client.SecretKey == null)
|
||||
return;
|
||||
|
||||
Buffer.BlockCopy(buffer, offset, _nonce, 0, 12); //Copy nonce from RTP header
|
||||
count = SecretBox.Encrypt(buffer, offset + 12, count - 12, buffer, 12, _nonce, _secretKey);
|
||||
count = SecretBox.Encrypt(buffer, offset + 12, count - 12, buffer, 12, _nonce, _client.SecretKey);
|
||||
await _next.WriteAsync(buffer, 0, count + 12, cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user