@@ -271,6 +271,7 @@ def __init__(self, client: Client, channel: abc.Connectable):
271
271
"xsalsa20_poly1305_lite" ,
272
272
"xsalsa20_poly1305_suffix" ,
273
273
"xsalsa20_poly1305" ,
274
+ "aead_xchacha20_poly1305_rtpsize" ,
274
275
)
275
276
276
277
@property
@@ -565,19 +566,22 @@ def _get_voice_packet(self, data):
565
566
return encrypt_packet (header , data )
566
567
567
568
def _encrypt_xsalsa20_poly1305 (self , header : bytes , data ) -> bytes :
569
+ # Deprecated, remove in 2.7
568
570
box = nacl .secret .SecretBox (bytes (self .secret_key ))
569
571
nonce = bytearray (24 )
570
572
nonce [:12 ] = header
571
573
572
574
return header + box .encrypt (bytes (data ), bytes (nonce )).ciphertext
573
575
574
576
def _encrypt_xsalsa20_poly1305_suffix (self , header : bytes , data ) -> bytes :
577
+ # Deprecated, remove in 2.7
575
578
box = nacl .secret .SecretBox (bytes (self .secret_key ))
576
579
nonce = nacl .utils .random (nacl .secret .SecretBox .NONCE_SIZE )
577
580
578
581
return header + box .encrypt (bytes (data ), nonce ).ciphertext + nonce
579
582
580
583
def _encrypt_xsalsa20_poly1305_lite (self , header : bytes , data ) -> bytes :
584
+ # Deprecated, remove in 2.7
581
585
box = nacl .secret .SecretBox (bytes (self .secret_key ))
582
586
nonce = bytearray (24 )
583
587
@@ -586,7 +590,18 @@ def _encrypt_xsalsa20_poly1305_lite(self, header: bytes, data) -> bytes:
586
590
587
591
return header + box .encrypt (bytes (data ), bytes (nonce )).ciphertext + nonce [:4 ]
588
592
593
+ def _encrypt_aead_xchacha20_poly1305_rtpsize (self , header : bytes , data ) -> bytes :
594
+ # Required as of Nov 18 2024
595
+ box = nacl .secret .Aead (bytes (self .secret_key ))
596
+ nonce = bytearray (24 )
597
+
598
+ nonce [:4 ] = struct .pack ('>I' , self ._lite_nonce )
599
+ self .checked_add ('_lite_nonce' , 1 , 4294967295 )
600
+
601
+ return header + box .encrypt (bytes (data ), bytes (header ), bytes (nonce )).ciphertext + nonce [:4 ]
602
+
589
603
def _decrypt_xsalsa20_poly1305 (self , header , data ):
604
+ # Deprecated, remove in 2.7
590
605
box = nacl .secret .SecretBox (bytes (self .secret_key ))
591
606
592
607
nonce = bytearray (24 )
@@ -595,6 +610,7 @@ def _decrypt_xsalsa20_poly1305(self, header, data):
595
610
return self .strip_header_ext (box .decrypt (bytes (data ), bytes (nonce )))
596
611
597
612
def _decrypt_xsalsa20_poly1305_suffix (self , header , data ):
613
+ # Deprecated, remove in 2.7
598
614
box = nacl .secret .SecretBox (bytes (self .secret_key ))
599
615
600
616
nonce_size = nacl .secret .SecretBox .NONCE_SIZE
@@ -603,6 +619,7 @@ def _decrypt_xsalsa20_poly1305_suffix(self, header, data):
603
619
return self .strip_header_ext (box .decrypt (bytes (data [:- nonce_size ]), nonce ))
604
620
605
621
def _decrypt_xsalsa20_poly1305_lite (self , header , data ):
622
+ # Deprecated, remove in 2.7
606
623
box = nacl .secret .SecretBox (bytes (self .secret_key ))
607
624
608
625
nonce = bytearray (24 )
@@ -611,6 +628,16 @@ def _decrypt_xsalsa20_poly1305_lite(self, header, data):
611
628
612
629
return self .strip_header_ext (box .decrypt (bytes (data ), bytes (nonce )))
613
630
631
+ def _decrypt_aead_xchacha20_poly1305_rtpsize (self , header , data ):
632
+ # Required as of Nov 18 2024
633
+ box = nacl .secret .Aead (bytes (self .secret_key ))
634
+
635
+ nonce = bytearray (24 )
636
+ nonce [:4 ] = data [- 4 :]
637
+ data = data [:- 4 ]
638
+
639
+ return self .strip_header_ext (box .decrypt (bytes (data ), bytes (header ), bytes (nonce )))
640
+
614
641
@staticmethod
615
642
def strip_header_ext (data ):
616
643
if len (data ) > 4 and data [0 ] == 0xBE and data [1 ] == 0xDE :
0 commit comments