use crate::error::{Error, Result};
use crate::noise::HandshakeResult;
pub const MAX_PLAINTEXT: usize = 65519;
pub struct FrameCipher {
pub transport: HandshakeResult,
}
impl FrameCipher {
pub fn new(transport: HandshakeResult) -> Self {
Self { transport }
}
pub fn seal(&mut self, plaintext: &[u8]) -> Result<Vec<u8>> {
if plaintext.len() > MAX_PLAINTEXT {
return Err(Error::PlaintextTooLarge {
got: plaintext.len(),
max: MAX_PLAINTEXT,
});
}
self.transport.send(plaintext)
}
pub fn open(&mut self, ciphertext: &[u8]) -> Result<Vec<u8>> {
self.transport.recv(ciphertext)
}
}