1pub mod public_key;
4pub mod utils;
5
6use bytes::Bytes;
7use commonware_codec::Error as CodecError;
8use commonware_runtime::Error as RuntimeError;
9use std::future::Future;
10use thiserror::Error;
11
12#[derive(Error, Debug)]
14pub enum Error {
15 #[error("unable to decode: {0}")]
16 UnableToDecode(CodecError),
17 #[error("handshake not for us")]
18 HandshakeNotForUs,
19 #[error("handshake timeout")]
20 HandshakeTimeout,
21 #[error("invalid signature")]
22 InvalidSignature,
23 #[error("wrong peer")]
24 WrongPeer,
25 #[error("recv failed")]
26 RecvFailed(RuntimeError),
27 #[error("recv too large: {0} bytes")]
28 RecvTooLarge(usize),
29 #[error("send failed")]
30 SendFailed(RuntimeError),
31 #[error("send zero size")]
32 SendZeroSize,
33 #[error("send too large: {0} bytes")]
34 SendTooLarge(usize),
35 #[error("connection closed")]
36 StreamClosed,
37 #[error("cipher creation failed")]
38 CipherCreationFailed,
39 #[error("nonce overflow")]
40 NonceOverflow,
41 #[error("encryption failed")]
42 EncryptionFailed,
43 #[error("decryption failed")]
44 DecryptionFailed,
45 #[error("timestamp too old: {0}")]
46 InvalidTimestampOld(u64),
47 #[error("timestamp too future: {0}")]
48 InvalidTimestampFuture(u64),
49}
50
51pub trait Sender: Sync + Send + 'static {
53 fn send(&mut self, msg: &[u8]) -> impl Future<Output = Result<(), Error>> + Send;
55}
56
57pub trait Receiver: Sync + Send + 'static {
59 fn receive(&mut self) -> impl Future<Output = Result<Bytes, Error>> + Send;
61}