Skip to content

Commit

Permalink
Deprecate pynacl voice dependency
Browse files Browse the repository at this point in the history
- disco.util.crypto: removed `pynacl`
- disco.voice.udp: cleanup
  • Loading branch information
elderlabs committed Sep 18, 2024
1 parent 68cd3f5 commit 066e37a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
14 changes: 5 additions & 9 deletions disco/util/crypto.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from warnings import warn as warnings_warn

try:
from nacl.utils import EncryptedMessage
except ImportError:
warnings_warn('nacl is not installed, voice support is disabled')

try:
from libnacl import crypto_aead_xchacha20poly1305_ietf_encrypt, crypto_aead_xchacha20poly1305_ietf_decrypt, crypto_aead_aes256gcm_encrypt, crypto_aead_aes256gcm_decrypt
except ImportError:
Expand All @@ -13,7 +8,9 @@

class AEScrypt:
"""
BECAUSE PYNACL REFUSES TO DO IT WITH THEIR TERRIBLE SELF-RIGHTEOUS PRACTICES
BECAUSE PYNACL REFUSED TO DO IT WITH THEIR TERRIBLE SELF-RIGHTEOUS PRACTICES,
BUT IN THIS MODERN AGE, WE NEEDED A GRACEFUL WRAPPER FOR LIBNACL AS PYNACL IS DEAD.
LONG LIVE LIBNACL, THE INFINITELY SUPERIOR SUCCESSOR TO PYNACL.
"""
def __init__(self, key: bytes, ciper: str):
self._key = key
Expand All @@ -25,10 +22,9 @@ def __bytes__(self) -> bytes:

def encrypt(self, plaintext: bytes, nonce: bytes, aad: bytes) -> bytes:
if self.cipher == 'aead_xchacha20_poly1305_rtpsize':
payload = crypto_aead_xchacha20poly1305_ietf_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key)
return crypto_aead_xchacha20poly1305_ietf_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key)
else:
payload = crypto_aead_aes256gcm_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key)
return EncryptedMessage._from_parts(nonce, payload, nonce + payload)
return crypto_aead_aes256gcm_encrypt(message=plaintext, aad=aad, nonce=nonce, key=self._key)

def decrypt(self, ciphertext: bytes, nonce: bytes, aad: bytes) -> bytes:
if self.cipher == 'aead_xchacha20_poly1305_rtpsize':
Expand Down
6 changes: 2 additions & 4 deletions disco/voice/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,9 @@ def send_frame(self, frame, sequence=None, timestamp=None, incr_timestamp=None):

# Encrypt the payload with the nonce
payload = self._secret_box.encrypt(plaintext=frame, nonce=bytes(nonce), aad=bytes(self._rtp_audio_header))
payload = payload.ciphertext

# Pad the payload with the nonce, if applicable
if nonce_padding:
payload += nonce_padding
# Pad the payload with the nonce
payload += nonce_padding

# Send the header (sans nonce padding) plus the payload
self.send(self._rtp_audio_header + payload)
Expand Down

0 comments on commit 066e37a

Please sign in to comment.