use std::collections::HashMap;
use std::fmt;
use chacha20poly1305::aead::{Aead, KeyInit, Payload};
use chacha20poly1305::{XChaCha20Poly1305, XNonce};
use hkdf::Hkdf;
use sha2::Sha256;
use teter_common::SessionId;
use zeroize::Zeroizing;
const VERSION: u8 = 1;
const CONTEXT: &[u8] = b"teter-e2e-v1";
const SENDER_LEN: usize = 16;
const SEQ_LEN: usize = 8;
const HEADER_LEN: usize = 1 + SENDER_LEN + SEQ_LEN;
const TAG_LEN: usize = 16;
const MAX_SENDERS: usize = 4096;
#[derive(Clone, PartialEq, Eq)]
pub struct Secret(Zeroizing<[u8; 32]>);
impl Secret {
pub fn generate() -> std::io::Result<Self> {
let mut bytes = Zeroizing::new([0u8; 32]);
getrandom::fill(bytes.as_mut()).map_err(std::io::Error::other)?;
Ok(Self(bytes))
}
#[expect(
clippy::indexing_slicing,
reason = "fixed-size buffers: the header's length is checked before it is cut, and hex digits come in pairs of a 64-digit secret"
)]
pub fn parse(text: &str) -> Result<Self, InvalidSecret> {
let mut digits = Zeroizing::new(Vec::with_capacity(text.len()));
digits.extend(
text.bytes()
.filter(|b| !b.is_ascii_whitespace() && *b != b'-'),
);
if digits.len() != 64 {
return Err(InvalidSecret);
}
let mut bytes = Zeroizing::new([0u8; 32]);
for (byte, pair) in bytes.iter_mut().zip(digits.chunks(2)) {
*byte = hex_value(pair[0])? * 16 + hex_value(pair[1])?;
}
Ok(Self(bytes))
}
#[expect(
clippy::indexing_slicing,
reason = "fixed-size buffers: the header's length is checked before it is cut, and hex digits come in pairs of a 64-digit secret"
)]
pub fn reveal(&self) -> Zeroizing<String> {
let mut text = Zeroizing::new(String::with_capacity(64));
for byte in self.0.iter() {
text.push(char::from(HEX[usize::from(byte >> 4)]));
text.push(char::from(HEX[usize::from(byte & 0xf)]));
}
text
}
}
impl fmt::Debug for Secret {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Secret(..)")
}
}
const HEX: &[u8; 16] = b"0123456789abcdef";
fn hex_value(digit: u8) -> Result<u8, InvalidSecret> {
match digit {
b'0'..=b'9' => Ok(digit - b'0'),
b'a'..=b'f' => Ok(digit - b'a' + 10),
b'A'..=b'F' => Ok(digit - b'A' + 10),
_ => Err(InvalidSecret),
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InvalidSecret;
impl fmt::Display for InvalidSecret {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("the secret is not 64 hex digits")
}
}
impl std::error::Error for InvalidSecret {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
ToBackend,
ToFrontend,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Kind {
Input,
Resize,
Output,
Paste,
History,
}
impl Kind {
fn byte(self) -> u8 {
match self {
Self::Input => 1,
Self::Resize => 2,
Self::Output => 3,
Self::Paste => 4,
Self::History => 5,
}
}
}
pub struct Keys {
session: SessionId,
to_backend: Zeroizing<[u8; 32]>,
to_frontend: Zeroizing<[u8; 32]>,
}
impl Keys {
pub fn derive(secret: &Secret, session: SessionId) -> Self {
Self::derive_with(secret, session, None)
}
pub fn derive_on(secret: &Secret, session: SessionId, channel: &str) -> Self {
Self::derive_with(secret, session, Some(channel))
}
#[expect(
clippy::expect_used,
reason = "fixed-size slices of a header whose length was checked, and an AEAD key of the length the cipher takes"
)]
fn derive_with(secret: &Secret, session: SessionId, channel: Option<&str>) -> Self {
let hkdf = Hkdf::<Sha256>::new(Some(session.as_bytes()), secret.0.as_ref());
let key = |direction: &[u8]| {
let mut info = direction.to_vec();
if let Some(channel) = channel {
info.extend_from_slice(b" on channel ");
info.extend_from_slice(channel.as_bytes());
}
let mut key = Zeroizing::new([0u8; 32]);
hkdf.expand(&info, key.as_mut())
.expect("32 bytes is a valid HKDF-SHA256 length");
key
};
Self {
session,
to_backend: key(b"teter-e2e-v1 frontend to backend"),
to_frontend: key(b"teter-e2e-v1 backend to frontend"),
}
}
fn cipher(&self, direction: Direction) -> XChaCha20Poly1305 {
let key = match direction {
Direction::ToBackend => &self.to_backend,
Direction::ToFrontend => &self.to_frontend,
};
XChaCha20Poly1305::new(key.as_ref().into())
}
pub fn sealer(&self, direction: Direction) -> std::io::Result<Sealer> {
let mut sender = [0u8; SENDER_LEN];
getrandom::fill(&mut sender).map_err(std::io::Error::other)?;
Ok(Sealer {
cipher: self.cipher(direction),
session: self.session,
sender,
next: 0,
})
}
pub fn opener(&self, direction: Direction) -> Opener {
Opener {
cipher: self.cipher(direction),
session: self.session,
last: HashMap::new(),
refused: std::collections::HashSet::new(),
newly_refused: false,
}
}
}
impl fmt::Debug for Keys {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Keys")
.field("session", &self.session)
.finish_non_exhaustive()
}
}
fn associated(session: SessionId, kind: Kind, header: &[u8]) -> Vec<u8> {
let mut aad = Vec::with_capacity(CONTEXT.len() + 16 + 1 + header.len());
aad.extend_from_slice(CONTEXT);
aad.extend_from_slice(session.as_bytes());
aad.push(kind.byte());
aad.extend_from_slice(header);
aad
}
pub type SenderId = [u8; SENDER_LEN];
pub struct Sealer {
cipher: XChaCha20Poly1305,
session: SessionId,
sender: [u8; SENDER_LEN],
next: u64,
}
impl Sealer {
#[expect(
clippy::expect_used,
reason = "fixed-size slices of a header whose length was checked, and an AEAD key of the length the cipher takes"
)]
pub fn seal(&mut self, kind: Kind, plaintext: &[u8]) -> Vec<u8> {
let seq = self.next;
self.next = seq.checked_add(1).expect("2^64 messages from one sender");
let mut header = [0u8; HEADER_LEN];
header[0] = VERSION;
header[1..1 + SENDER_LEN].copy_from_slice(&self.sender);
header[1 + SENDER_LEN..].copy_from_slice(&seq.to_be_bytes());
let nonce = XNonce::from_slice(&header[1..]);
let aad = associated(self.session, kind, &header);
let sealed = self
.cipher
.encrypt(
nonce,
Payload {
msg: plaintext,
aad: &aad,
},
)
.expect("XChaCha20-Poly1305 seals any length a message can have");
let mut out = Vec::with_capacity(HEADER_LEN + sealed.len());
out.extend_from_slice(&header);
out.extend_from_slice(&sealed);
out
}
}
impl fmt::Debug for Sealer {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Sealer")
.field("session", &self.session)
.finish_non_exhaustive()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OpenError {
Malformed,
Forged,
Replayed,
TooManySenders,
}
impl fmt::Display for OpenError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Malformed => "a sealed message is malformed",
Self::Forged => "a sealed message does not open: another secret, or altered",
Self::Replayed => "a sealed message was seen before",
Self::TooManySenders => "too many senders in this session",
})
}
}
impl std::error::Error for OpenError {}
pub struct Opener {
cipher: XChaCha20Poly1305,
session: SessionId,
last: HashMap<[u8; SENDER_LEN], u64>,
refused: std::collections::HashSet<[u8; SENDER_LEN]>,
newly_refused: bool,
}
impl Opener {
pub fn open(&mut self, kind: Kind, sealed: &[u8]) -> Result<Zeroizing<Vec<u8>>, OpenError> {
self.open_from(kind, sealed).map(|(plaintext, _)| plaintext)
}
#[expect(
clippy::indexing_slicing,
clippy::expect_used,
clippy::map_err_ignore,
reason = "fixed-size buffers: the header's length is checked before it is cut, and hex digits come in pairs of a 64-digit secret; fixed-size slices of a header whose length was checked, and an AEAD key of the length the cipher takes; AEAD failure carries no cause on purpose: a forgery and a corruption must look alike"
)]
pub fn open_from(
&mut self,
kind: Kind,
sealed: &[u8],
) -> Result<(Zeroizing<Vec<u8>>, SenderId), OpenError> {
if sealed.len() < HEADER_LEN + TAG_LEN || sealed[0] != VERSION {
return Err(OpenError::Malformed);
}
let (header, body) = sealed.split_at(HEADER_LEN);
let sender: [u8; SENDER_LEN] = header[1..1 + SENDER_LEN].try_into().expect("16 bytes");
let seq = u64::from_be_bytes(header[1 + SENDER_LEN..].try_into().expect("8 bytes"));
if self.last.get(&sender).is_some_and(|&last| seq <= last) {
return Err(OpenError::Replayed);
}
let aad = associated(self.session, kind, header);
let plaintext = self
.cipher
.decrypt(
XNonce::from_slice(&header[1..]),
Payload {
msg: body,
aad: &aad,
},
)
.map_err(|_| OpenError::Forged)?;
if !self.last.contains_key(&sender) && self.last.len() >= MAX_SENDERS {
if self.refused.len() < MAX_SENDERS && self.refused.insert(sender) {
self.newly_refused = true;
}
return Err(OpenError::TooManySenders);
}
self.last.insert(sender, seq);
Ok((Zeroizing::new(plaintext), sender))
}
}
impl Opener {
pub fn take_newly_refused(&mut self) -> bool {
std::mem::take(&mut self.newly_refused)
}
}
impl fmt::Debug for Opener {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Opener")
.field("session", &self.session)
.finish_non_exhaustive()
}
}
pub fn encode_size(columns: u16, rows: u16) -> [u8; 4] {
let [c0, c1] = columns.to_be_bytes();
let [r0, r1] = rows.to_be_bytes();
[c0, c1, r0, r1]
}
pub fn decode_size(plaintext: &[u8]) -> Option<(u16, u16)> {
let [c0, c1, r0, r1] = plaintext.try_into().ok()?;
Some((u16::from_be_bytes([c0, c1]), u16::from_be_bytes([r0, r1])))
}
#[cfg(test)]
mod tests {
use super::*;
fn pair() -> (Keys, Keys) {
let secret = Secret::generate().unwrap();
let session = SessionId::new_v4();
let backend = Keys::derive(&secret, session);
let frontend = Keys::derive(&Secret::parse(&secret.reveal()).unwrap(), session);
(backend, frontend)
}
#[test]
fn a_secret_round_trips_through_its_text() {
let secret = Secret::generate().unwrap();
let text = secret.reveal();
assert_eq!(text.len(), 64);
assert!(text.bytes().all(|b| HEX.contains(&b)));
assert_eq!(Secret::parse(&text).unwrap(), secret);
assert_eq!(Secret::parse(&text.to_uppercase()).unwrap(), secret);
let grouped: String = text
.as_bytes()
.chunks(8)
.map(|c| std::str::from_utf8(c).unwrap())
.collect::<Vec<_>>()
.join("-");
assert_eq!(Secret::parse(&grouped).unwrap(), secret);
assert_eq!(Secret::parse(&format!(" {}\r\n", *text)).unwrap(), secret);
assert_eq!(Secret::parse(&format!("{}\t", *text)).unwrap(), secret);
assert_ne!(Secret::generate().unwrap(), secret);
}
#[test]
fn a_secret_that_is_not_64_hex_digits_is_refused() {
assert_eq!(Secret::parse(""), Err(InvalidSecret));
assert_eq!(Secret::parse(&"a".repeat(63)), Err(InvalidSecret));
assert_eq!(Secret::parse(&"a".repeat(65)), Err(InvalidSecret));
assert_eq!(Secret::parse(&"g".repeat(64)), Err(InvalidSecret));
assert_eq!(
Secret::parse(&format!("{}G", "a".repeat(63))),
Err(InvalidSecret)
);
let secret = Secret::parse(&format!("0f{}", "0".repeat(62))).unwrap();
assert!(secret.reveal().starts_with("0f00"));
let secret = Secret::parse(&format!("A9{}", "0".repeat(62))).unwrap();
assert!(secret.reveal().starts_with("a900"));
}
#[test]
fn nothing_secret_shows_in_debug() {
let secret = Secret::parse(&"ab".repeat(32)).unwrap();
assert_eq!(format!("{secret:?}"), "Secret(..)");
let keys = Keys::derive(&secret, SessionId::nil());
let shown = format!(
"{keys:?} {:?} {:?}",
keys.sealer(Direction::ToBackend).unwrap(),
keys.opener(Direction::ToBackend)
);
assert!(!shown.contains("ab"), "{shown}");
assert!(!shown.contains("171"), "{shown}");
for name in ["Keys", "Sealer", "Opener"] {
assert!(shown.contains(name), "{shown}");
}
assert!(InvalidSecret.to_string().contains("64 hex digits"));
assert!(OpenError::Forged.to_string().contains("another secret"));
assert!(OpenError::Replayed.to_string().contains("seen before"));
assert!(OpenError::Malformed.to_string().contains("malformed"));
assert!(
OpenError::TooManySenders
.to_string()
.contains("too many senders")
);
}
#[test]
fn what_one_side_seals_the_other_opens() {
let (backend, frontend) = pair();
let mut sealer = frontend.sealer(Direction::ToBackend).unwrap();
let mut opener = backend.opener(Direction::ToBackend);
let sealed = sealer.seal(Kind::Input, b"hunter2\r");
assert_eq!(sealed.len(), HEADER_LEN + 8 + TAG_LEN);
assert!(!sealed.windows(7).any(|w| w == b"hunter2"));
assert_eq!(
&opener.open(Kind::Input, &sealed).unwrap()[..],
b"hunter2\r"
);
let mut sealer = backend.sealer(Direction::ToFrontend).unwrap();
let mut opener = frontend.opener(Direction::ToFrontend);
let sealed = sealer.seal(Kind::Output, b"$ ");
assert_eq!(&opener.open(Kind::Output, &sealed).unwrap()[..], b"$ ");
let sealed = sealer.seal(Kind::Output, b"");
assert_eq!(&opener.open(Kind::Output, &sealed).unwrap()[..], b"");
}
#[test]
fn the_same_plaintext_never_seals_the_same() {
let (backend, _) = pair();
let mut sealer = backend.sealer(Direction::ToFrontend).unwrap();
let a = sealer.seal(Kind::Output, b"same");
let b = sealer.seal(Kind::Output, b"same");
assert_ne!(a[HEADER_LEN..], b[HEADER_LEN..]);
let mut other = backend.sealer(Direction::ToFrontend).unwrap();
assert_ne!(
a[1..1 + SENDER_LEN],
other.seal(Kind::Output, b"same")[1..1 + SENDER_LEN]
);
}
#[test]
fn a_wrong_secret_another_session_or_direction_does_not_open() {
let (backend, _) = pair();
let mut sealer = backend.sealer(Direction::ToFrontend).unwrap();
let sealed = sealer.seal(Kind::Output, b"screen");
let other = Keys::derive(&Secret::generate().unwrap(), backend.session);
assert_eq!(
other
.opener(Direction::ToFrontend)
.open(Kind::Output, &sealed),
Err(OpenError::Forged)
);
let secret = Secret::parse(&"11".repeat(32)).unwrap();
let here = Keys::derive(&secret, SessionId::new_v4());
let elsewhere = Keys::derive(&secret, SessionId::new_v4());
let sealed = here
.sealer(Direction::ToFrontend)
.unwrap()
.seal(Kind::Output, b"x");
assert_eq!(
elsewhere
.opener(Direction::ToFrontend)
.open(Kind::Output, &sealed),
Err(OpenError::Forged)
);
assert_eq!(
here.opener(Direction::ToBackend)
.open(Kind::Output, &sealed),
Err(OpenError::Forged)
);
}
#[test]
fn an_altered_message_or_one_of_another_kind_does_not_open() {
let (backend, frontend) = pair();
let mut sealer = frontend.sealer(Direction::ToBackend).unwrap();
let mut opener = backend.opener(Direction::ToBackend);
let sealed = sealer.seal(Kind::Input, b"ls\r");
for at in 1..sealed.len() {
let mut altered = sealed.clone();
altered[at] ^= 1;
assert!(opener.open(Kind::Input, &altered).is_err(), "byte {at}");
}
assert_eq!(opener.open(Kind::Resize, &sealed), Err(OpenError::Forged));
assert!(opener.open(Kind::Input, &sealed).is_ok());
}
#[test]
fn a_malformed_message_is_refused() {
let (backend, _) = pair();
let mut opener = backend.opener(Direction::ToBackend);
assert_eq!(opener.open(Kind::Input, b""), Err(OpenError::Malformed));
assert_eq!(
opener.open(Kind::Input, &[VERSION; HEADER_LEN + TAG_LEN - 1]),
Err(OpenError::Malformed)
);
let mut sealed = backend
.sealer(Direction::ToBackend)
.unwrap()
.seal(Kind::Input, b"");
assert_eq!(sealed.len(), HEADER_LEN + TAG_LEN);
assert!(
backend
.opener(Direction::ToBackend)
.open(Kind::Input, &sealed)
.is_ok()
);
sealed[0] = 2;
assert_eq!(opener.open(Kind::Input, &sealed), Err(OpenError::Malformed));
}
#[test]
fn a_replayed_or_older_message_is_refused() {
let (backend, frontend) = pair();
let mut sealer = frontend.sealer(Direction::ToBackend).unwrap();
let mut opener = backend.opener(Direction::ToBackend);
let first = sealer.seal(Kind::Input, b"a");
let second = sealer.seal(Kind::Input, b"b");
let third = sealer.seal(Kind::Input, b"c");
assert!(opener.open(Kind::Input, &second).is_ok());
assert_eq!(opener.open(Kind::Input, &second), Err(OpenError::Replayed));
assert_eq!(opener.open(Kind::Input, &first), Err(OpenError::Replayed));
assert!(opener.open(Kind::Input, &third).is_ok());
let mut another = frontend.sealer(Direction::ToBackend).unwrap();
assert!(
opener
.open(Kind::Input, &another.seal(Kind::Input, b"d"))
.is_ok()
);
assert!(
opener
.open(Kind::Resize, &sealer.seal(Kind::Resize, &encode_size(1, 2)))
.is_ok()
);
}
#[test]
#[expect(
clippy::let_underscore_must_use,
reason = "the test checks what the opener records, not what open returns"
)]
fn a_new_sender_past_the_limit_is_refused_and_none_is_forgotten() {
let (backend, frontend) = pair();
let mut opener = backend.opener(Direction::ToBackend);
let mut first = frontend.sealer(Direction::ToBackend).unwrap();
let old = first.seal(Kind::Input, b"old");
assert!(opener.open(Kind::Input, &old).is_ok());
for _ in 1..MAX_SENDERS {
let mut sender = frontend.sealer(Direction::ToBackend).unwrap();
assert!(
opener
.open(Kind::Input, &sender.seal(Kind::Input, b"x"))
.is_ok()
);
}
assert_eq!(opener.last.len(), MAX_SENDERS);
let mut newest = frontend.sealer(Direction::ToBackend).unwrap();
assert!(!opener.take_newly_refused());
assert_eq!(
opener.open(Kind::Input, &newest.seal(Kind::Input, b"y")),
Err(OpenError::TooManySenders)
);
assert!(opener.take_newly_refused());
assert!(!opener.take_newly_refused(), "told once per ask");
let _ = opener.open(Kind::Input, &newest.seal(Kind::Input, b"y2"));
assert!(!opener.take_newly_refused());
let mut other = frontend.sealer(Direction::ToBackend).unwrap();
let _ = opener.open(Kind::Input, &other.seal(Kind::Input, b"o"));
assert!(opener.take_newly_refused());
assert_eq!(opener.open(Kind::Input, &old), Err(OpenError::Replayed));
assert!(
opener
.open(Kind::Input, &first.seal(Kind::Input, b"z"))
.is_ok()
);
let mut forged = newest.seal(Kind::Input, b"f");
let last = forged.len() - 1;
forged[last] ^= 1;
assert_eq!(opener.open(Kind::Input, &forged), Err(OpenError::Forged));
while opener.refused.len() < MAX_SENDERS {
let mut sender = frontend.sealer(Direction::ToBackend).unwrap();
let _ = opener.open(Kind::Input, &sender.seal(Kind::Input, b"r"));
assert!(opener.take_newly_refused());
}
let mut past = frontend.sealer(Direction::ToBackend).unwrap();
assert_eq!(
opener.open(Kind::Input, &past.seal(Kind::Input, b"p")),
Err(OpenError::TooManySenders)
);
assert!(!opener.take_newly_refused(), "told past the bound");
assert_eq!(opener.refused.len(), MAX_SENDERS);
}
#[test]
fn paste_is_a_kind_of_its_own_and_the_sender_is_told() {
let (backend, frontend) = pair();
let mut sealer = frontend.sealer(Direction::ToBackend).unwrap();
let mut opener = backend.opener(Direction::ToBackend);
let pasted = sealer.seal(Kind::Paste, b"p");
assert_eq!(opener.open(Kind::Input, &pasted), Err(OpenError::Forged));
let (plaintext, sender) = opener.open_from(Kind::Paste, &pasted).unwrap();
assert_eq!(&plaintext[..], b"p");
assert_eq!(sender, sealer.sender);
let typed = sealer.seal(Kind::Input, b"t");
assert_eq!(opener.open(Kind::Paste, &typed), Err(OpenError::Forged));
let (_, again) = opener.open_from(Kind::Input, &typed).unwrap();
assert_eq!(again, sender);
}
#[test]
fn a_size_round_trips() {
assert_eq!(decode_size(&encode_size(80, 24)), Some((80, 24)));
assert_eq!(
decode_size(&encode_size(0x1234, 0xabcd)),
Some((0x1234, 0xabcd))
);
assert_eq!(encode_size(0x1234, 0xabcd), [0x12, 0x34, 0xab, 0xcd]);
assert_eq!(decode_size(&[1, 2, 3]), None);
assert_eq!(decode_size(&[1, 2, 3, 4, 5]), None);
}
#[test]
fn the_keys_follow_a_known_derivation() {
let secret = Secret::parse(&"00".repeat(32)).unwrap();
let keys = Keys::derive(&secret, SessionId::nil());
let hex = |k: &[u8; 32]| k.iter().map(|b| format!("{b:02x}")).collect::<String>();
let pinned = (hex(&keys.to_backend), hex(&keys.to_frontend));
assert_ne!(pinned.0, pinned.1);
assert_eq!(
pinned,
(
String::from("026099e9d850ab7ef27762ea7e6c8590bb153abae1261881b66d32b2a24e9b42"),
String::from("7b11817c258cfdc9b023206880109ea790e6ec441440e0dc413f9307d02dc870")
)
);
}
#[test]
fn a_message_moved_to_another_channel_does_not_open() {
let secret = Secret::generate().unwrap();
let session = SessionId::new_v4();
let on_a = Keys::derive_on(&secret, session, "aaaa");
let mut sealer = on_a.sealer(Direction::ToFrontend).unwrap();
let sealed = sealer.seal(Kind::Output, b"for channel a");
let mut opener = on_a.opener(Direction::ToFrontend);
assert_eq!(
opener.open(Kind::Output, &sealed).unwrap().as_slice(),
b"for channel a"
);
for keys in [
Keys::derive_on(&secret, session, "bbbb"),
Keys::derive(&secret, session),
] {
assert!(
keys.opener(Direction::ToFrontend)
.open(Kind::Output, &sealed)
.is_err()
);
}
let plain = Keys::derive(&secret, session)
.sealer(Direction::ToFrontend)
.unwrap()
.seal(Kind::Output, b"whole session");
assert!(
on_a.opener(Direction::ToFrontend)
.open(Kind::Output, &plain)
.is_err()
);
}
}