Chore: Update xsalsa20poly1305 -> 0.9
A few extra error types needed adding and handling due to the new `KeyInit::new_from_slice` returning a non-exported error.
This commit is contained in:
@@ -46,7 +46,7 @@ twilight-model = { default-features = false, optional = true, version = "0.12.0"
|
|||||||
typemap_rev = { optional = true, version = "0.1" }
|
typemap_rev = { optional = true, version = "0.1" }
|
||||||
url = { optional = true, version = "2" }
|
url = { optional = true, version = "2" }
|
||||||
uuid = { features = ["v4"], optional = true, version = "1" }
|
uuid = { features = ["v4"], optional = true, version = "1" }
|
||||||
xsalsa20poly1305 = { features = ["std"], optional = true, version = "0.8" }
|
xsalsa20poly1305 = { features = ["std"], optional = true, version = "0.9" }
|
||||||
|
|
||||||
[dependencies.serenity]
|
[dependencies.serenity]
|
||||||
version = "0.11"
|
version = "0.11"
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ pub enum Error {
|
|||||||
/// The driver hung up an internal signaller, either due to another connection attempt
|
/// The driver hung up an internal signaller, either due to another connection attempt
|
||||||
/// or a crash.
|
/// or a crash.
|
||||||
AttemptDiscarded,
|
AttemptDiscarded,
|
||||||
/// An error occurred during [en/de]cryption of voice packets or key generation.
|
/// An error occurred during [en/de]cryption of voice packets.
|
||||||
Crypto(CryptoError),
|
Crypto(CryptoError),
|
||||||
|
/// The symmetric key supplied by Discord had the wrong size.
|
||||||
|
CryptoInvalidLength,
|
||||||
/// Server did not return the expected crypto mode during negotiation.
|
/// Server did not return the expected crypto mode during negotiation.
|
||||||
CryptoModeInvalid,
|
CryptoModeInvalid,
|
||||||
/// Selected crypto mode was not offered by server.
|
/// Selected crypto mode was not offered by server.
|
||||||
@@ -97,6 +99,7 @@ impl fmt::Display for Error {
|
|||||||
match self {
|
match self {
|
||||||
Self::AttemptDiscarded => write!(f, "connection attempt was aborted/discarded"),
|
Self::AttemptDiscarded => write!(f, "connection attempt was aborted/discarded"),
|
||||||
Self::Crypto(e) => e.fmt(f),
|
Self::Crypto(e) => e.fmt(f),
|
||||||
|
Self::CryptoInvalidLength => write!(f, "server supplied key of wrong length"),
|
||||||
Self::CryptoModeInvalid => write!(f, "server changed negotiated encryption mode"),
|
Self::CryptoModeInvalid => write!(f, "server changed negotiated encryption mode"),
|
||||||
Self::CryptoModeUnavailable => write!(f, "server did not offer chosen encryption mode"),
|
Self::CryptoModeUnavailable => write!(f, "server did not offer chosen encryption mode"),
|
||||||
Self::EndpointUrl => write!(f, "endpoint URL received from gateway was invalid"),
|
Self::EndpointUrl => write!(f, "endpoint URL received from gateway was invalid"),
|
||||||
@@ -117,6 +120,7 @@ impl StdError for Error {
|
|||||||
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
Error::AttemptDiscarded
|
Error::AttemptDiscarded
|
||||||
|
| Error::CryptoInvalidLength
|
||||||
| Error::CryptoModeInvalid
|
| Error::CryptoModeInvalid
|
||||||
| Error::CryptoModeUnavailable
|
| Error::CryptoModeUnavailable
|
||||||
| Error::EndpointUrl
|
| Error::EndpointUrl
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use std::{net::IpAddr, str::FromStr};
|
|||||||
use tokio::{net::UdpSocket, spawn, time::timeout};
|
use tokio::{net::UdpSocket, spawn, time::timeout};
|
||||||
use tracing::{debug, info, instrument};
|
use tracing::{debug, info, instrument};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use xsalsa20poly1305::{aead::NewAead, XSalsa20Poly1305 as Cipher};
|
use xsalsa20poly1305::{KeyInit, XSalsa20Poly1305 as Cipher};
|
||||||
|
|
||||||
pub(crate) struct Connection {
|
pub(crate) struct Connection {
|
||||||
pub(crate) info: ConnectionInfo,
|
pub(crate) info: ConnectionInfo,
|
||||||
@@ -353,7 +353,8 @@ async fn init_cipher(client: &mut WsStream, mode: CryptoMode) -> Result<Cipher>
|
|||||||
return Err(Error::CryptoModeInvalid);
|
return Err(Error::CryptoModeInvalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(Cipher::new_from_slice(&desc.secret_key)?);
|
return Cipher::new_from_slice(&desc.secret_key)
|
||||||
|
.map_err(|_| Error::CryptoInvalidLength);
|
||||||
},
|
},
|
||||||
other => {
|
other => {
|
||||||
debug!(
|
debug!(
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ impl CryptoState {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use discortp::rtp::MutableRtpPacket;
|
use discortp::rtp::MutableRtpPacket;
|
||||||
use xsalsa20poly1305::{aead::NewAead, KEY_SIZE, TAG_SIZE};
|
use xsalsa20poly1305::{KeyInit, KEY_SIZE, TAG_SIZE};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn small_packet_decrypts_error() {
|
fn small_packet_decrypts_error() {
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ impl From<&ConnectionError> for DisconnectReason {
|
|||||||
fn from(e: &ConnectionError) -> Self {
|
fn from(e: &ConnectionError) -> Self {
|
||||||
match e {
|
match e {
|
||||||
ConnectionError::AttemptDiscarded => Self::AttemptDiscarded,
|
ConnectionError::AttemptDiscarded => Self::AttemptDiscarded,
|
||||||
ConnectionError::CryptoModeInvalid
|
ConnectionError::CryptoInvalidLength
|
||||||
|
| ConnectionError::CryptoModeInvalid
|
||||||
| ConnectionError::CryptoModeUnavailable
|
| ConnectionError::CryptoModeUnavailable
|
||||||
| ConnectionError::EndpointUrl
|
| ConnectionError::EndpointUrl
|
||||||
| ConnectionError::ExpectedHandshake
|
| ConnectionError::ExpectedHandshake
|
||||||
|
|||||||
Reference in New Issue
Block a user