#![doc = include_str!("../README.md")]
pub mod protocol;
mod framing;
mod handshake;
mod session;
mod side_ark;
mod side_host;
pub use protocol::{ArkToHost, HostToArk};
pub use side_ark::{ArkSide, Attestation, Attester};
pub use side_host::{HostSide, Roots, Verifier};
use std::io;
pub const MAX_FRAME_SIZE: usize = 2 * 1024 * 1024;
pub const MAX_MESSAGE_SIZE: usize = {
let mut size = MAX_FRAME_SIZE;
while darkbio_cobs::encode_buffer(size + session::Session::SEAL_OVERHEAD) > MAX_FRAME_SIZE {
size -= 1;
}
size
};
pub(crate) const CRYPTO_DOMAIN_WIRE: &[u8] = b"wire-v1";
pub(crate) const CRYPTO_DOMAIN_WIRE_ARK_TO_HOST: &[u8] = b"wire-v1:ark-to-host";
pub(crate) const CRYPTO_DOMAIN_WIRE_HOST_TO_ARK: &[u8] = b"wire-v1:host-to-ark";
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("wire packet too large: {0} bytes, max {MAX_MESSAGE_SIZE} bytes")]
PacketTooLarge(usize),
#[error("wire packet encode failed: {0}")]
PacketEncodingFailed(prost::EncodeError),
#[error("wire packet decode failed: {0}")]
PacketDecodingFailed(prost::DecodeError),
#[error("wire frame too large: {0} bytes, max {MAX_FRAME_SIZE} bytes")]
FrameTooLarge(usize),
#[error("wire frame encode failed: {0}")]
FrameEncodingFailed(darkbio_cobs::EncodeError),
#[error("wire frame decode failed: {0}")]
FrameDecodingFailed(darkbio_cobs::DecodeError),
#[error("wire send failed: {0}")]
SendFailed(io::Error),
#[error("wire receive failed: {0}")]
RecvFailed(io::Error),
#[error("wire terminated")]
Terminated,
#[error("attestation is not for a hardware or emulator")]
InvalidAttestation,
#[error("wire handshake failed: {0}")]
HandshakeFailed(String),
#[error("wire encryption failed: {0}")]
EncryptionFailed(String),
}
#[cfg(test)]
pub(crate) mod testing {
use std::sync::Once;
static INIT: Once = Once::new();
pub fn init_tracing() {
INIT.call_once(|| {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::from_default_env()
.add_directive(tracing::Level::TRACE.into()),
)
.with_ansi(true)
.with_test_writer()
.init();
});
}
}