SaiTLS/src/lib.rs

74 lines
1.7 KiB
Rust
Raw Normal View History

2020-10-04 22:22:29 +08:00
#![no_std]
2020-10-11 23:41:02 +08:00
extern crate alloc;
2020-10-04 22:22:29 +08:00
pub mod tls;
2020-10-11 13:46:24 +08:00
pub mod tls_packet;
pub mod parse;
2020-10-15 22:40:36 +08:00
pub mod buffer;
2020-10-16 17:38:29 +08:00
pub mod key;
2020-10-17 20:10:18 +08:00
pub mod session;
2020-10-21 18:18:54 +08:00
pub mod certificate;
2020-10-29 17:34:03 +08:00
pub mod fake_rng;
2020-11-04 17:45:23 +08:00
pub mod oid;
2020-11-23 17:16:07 +08:00
pub mod set;
2020-10-21 18:18:54 +08:00
2020-12-07 11:26:49 +08:00
#[cfg(feature = "nal_tcp_stack")]
2020-12-04 15:50:37 +08:00
pub mod tcp_stack;
2020-10-11 23:41:02 +08:00
// TODO: Implement errors
// Details: Encapsulate smoltcp & nom errors
2020-10-28 17:33:00 +08:00
#[derive(Debug, Clone)]
2020-10-11 13:46:24 +08:00
pub enum Error {
PropagatedError(smoltcp::Error),
2020-10-28 17:33:00 +08:00
ParsingError,
2020-10-15 17:29:42 +08:00
EncryptionError,
2020-10-18 20:02:40 +08:00
DecryptionError,
2020-10-15 17:29:42 +08:00
CapacityError,
2020-10-28 17:33:00 +08:00
SignatureValidationError,
2020-11-11 16:16:45 +08:00
TimeValidityError,
CertificateIssuerMismatch,
CertificateSubjectNotPermitted,
CertificateSubjectExcluded,
CertificatePolicyError,
CertificateVersionError,
2020-10-21 18:18:54 +08:00
}
2020-11-23 17:16:07 +08:00
impl From<smoltcp::Error> for Error {
fn from(error: smoltcp::Error) -> Self {
Self::PropagatedError(error)
}
}
pub trait TlsRng: rand_core::RngCore + rand_core::CryptoRng {}
use smoltcp as net;
use net::socket::SocketSet;
use net::iface::EthernetInterface;
use net::time::Instant;
use net::phy::Device;
use crate::set::TlsSocketSet;
// One-call function for polling all sockets within socket set
2020-12-04 15:50:37 +08:00
// Input of vanilla sockets are optional, as one may not feel needed to create them
// TLS socket set is mandatory, otherwise you should just use `EthernetInterface::poll(..)`
2020-11-23 17:16:07 +08:00
pub fn poll<DeviceT>(
2020-12-04 15:50:37 +08:00
sockets: Option<&mut SocketSet>,
2020-11-23 17:16:07 +08:00
tls_sockets: &mut TlsSocketSet,
iface: &mut EthernetInterface<DeviceT>,
now: Instant
) -> Result<bool, Error>
where
DeviceT: for<'d> Device<'d>
{
2020-12-04 15:50:37 +08:00
tls_sockets.polled_by(iface, now)?;
if let Some(vanilla_sockets) = sockets {
iface.poll(vanilla_sockets, now).map_err(Error::PropagatedError)?;
}
Ok(true)
2020-11-23 17:16:07 +08:00
}