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("handshake timeout")]
17 HandshakeTimeout,
18
19 #[error("hello not for us")]
21 HelloNotForUs,
22 #[error("hello uses our public key")]
23 HelloUsesOurKey,
24 #[error("invalid signature")]
25 InvalidSignature,
26 #[error("timestamp too old: {0}")]
27 InvalidTimestampOld(u64),
28 #[error("timestamp too future: {0}")]
29 InvalidTimestampFuture(u64),
30
31 #[error("shared secret was not contributory")]
33 SharedSecretNotContributory,
34 #[error("cipher creation failed")]
35 CipherCreation,
36 #[error("HKDF expansion failed")]
37 HKDFExpansion,
38 #[error("key confirmation failed")]
39 ConfirmationFailed,
40 #[error("invalid key confirmation")]
41 InvalidConfirmation,
42
43 #[error("cannot dial self")]
45 DialSelf,
46 #[error("wrong peer")]
47 WrongPeer,
48 #[error("recv failed")]
49 RecvFailed(RuntimeError),
50 #[error("recv too large: {0} bytes")]
51 RecvTooLarge(usize),
52 #[error("send failed")]
53 SendFailed(RuntimeError),
54 #[error("send zero size")]
55 SendZeroSize,
56 #[error("send too large: {0} bytes")]
57 SendTooLarge(usize),
58 #[error("connection closed")]
59 StreamClosed,
60
61 #[error("nonce overflow")]
63 NonceOverflow,
64 #[error("encryption failed")]
65 EncryptionFailed,
66 #[error("decryption failed")]
67 DecryptionFailed,
68
69 #[error("unable to decode: {0}")]
71 UnableToDecode(CodecError),
72}
73
74pub trait Sender: Sync + Send + 'static {
76 fn send(&mut self, msg: &[u8]) -> impl Future<Output = Result<(), Error>> + Send;
78}
79
80pub trait Receiver: Sync + Send + 'static {
82 fn receive(&mut self) -> impl Future<Output = Result<Bytes, Error>> + Send;
84}