Driver: Replace xsalsa20poly1305 with crypto_secretbox (#198)
As of v0.9.1, `xsalsa20poly1305` has been deprecated. This is a mostly seamless replacement, as it appears to be the same crate authors / code / etc. Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ async-trait = { optional = true, version = "0.1" }
|
||||
audiopus = { optional = true, version = "0.3.0-rc.0" }
|
||||
byteorder = { optional = true, version = "1" }
|
||||
bytes = { optional = true, version = "1" }
|
||||
crypto_secretbox = { optional = true, features = ["std"], version = "0.1" }
|
||||
dashmap = { optional = true, version = "5" }
|
||||
derivative = "2"
|
||||
discortp = { default-features = false, features = ["discord", "pnet", "rtp"], optional = true, version = "0.5" }
|
||||
@@ -50,7 +51,6 @@ twilight-model = { default-features = false, optional = true, version = "0.15.0"
|
||||
typemap_rev = { optional = true, version = "0.3" }
|
||||
url = { optional = true, version = "2" }
|
||||
uuid = { features = ["v4"], optional = true, version = "1" }
|
||||
xsalsa20poly1305 = { features = ["std"], optional = true, version = "0.9" }
|
||||
|
||||
[dependencies.serenity]
|
||||
version = "0.11"
|
||||
@@ -91,6 +91,7 @@ driver = [
|
||||
"dep:async-trait",
|
||||
"dep:audiopus",
|
||||
"dep:byteorder",
|
||||
"dep:crypto_secretbox",
|
||||
"dep:discortp",
|
||||
"dep:reqwest",
|
||||
"dep:flume",
|
||||
@@ -113,7 +114,6 @@ driver = [
|
||||
"dep:typemap_rev",
|
||||
"dep:url",
|
||||
"dep:uuid",
|
||||
"dep:xsalsa20poly1305",
|
||||
"tokio?/fs",
|
||||
"tokio?/io-util",
|
||||
"tokio?/macros",
|
||||
|
||||
@@ -4,11 +4,11 @@ use crate::{
|
||||
driver::tasks::{error::Recipient, message::*},
|
||||
ws::Error as WsError,
|
||||
};
|
||||
use crypto_secretbox::Error as CryptoError;
|
||||
use flume::SendError;
|
||||
use serde_json::Error as JsonError;
|
||||
use std::{error::Error as StdError, fmt, io::Error as IoError};
|
||||
use tokio::time::error::Elapsed;
|
||||
use xsalsa20poly1305::aead::Error as CryptoError;
|
||||
|
||||
/// Errors encountered while connecting to a Discord voice server over the driver.
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::{
|
||||
ws::WsStream,
|
||||
ConnectionInfo,
|
||||
};
|
||||
use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher};
|
||||
use discortp::discord::{IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPacket};
|
||||
use error::{Error, Result};
|
||||
use flume::Sender;
|
||||
@@ -30,7 +31,6 @@ use std::{net::IpAddr, str::FromStr};
|
||||
use tokio::{net::UdpSocket, spawn, time::timeout};
|
||||
use tracing::{debug, info, instrument};
|
||||
use url::Url;
|
||||
use xsalsa20poly1305::{KeyInit, XSalsa20Poly1305 as Cipher};
|
||||
|
||||
pub(crate) struct Connection {
|
||||
pub(crate) info: ConnectionInfo,
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
//! Encryption schemes supported by Discord's secure RTP negotiation.
|
||||
use byteorder::{NetworkEndian, WriteBytesExt};
|
||||
#[cfg(any(feature = "receive", test))]
|
||||
use crypto_secretbox::Tag;
|
||||
use crypto_secretbox::{
|
||||
aead::{AeadInPlace, Error as CryptoError},
|
||||
Nonce,
|
||||
SecretBox,
|
||||
XSalsa20Poly1305 as Cipher,
|
||||
};
|
||||
use discortp::{rtp::RtpPacket, MutablePacket};
|
||||
use rand::Rng;
|
||||
use std::num::Wrapping;
|
||||
#[cfg(any(feature = "receive", test))]
|
||||
use xsalsa20poly1305::Tag;
|
||||
use xsalsa20poly1305::{
|
||||
aead::{AeadInPlace, Error as CryptoError},
|
||||
Nonce,
|
||||
XSalsa20Poly1305 as Cipher,
|
||||
NONCE_SIZE,
|
||||
TAG_SIZE,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub const KEY_SIZE: usize = SecretBox::<()>::KEY_SIZE;
|
||||
pub const NONCE_SIZE: usize = SecretBox::<()>::NONCE_SIZE;
|
||||
pub const TAG_SIZE: usize = SecretBox::<()>::TAG_SIZE;
|
||||
|
||||
/// Variants of the `XSalsa20Poly1305` encryption scheme.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@@ -253,8 +257,8 @@ impl CryptoState {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crypto_secretbox::KeyInit;
|
||||
use discortp::rtp::MutableRtpPacket;
|
||||
use xsalsa20poly1305::{KeyInit, KEY_SIZE, TAG_SIZE};
|
||||
|
||||
#[test]
|
||||
fn small_packet_decrypts_error() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::message::*;
|
||||
use crate::ws::Error as WsError;
|
||||
use audiopus::Error as OpusError;
|
||||
use crypto_secretbox::aead::Error as CryptoError;
|
||||
use flume::SendError;
|
||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||
use xsalsa20poly1305::aead::Error as CryptoError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Recipient {
|
||||
|
||||
@@ -8,10 +8,10 @@ use crate::{
|
||||
driver::{Bitrate, Config, CryptoState},
|
||||
input::{AudioStreamError, Compose, Parsed},
|
||||
};
|
||||
use crypto_secretbox::XSalsa20Poly1305 as Cipher;
|
||||
use flume::Sender;
|
||||
use std::{net::UdpSocket, sync::Arc};
|
||||
use symphonia_core::{errors::Error as SymphoniaError, formats::SeekedTo};
|
||||
use xsalsa20poly1305::XSalsa20Poly1305 as Cipher;
|
||||
|
||||
pub struct MixerConnection {
|
||||
pub cipher: Cipher,
|
||||
|
||||
@@ -15,6 +15,7 @@ use super::{
|
||||
error::{Error, Result},
|
||||
message::*,
|
||||
};
|
||||
use crate::driver::crypto::TAG_SIZE;
|
||||
use crate::{
|
||||
constants::*,
|
||||
driver::MixMode,
|
||||
@@ -53,7 +54,6 @@ use symphonia_core::{
|
||||
};
|
||||
use tokio::runtime::Handle;
|
||||
use tracing::error;
|
||||
use xsalsa20poly1305::TAG_SIZE;
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::driver::test_config::{OutputMessage, OutputMode};
|
||||
|
||||
@@ -12,6 +12,7 @@ use crate::{
|
||||
Config,
|
||||
};
|
||||
use bytes::BytesMut;
|
||||
use crypto_secretbox::XSalsa20Poly1305 as Cipher;
|
||||
use discortp::{
|
||||
demux::{self, DemuxedMut},
|
||||
rtp::RtpPacket,
|
||||
@@ -25,7 +26,6 @@ use std::{
|
||||
};
|
||||
use tokio::{net::UdpSocket, select, time::Instant};
|
||||
use tracing::{error, instrument, trace, warn};
|
||||
use xsalsa20poly1305::XSalsa20Poly1305 as Cipher;
|
||||
|
||||
type RtpSequence = Wrapping<u16>;
|
||||
type RtpTimestamp = Wrapping<u32>;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use crate::{
|
||||
constants::*,
|
||||
driver::crypto::KEY_SIZE,
|
||||
input::{
|
||||
cached::Compressed,
|
||||
codecs::{CODEC_REGISTRY, PROBE},
|
||||
@@ -10,10 +11,10 @@ use crate::{
|
||||
test_utils,
|
||||
tracks::LoopState,
|
||||
};
|
||||
use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher};
|
||||
use flume::{Receiver, Sender};
|
||||
use std::{io::Cursor, net::UdpSocket, sync::Arc};
|
||||
use tokio::runtime::Handle;
|
||||
use xsalsa20poly1305::{KeyInit, XSalsa20Poly1305 as Cipher, KEY_SIZE};
|
||||
|
||||
use super::{
|
||||
scheduler::*,
|
||||
|
||||
Reference in New Issue
Block a user