#![cfg(feature = "afc")]
use anyhow::{Context, Result};
use aranya_daemon_api::text;
use super::common::{sleep, DevicesCtx, SLEEP_INTERVAL};
use crate::{afc::Channels, client::ChanOp, Rank};
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_create_assign_revoke_delete_label() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_create_assign_revoke_delete_label").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
let owner_team = devices.owner.client.team(team_id);
let membera_team = devices.membera.client.team(team_id);
let memberb_team = devices.memberb.client.team(team_id);
membera_team.sync_now(owner_addr, None).await?;
assert_eq!(membera_team.labels().await?.iter().count(), 0);
memberb_team.sync_now(owner_addr, None).await?;
assert_eq!(memberb_team.labels().await?.iter().count(), 0);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
membera_team.sync_now(owner_addr, None).await?;
assert_eq!(membera_team.labels().await?.iter().count(), 1);
memberb_team.sync_now(owner_addr, None).await?;
assert_eq!(memberb_team.labels().await?.iter().count(), 1);
owner_team
.device(devices.operator.id)
.assign_label(label_id, op)
.await
.context("unable to assign label")
.expect_err("expected label assignment to fail");
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
membera_team.sync_now(owner_addr, None).await?;
assert_eq!(
membera_team
.device(devices.membera.id)
.label_assignments()
.await?
.iter()
.count(),
1
);
memberb_team.sync_now(owner_addr, None).await?;
assert_eq!(
memberb_team
.device(devices.memberb.id)
.label_assignments()
.await?
.iter()
.count(),
1
);
owner_team
.device(devices.membera.id)
.revoke_label(label_id)
.await?;
owner_team
.device(devices.memberb.id)
.revoke_label(label_id)
.await?;
membera_team.sync_now(owner_addr, None).await?;
assert_eq!(
membera_team
.device(devices.membera.id)
.label_assignments()
.await?
.iter()
.count(),
0
);
memberb_team.sync_now(owner_addr, None).await?;
assert_eq!(
memberb_team
.device(devices.memberb.id)
.label_assignments()
.await?
.iter()
.count(),
0
);
owner_team.delete_label(label_id).await?;
membera_team.sync_now(owner_addr, None).await?;
assert_eq!(membera_team.labels().await?.iter().count(), 0);
memberb_team.sync_now(owner_addr, None).await?;
assert_eq!(memberb_team.labels().await?.iter().count(), 0);
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await
.expect_err("expected label assignment to fail with deleted label");
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_chan_create() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_chan_create").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let (_chan, ctrl) = devices
.membera
.client
.afc()
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
devices
.memberb
.client
.afc()
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_send_chan_seal_open() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_send_chan_seal_open").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan, ctrl) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
let recv = memberb_afc
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext = vec![0u8; ciphertext.len() - Channels::OVERHEAD];
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")?;
assert_eq!(afc_msg, plaintext);
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_chan_delete() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_chan_delete").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan, ctrl) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
let recv = memberb_afc
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext = vec![0u8; ciphertext.len() - Channels::OVERHEAD];
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")?;
chan.delete().await.context("unable to delete channel")?;
recv.delete().await.context("unable to delete channel")?;
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")
.expect_err("expected open to fail");
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_chan_revoke_label() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_chan_revoke_label").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan, ctrl) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
let recv = memberb_afc
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext = vec![0u8; ciphertext.len() - Channels::OVERHEAD];
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")?;
owner_team
.device(devices.membera.id)
.revoke_label(label_id)
.await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
sleep(SLEEP_INTERVAL).await;
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")
.expect_err("expected open to fail");
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_chan_delete_label() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_chan_delete_label").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan, ctrl) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
let recv = memberb_afc
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext = vec![0u8; ciphertext.len() - Channels::OVERHEAD];
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")?;
let operator_addr = devices.operator.aranya_local_addr().await?;
devices
.admin
.client
.team(team_id)
.sync_now(operator_addr, None)
.await?;
owner_team.delete_label(label_id).await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
sleep(SLEEP_INTERVAL).await;
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")
.expect_err("expected open to fail");
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_chan_remove_devices() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_chan_remove_devices").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan, ctrl) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
let recv = memberb_afc
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext = vec![0u8; ciphertext.len() - Channels::OVERHEAD];
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")?;
let operator_addr = devices.operator.aranya_local_addr().await?;
devices
.admin
.client
.team(team_id)
.sync_now(operator_addr, None)
.await?;
owner_team
.device(devices.membera.id)
.remove_from_team()
.await?;
owner_team
.device(devices.memberb.id)
.remove_from_team()
.await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
sleep(SLEEP_INTERVAL).await;
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")
.expect_err("expected open to fail");
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_chan_revoke_role() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_chan_revoke_role").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan, ctrl) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
let recv = memberb_afc
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext = vec![0u8; ciphertext.len() - Channels::OVERHEAD];
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")?;
let operator_addr = devices.operator.aranya_local_addr().await?;
devices
.admin
.client
.team(team_id)
.sync_now(operator_addr, None)
.await?;
owner_team
.device(devices.membera.id)
.revoke_role(default_roles.member().id)
.await?;
owner_team
.device(devices.memberb.id)
.revoke_role(default_roles.member().id)
.await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
sleep(SLEEP_INTERVAL).await;
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")
.expect_err("expected open to fail");
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_chan_change_role_without_perm() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_chan_change_role_without_perm").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let label_id = owner_team.create_label(text!("label1"), label_rank).await?;
let op = ChanOp::SendRecv;
owner_team
.device(devices.membera.id)
.assign_label(label_id, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan, ctrl) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id)
.await
.context("unable to create afc uni channel")?;
let recv = memberb_afc
.accept_channel(team_id, ctrl)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext = vec![0u8; ciphertext.len() - Channels::OVERHEAD];
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")?;
let operator_addr = devices.operator.aranya_local_addr().await?;
devices
.admin
.client
.team(team_id)
.sync_now(operator_addr, None)
.await?;
owner_team
.device(devices.membera.id)
.change_role(default_roles.member().id, default_roles.operator().id)
.await?;
owner_team
.device(devices.memberb.id)
.change_role(default_roles.member().id, default_roles.operator().id)
.await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
sleep(SLEEP_INTERVAL).await;
chan.seal(&mut ciphertext, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv.open(&mut plaintext, &ciphertext)
.context("unable to open afc message")
.expect_err("expected open to fail");
Ok(())
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_afc_uni_multi_send_chans() -> Result<()> {
let mut devices = DevicesCtx::new("test_afc_uni_multi_chans").await?;
let team_id = devices.create_and_add_team().await?;
let default_roles = devices.setup_default_roles(team_id).await?;
devices
.add_all_device_roles(team_id, &default_roles)
.await?;
let owner_team = devices.owner.client.team(team_id);
let member_role_rank = owner_team.rank(default_roles.member().id).await?;
let label_rank = Rank::new(member_role_rank.value().saturating_sub(1));
let op = ChanOp::SendRecv;
let label_id1 = owner_team.create_label(text!("label1"), label_rank).await?;
owner_team
.device(devices.membera.id)
.assign_label(label_id1, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id1, op)
.await?;
let label_id2 = owner_team.create_label(text!("label2"), label_rank).await?;
owner_team
.device(devices.membera.id)
.assign_label(label_id2, op)
.await?;
owner_team
.device(devices.memberb.id)
.assign_label(label_id2, op)
.await?;
let owner_addr = devices.owner.aranya_local_addr().await?;
devices
.membera
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
devices
.memberb
.client
.team(team_id)
.sync_now(owner_addr, None)
.await?;
let membera_afc = devices.membera.client.afc();
let memberb_afc = devices.memberb.client.afc();
let (mut chan1, ctrl1) = membera_afc
.create_channel(team_id, devices.memberb.id, label_id1)
.await
.context("unable to create afc uni channel")?;
let (mut chan2, ctrl2) = memberb_afc
.create_channel(team_id, devices.membera.id, label_id2)
.await
.context("unable to create afc uni channel")?;
let recv1 = memberb_afc
.accept_channel(team_id, ctrl1)
.await
.context("unable to receive afc uni channel")?;
let recv2 = membera_afc
.accept_channel(team_id, ctrl2)
.await
.context("unable to receive afc uni channel")?;
let afc_msg = "afc msg".as_bytes();
let mut ciphertext1 = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan1
.seal(&mut ciphertext1, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext1 = vec![0u8; ciphertext1.len() - Channels::OVERHEAD];
recv1
.open(&mut plaintext1, &ciphertext1)
.context("unable to open afc message")?;
assert_eq!(afc_msg, plaintext1);
let mut ciphertext2 = vec![0u8; afc_msg.len() + Channels::OVERHEAD];
chan2
.seal(&mut ciphertext2, afc_msg)
.context("unable to seal afc message")?;
let mut plaintext2 = vec![0u8; ciphertext2.len() - Channels::OVERHEAD];
recv2
.open(&mut plaintext2, &ciphertext2)
.context("unable to open afc message")?;
assert_eq!(afc_msg, plaintext2);
chan1.delete().await.context("unable to delete channel")?;
recv1.delete().await.context("unable to delete channel")?;
chan2.delete().await.context("unable to delete channel")?;
recv2.delete().await.context("unable to delete channel")?;
chan1
.seal(&mut ciphertext1, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv1
.open(&mut plaintext1, &ciphertext1)
.context("unable to open afc message")
.expect_err("expected open to fail");
chan2
.seal(&mut ciphertext2, afc_msg)
.context("unable to seal afc message")
.expect_err("expected seal to fail");
recv2
.open(&mut plaintext2, &ciphertext2)
.context("unable to open afc message")
.expect_err("expected open to fail");
Ok(())
}