Skip to content

Commit

Permalink
Merge pull request #25 from nicolaschan/binary
Browse files Browse the repository at this point in the history
Switch to baybridge with binary values
  • Loading branch information
neelayjunnarkar authored Sep 5, 2024
2 parents d3ee978 + 4ee9c41 commit e6b8421
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 14 deletions.
122 changes: 115 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion insanity-native-tui-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ argon2 = "0.5.3"
chacha20poly1305 = "0.10.1"
blake3 = "1.5.4"
ed25519-dalek = { version = "2.1.1", features = ["serde"] }
ecoji = "1.0.0"
11 changes: 5 additions & 6 deletions insanity-native-tui-app/src/room_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tokio_util::sync::CancellationToken;
use crate::connection_manager::AugmentedInfo;

use baybridge::client::Actions;
use baybridge::models::Value;

use chacha20poly1305::{
aead::{Aead, AeadCore, KeyInit, OsRng},
Expand Down Expand Up @@ -61,9 +62,8 @@ async fn action_set(
};

// Set to key
let mut serialized_signed_value: &[u8] = &bincode::serialize(&signed_value)?;
let encoded_signed_value = ecoji::encode_to_string(&mut serialized_signed_value)?;
if let Err(e) = action.set(key, encoded_signed_value).await {
let serialized_signed_value: Vec<u8> = bincode::serialize(&signed_value)?;
if let Err(e) = action.set(key, serialized_signed_value.into()).await {
anyhow::bail!("Failed to set value to baybridge with error: {e}");
}

Expand Down Expand Up @@ -97,11 +97,10 @@ async fn set_own_info(
fn verify_and_decrypt(
cipher: &ChaCha20Poly1305,
verifying_key: &VerifyingKey,
info: String,
info: Value,
) -> anyhow::Result<AugmentedInfo> {
// Deserialize to SignedValue
let serialized_signed_value = ecoji::decode_to_vec(&mut info.as_bytes())?;
let signed_value: SignedValue = bincode::deserialize(&serialized_signed_value)?;
let signed_value: SignedValue = bincode::deserialize(info.as_bytes())?;

// Verify signature
verifying_key.verify_strict(&signed_value.msg, &signed_value.signature)?;
Expand Down

0 comments on commit e6b8421

Please sign in to comment.