noxtls-io 0.2.11

Internal implementation crate for noxtls: transport traits and blocking/async TLS record I/O adapters.
Documentation
// Copyright (c) 2019-2026, Argenox Technologies LLC
// All rights reserved.
//
// SPDX-License-Identifier: GPL-2.0-only OR LicenseRef-Argenox-Commercial-License

//! Wraps a [`super::blocking::BlockingStream`] as [`super::stream_async::AsyncByteStream`] for same-thread use.

use async_trait::async_trait;

#[cfg(not(feature = "std"))]
use crate::internal_alloc::Box;

use super::blocking::BlockingStream;
use super::stream_async::AsyncByteStream;
use super::TransportError;

/// Adapts a blocking transport for async TLS drivers without a runtime.
pub struct BlockingAsAsync<S> {
    inner: S,
}

impl<S> BlockingAsAsync<S> {
    /// Wraps `inner`.
    #[must_use]
    pub fn noxtls_new(inner: S) -> Self {
        Self { inner }
    }

    /// Returns the wrapped stream.
    pub fn into_inner(self) -> S {
        self.inner
    }
}

#[async_trait(?Send)]
impl<S: BlockingStream> AsyncByteStream for BlockingAsAsync<S> {
    async fn read_async(&mut self, buf: &mut [u8]) -> Result<usize, TransportError> {
        self.inner.read(buf)
    }

    async fn write_all_async(&mut self, data: &[u8]) -> Result<(), TransportError> {
        self.inner.write_all(data)
    }
}