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-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::tls::TlsSocket;
|
|
|
|
use crate::set::TlsSocketSet;
|
|
|
|
|
|
|
|
// One-call function for polling all sockets within socket set
|
|
|
|
pub fn poll<DeviceT>(
|
|
|
|
sockets: &mut SocketSet,
|
|
|
|
tls_sockets: &mut TlsSocketSet,
|
|
|
|
iface: &mut EthernetInterface<DeviceT>,
|
|
|
|
now: Instant
|
|
|
|
) -> Result<bool, Error>
|
|
|
|
where
|
|
|
|
DeviceT: for<'d> Device<'d>
|
|
|
|
{
|
|
|
|
tls_sockets.polled_by(sockets)?;
|
|
|
|
iface.poll(sockets, now).map_err(Error::PropagatedError)
|
|
|
|
}
|