Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

An encrypted HTTP client that communicates through an enclavia proxy.

All requests are encrypted end-to-end using the Noise protocol and forwarded through a WebSocket proxy to the enclave backend. The client verifies the enclave’s attestation document during connection.

Client is cheaply cloneable and can be shared across tasks.

Implementations§

Source§

impl Client

Source

pub async fn connect(url: &str, pcrs: Pcrs) -> Result<Self, Error>

Connect to an enclavia proxy and verify the enclave attestation.

This performs the full connection sequence:

  1. WebSocket connection to the proxy
  2. Noise NN handshake
  3. Attestation request and verification
§Example
// Hex PCRs exactly as printed by `enclavia enclave status` /
// `enclavia reproduce`, copy/paste friendly:
let pcrs = enclavia::Pcrs::from_hex("6be2...", "4b4d...", "21b9...")?;
let client = enclavia::Client::connect("wss://proxy.example.com", pcrs).await?;
let resp = client.get("/api/data").send().await?;
Source

pub fn builder(url: &str) -> ClientBuilder

Create a builder for more advanced configuration.

Source

pub fn get(&self, path: &str) -> RequestBuilder

Start building a GET request.

Source

pub fn post(&self, path: &str) -> RequestBuilder

Start building a POST request.

Source

pub fn put(&self, path: &str) -> RequestBuilder

Start building a PUT request.

Source

pub fn delete(&self, path: &str) -> RequestBuilder

Start building a DELETE request.

Source

pub fn patch(&self, path: &str) -> RequestBuilder

Start building a PATCH request.

Source

pub fn request(&self, method: Method, path: &str) -> RequestBuilder

Start building a request with an arbitrary method.

Source

pub async fn upgrade( &self, method: Method, path: &str, headers: &[(String, String)], ) -> Result<UpgradedStream, Error>

Open an upgraded stream (e.g. WebSocket) through the encrypted channel.

Builds an HTTP/1.1 request with the supplied method, path, and headers, sends it as a ClientMessage::OpenStream through the Noise tunnel, and accumulates the workload’s reply bytes (delivered as ServerMessage::StreamData) until a complete HTTP/1.1 response head is parsed.

On 101 Switching Protocols the returned UpgradedStream is a raw bidirectional byte pipe carrying the post-upgrade payload (e.g. WebSocket frames). On any other status the call returns Error::UpgradeFailed with the observed status code and the response head bytes, so the caller can surface the failure verbatim.

The 101 detection lives entirely on the SDK side: the in-enclave server treats OpenStream as an opaque byte pipe, which keeps the server-side protocol small enough that a future non-Rust frontend can implement it without an HTTP parser.

The returned stream implements tokio::io::AsyncRead + tokio::io::AsyncWrite and can be wrapped with tokio_tungstenite::WebSocketStream::from_raw_socket to get a client-side WebSocket endpoint that talks to the workload.

Source

pub async fn open_stream( &self, payload: Vec<u8>, ) -> Result<UpgradedStream, Error>

Opens a raw bidirectional byte stream to the workload.

The workload’s loopback TCP receives payload first, then bytes flow bidirectionally over the returned UpgradedStream. No HTTP semantics: this is the low-level primitive Client::upgrade is built on top of. Useful for non-HTTP protocols (raw TCP forwarding, custom wire formats) or for proxies that handle HTTP parsing themselves (pingora-enclavia hands the resulting stream to Pingora as a custom L4 transport).

payload is delivered as the first chunk of the in-enclave socket’s receive buffer; if you don’t have any prologue to ship, pass an empty Vec<u8> and the channel becomes a plain TCP-shaped pipe from the first byte.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more