pub struct Wormhole {
    pub verifier: Box<Key>,
    pub our_version: Box<dyn Any + Send + Sync>,
    pub peer_version: Value,
    /* private fields */
}
Expand description

Establishing Wormhole connection

You can send and receive arbitrary messages in form of byte slices over it, using Wormhole::send and Wormhole::receive. Everything else (including encryption) will be handled for you.

To create a wormhole, use the Wormhole::connect_without_code, Wormhole::connect_with_code etc. methods, depending on which values you have. Typically, the sender side connects without a code (which will create one), and the receiver side has one (the user entered it, who got it from the sender).

Clean shutdown

TODO

Fields§

§verifier: Box<Key>

If you’re paranoid, let both sides check that they calculated the same verifier.

PAKE hardens a standard key exchange with a password (“password authenticated”) in order to mitigate potential man in the middle attacks that would otherwise be possible. Since the passwords usually are not of hight entropy, there is a low-probability possible of an attacker guessing the password correctly, enabling them to MitM the connection.

Not only is that probability low, but they also have only one try per connection and a failed attempts will be noticed by both sides. Nevertheless, comparing the verifier mitigates that attack vector.

§our_version: Box<dyn Any + Send + Sync>

Our “app version” information that we sent. See the [peer_version] for more information.

§peer_version: Value

Protocol version information from the other side. This is bound by the AppID’s protocol and thus shall be handled on a higher level (e.g. by the file transfer API).

Implementations§

source§

impl Wormhole

source

pub async fn connect_without_code( config: AppConfig<impl Serialize + Send + Sync + 'static>, code_length: usize ) -> Result<(WormholeWelcome, impl Future<Output = Result<Self, WormholeError>>), WormholeError>

Generate a code and connect to the rendezvous server.

Returns

A tuple with a WormholeWelcome and a std::future::Future that will do the rest of the client-client handshake and yield the Wormhole object on success.

source

pub async fn connect_with_code( config: AppConfig<impl Serialize + Send + Sync + 'static>, code: Code ) -> Result<(WormholeWelcome, Self), WormholeError>

Connect to a peer with a code.

source

pub async fn connect_with_seed()

TODO

source

pub async fn connect_custom( server: RendezvousServer, appid: AppID, password: String, app_versions: impl Serialize + Send + Sync + 'static ) -> Result<Self, WormholeError>

Do only the client-client part of the connection setup

The rendezvous server must already have an opened mailbox.

Panics

If the RendezvousServer is not properly initialized, i.e. if the mailbox is not open.

source

pub async fn send(&mut self, plaintext: Vec<u8>) -> Result<(), WormholeError>

Send an encrypted message to peer

source

pub async fn send_json<T: Serialize>( &mut self, message: &T ) -> Result<(), WormholeError>

Serialize and send an encrypted message to peer

This will serialize the message as json string, which is most commonly used by upper layer protocols. The serialization may not fail

Panics

If the serialization fails

source

pub async fn receive(&mut self) -> Result<Vec<u8>, WormholeError>

Receive an encrypted message from peer

source

pub async fn receive_json<T>( &mut self ) -> Result<Result<T, Error>, WormholeError>
where T: for<'a> Deserialize<'a>,

Receive an encrypted message from peer

This will deserialize the message as json string, which is most commonly used by upper layer protocols. We distinguish between the different layers on which a serialization error happened, hence the double Result.

source

pub async fn close(self) -> Result<(), WormholeError>

source

pub fn appid(&self) -> &AppID

The AppID this wormhole is bound to. This determines the upper-layer protocol. Only wormholes with the same value can talk to each other.

source

pub fn key(&self) -> &Key<WormholeKey>

The symmetric encryption key used by this connection. Can be used to derive sub-keys for different purposes.

Trait Implementations§

source§

impl Debug for Wormhole

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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