Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public sealed class Aes256GcmRtpSizeEncryption : IVoiceEncryption

private const int TagSize = 16;

public static bool IsSupported => AesGcm.IsSupported;

public string Name => "aead_aes256_gcm_rtpsize";

public int Expansion => TagSize + sizeof(int);
Expand Down
5 changes: 5 additions & 0 deletions NetCord/Gateway/Voice/Encryption/IVoiceEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace NetCord.Gateway.Voice.Encryption;
/// </summary>
public interface IVoiceEncryption : IDisposable
{
/// <summary>
/// Indicates whether the encryption algorithm is supported on the current platform.
/// </summary>
public static abstract bool IsSupported { get; }
Comment thread
KubaZ2 marked this conversation as resolved.

/// <summary>
/// The name of the encryption algorithm.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public sealed class XChaCha20Poly1305RtpSizeEncryption : IVoiceEncryption
private byte[]? _key;
private int _nonce;

public static bool IsSupported => true;

Comment thread
KubaZ2 marked this conversation as resolved.
public string Name => "aead_xchacha20_poly1305_rtpsize";

public int Expansion => XChaCha20Poly1305.ABytes + sizeof(int);
Expand Down
2 changes: 1 addition & 1 deletion NetCord/Gateway/Voice/VoiceEncryptionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private VoiceEncryptionProvider()

public IVoiceEncryption GetEncryption(IReadOnlyList<string> modes)
{
return modes.Contains("aead_aes256_gcm_rtpsize")
return (modes.Contains("aead_aes256_gcm_rtpsize") && Aes256GcmRtpSizeEncryption.IsSupported)
? new Aes256GcmRtpSizeEncryption()
: new XChaCha20Poly1305RtpSizeEncryption();
}
Comment thread
KubaZ2 marked this conversation as resolved.
Expand Down