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