pub mod auth;
pub mod body;
pub mod control;
pub mod crypto;
pub mod frame;
pub mod io;
pub mod payload;
pub mod replay;
pub mod secure_channel;
pub mod session;
pub use auth::{
HANDSHAKE_AUTH_ED25519, HANDSHAKE_AUTH_NONE, HandshakeAuth, IdentityKeyPair, PeerIdentity,
SessionAuthConfig,
};
pub use body::{
BODY_MAGIC, BODY_PROFILE_V0, BODY_VERSION_V0, BodyEnvelopeError, BodyEnvelopeLimits, open_body,
open_body_for_key_id, open_body_for_key_id_with_limits, open_body_with_limits, seal_body,
seal_body_with_limits,
};
pub use control::{ControlMessage, ControlMessageKind};
pub use crypto::{
Direction, EphemeralKeyPair, TrafficKeys, decrypt_frame, decrypt_frame_with_key,
derive_rekey_traffic_keys, derive_traffic_keys, encrypt_frame, make_nonce, random_session_salt,
};
pub use frame::{
DRAFT_MAGIC, FRAME_HEADER_LEN, FoctetFramed, FoctetStream, Frame, FrameHeader,
PROFILE_X25519_HKDF_XCHACHA20POLY1305, WIRE_VERSION_V0,
};
pub use payload::{Tlv, decode_tlvs, encode_tlvs, tlv_type};
pub use replay::{DEFAULT_REPLAY_WINDOW, ReplayProtector, ReplayWindow};
pub use secure_channel::{AsyncSecureChannel, SecureChannel};
pub use session::{HandshakeRole, RekeyThresholds, Session, SessionState};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum CoreError {
#[error("invalid frame header length: {0}")]
InvalidHeaderLength(usize),
#[error("invalid frame magic")]
InvalidMagic,
#[error("unsupported version: {0}")]
UnsupportedVersion(u8),
#[error("unsupported profile: {0}")]
UnsupportedProfile(u8),
#[error("unknown or reserved flags are set: 0x{0:02x}")]
UnknownFlags(u8),
#[error("ciphertext length mismatch: expected {expected}, got {actual}")]
CiphertextLengthMismatch {
expected: usize,
actual: usize,
},
#[error("aead operation failed")]
Aead,
#[error("hkdf expand failed")]
Hkdf,
#[error("invalid key length")]
InvalidKeyLength,
#[error("unexpected key id: expected {expected}, got {actual}")]
UnexpectedKeyId {
expected: u8,
actual: u8,
},
#[error("invalid control message")]
InvalidControlMessage,
#[error("unexpected control message for current state")]
UnexpectedControlMessage,
#[error("invalid session state")]
InvalidSessionState,
#[error("missing session secret")]
MissingSessionSecret,
#[error("invalid tlv payload")]
InvalidTlv,
#[error("tlv payload too large")]
TlvTooLarge,
#[error("replay detected")]
Replay,
#[error("frame is outside replay window")]
ReplayWindowExceeded,
#[error("frame exceeds configured limit")]
FrameTooLarge,
#[error("unexpected eof")]
UnexpectedEof,
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("invalid shared secret")]
InvalidSharedSecret,
#[error("sequence space exhausted")]
SequenceExhausted,
#[error("key id space exhausted")]
KeyIdExhausted,
#[error("missing peer authentication")]
MissingPeerAuthentication,
#[error("invalid peer authentication")]
InvalidPeerAuthentication,
#[error("peer identity mismatch")]
PeerIdentityMismatch,
}