diff options
author | metamuffin <metamuffin@disroot.org> | 2023-02-05 20:57:47 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-02-05 20:57:47 +0100 |
commit | 2c6f4dc839a279b9d5c10d674489998b021908b8 (patch) | |
tree | 51922c7eceffdaf847713b15a1e30159b316d334 /client-native-lib/src | |
parent | 47556e24509d4c438a7fad6c05828ca4e3f2761a (diff) | |
download | keks-meet-2c6f4dc839a279b9d5c10d674489998b021908b8.tar keks-meet-2c6f4dc839a279b9d5c10d674489998b021908b8.tar.bz2 keks-meet-2c6f4dc839a279b9d5c10d674489998b021908b8.tar.zst |
update deps
Diffstat (limited to 'client-native-lib/src')
-rw-r--r-- | client-native-lib/src/crypto.rs | 9 | ||||
-rw-r--r-- | client-native-lib/src/peer.rs | 93 |
2 files changed, 47 insertions, 55 deletions
diff --git a/client-native-lib/src/crypto.rs b/client-native-lib/src/crypto.rs index 239c9f3..0472ec7 100644 --- a/client-native-lib/src/crypto.rs +++ b/client-native-lib/src/crypto.rs @@ -7,6 +7,7 @@ use aes_gcm::{ aead::{generic_array::sequence::GenericSequence, Aead}, Aes256Gcm, KeyInit, Nonce, }; +use base64::Engine; use log::info; pub struct Key(Aes256Gcm); @@ -14,7 +15,9 @@ pub struct Key(Aes256Gcm); impl Key { pub fn derive(secret: &str) -> Self { info!("running key generation..."); - let salt = base64::decode("thisisagoodsaltAAAAAAA==").unwrap(); + let salt = base64::engine::general_purpose::STANDARD + .decode("thisisagoodsaltAAAAAAA==") + .unwrap(); let mut key = [0u8; 32]; fastpbkdf2::pbkdf2_hmac_sha256(secret.as_bytes(), salt.as_slice(), 250000, &mut key); @@ -28,10 +31,10 @@ impl Key { let ciphertext = self.0.encrypt(&iv, s.as_bytes()).unwrap(); let mut packet = iv.to_vec(); // TODO this could be doing less allocations packet.extend(ciphertext); - base64::encode(packet) + base64::engine::general_purpose::STANDARD.encode(packet) } pub fn decrypt(&self, s: &str) -> String { - let r = base64::decode(s).unwrap(); + let r = base64::engine::general_purpose::STANDARD.decode(s).unwrap(); let iv = &r[0..12]; let ciphertext = &r[12..]; let plaintext = self.0.decrypt(Nonce::from_slice(iv), ciphertext).unwrap(); diff --git a/client-native-lib/src/peer.rs b/client-native-lib/src/peer.rs index b3b4dd4..8c27234 100644 --- a/client-native-lib/src/peer.rs +++ b/client-native-lib/src/peer.rs @@ -69,34 +69,28 @@ impl Peer { .on_peer_connection_state_change(Box::new(move |s: RTCPeerConnectionState| { info!("connection state changed: {s}"); Box::pin(async {}) - })) - .await; - + })); { let weak = Arc::<Peer>::downgrade(&peer); - peer.peer_connection - .on_ice_candidate(box move |c| { - if let Some(peer) = weak.upgrade() { - Box::pin(async move { - if let Some(c) = c { - peer.on_ice_candidate(c).await - } - }) - } else { - Box::pin(async move {}) - } - }) - .await; + peer.peer_connection.on_ice_candidate(box move |c| { + if let Some(peer) = weak.upgrade() { + Box::pin(async move { + if let Some(c) = c { + peer.on_ice_candidate(c).await + } + }) + } else { + Box::pin(async move {}) + } + }) } { let weak = Arc::<Peer>::downgrade(&peer); - peer.peer_connection - .on_negotiation_needed(box move || { - let peer = weak.upgrade().unwrap(); - Box::pin(async { peer.on_negotiation_needed().await }) - }) - .await; + peer.peer_connection.on_negotiation_needed(box move || { + let peer = weak.upgrade().unwrap(); + Box::pin(async { peer.on_negotiation_needed().await }) + }) } { @@ -124,37 +118,34 @@ impl Peer { } }) }) - .await; } { let weak = Arc::<Peer>::downgrade(&peer); - peer.peer_connection - .on_data_channel(box move |dc| { - let peer = weak.upgrade().unwrap(); - Box::pin(async move { - if let Some(res) = peer - .remote_provided - .read() - .await - .get(&dc.label().to_string()) - { - info!("data channel for ({:?}) '{:?}'", res.id, res.label); - peer.inst - .event_handler - .resource_connected( - peer.clone(), - res, - TransportChannel::DataChannel(dc), - ) - .await; - } else { - warn!("got unassociated data channel; closed connection"); - dc.close().await.unwrap(); - } - }) + peer.peer_connection.on_data_channel(box move |dc| { + let peer = weak.upgrade().unwrap(); + Box::pin(async move { + if let Some(res) = peer + .remote_provided + .read() + .await + .get(&dc.label().to_string()) + { + info!("data channel for ({:?}) '{:?}'", res.id, res.label); + peer.inst + .event_handler + .resource_connected( + peer.clone(), + res, + TransportChannel::DataChannel(dc), + ) + .await; + } else { + warn!("got unassociated data channel; closed connection"); + dc.close().await.unwrap(); + } }) - .await; + }) } peer } @@ -228,10 +219,8 @@ impl Peer { pub async fn on_ice_candidate(&self, candidate: RTCIceCandidate) { debug!("publishing local ICE candidate"); - self.send_relay(RelayMessage::IceCandidate( - candidate.to_json().await.unwrap(), - )) - .await; + self.send_relay(RelayMessage::IceCandidate(candidate.to_json().unwrap())) + .await; } pub async fn on_remote_ice_candidate(&self, candidate: RTCIceCandidateInit) { debug!("adding remote ICE candidate"); |