Struct mls_rs::client_builder::ClientBuilder

source ·
pub struct ClientBuilder<C>(/* private fields */);
Expand description

Builder for Client

This is returned by Client::builder and allows to tweak settings the Client will use. At a minimum, the builder must be told the CryptoProvider and IdentityProvider to use. Other settings have default values. This means that the following methods must be called before ClientBuilder::build:

§Example

use mls_rs::{
    Client,
    identity::{SigningIdentity, basic::{BasicIdentityProvider, BasicCredential}},
    CipherSuite,
};

use mls_rs_crypto_openssl::OpensslCryptoProvider;

// Replace by code to load the certificate and secret key
let secret_key = b"never hard-code secrets".to_vec().into();
let public_key = b"test invalid public key".to_vec().into();
let basic_identity = BasicCredential::new(b"name".to_vec());
let signing_identity = SigningIdentity::new(basic_identity.into_credential(), public_key);


let _client = Client::builder()
    .crypto_provider(OpensslCryptoProvider::default())
    .identity_provider(BasicIdentityProvider::new())
    .signing_identity(signing_identity, secret_key, CipherSuite::CURVE25519_AES128)
    .build();

§Spelling out a Client type

There are two main ways to spell out a Client type if needed (e.g. function return type).

The first option uses impl MlsConfig:

use mls_rs::{
    Client,
    client_builder::MlsConfig,
    identity::{SigningIdentity, basic::{BasicIdentityProvider, BasicCredential}},
    CipherSuite,
};

use mls_rs_crypto_openssl::OpensslCryptoProvider;

fn make_client() -> Client<impl MlsConfig> {
    // Replace by code to load the certificate and secret key
    let secret_key = b"never hard-code secrets".to_vec().into();
    let public_key = b"test invalid public key".to_vec().into();
    let basic_identity = BasicCredential::new(b"name".to_vec());
    let signing_identity = SigningIdentity::new(basic_identity.into_credential(), public_key);

    Client::builder()
        .crypto_provider(OpensslCryptoProvider::default())
        .identity_provider(BasicIdentityProvider::new())
        .signing_identity(signing_identity, secret_key, CipherSuite::CURVE25519_AES128)
        .build()
}

The second option is more verbose and consists in writing the full Client type:

use mls_rs::{
    Client,
    client_builder::{BaseConfig, WithIdentityProvider, WithCryptoProvider},
    identity::{SigningIdentity, basic::{BasicIdentityProvider, BasicCredential}},
    CipherSuite,
};

use mls_rs_crypto_openssl::OpensslCryptoProvider;

type MlsClient = Client<
    WithIdentityProvider<
        BasicIdentityProvider,
        WithCryptoProvider<OpensslCryptoProvider, BaseConfig>,
    >,
>;

fn make_client_2() -> MlsClient {
    // Replace by code to load the certificate and secret key
    let secret_key = b"never hard-code secrets".to_vec().into();
    let public_key = b"test invalid public key".to_vec().into();
    let basic_identity = BasicCredential::new(b"name".to_vec());
    let signing_identity = SigningIdentity::new(basic_identity.into_credential(), public_key);

    Client::builder()
        .crypto_provider(OpensslCryptoProvider::default())
        .identity_provider(BasicIdentityProvider::new())
        .signing_identity(signing_identity, secret_key, CipherSuite::CURVE25519_AES128)
        .build()
}

Implementations§

source§

impl ClientBuilder<BaseConfig>

source

pub fn new() -> Self

Create a new client builder with default in-memory providers

source§

impl ClientBuilder<EmptyConfig>

source

pub fn new_empty() -> Self

source§

impl ClientBuilder<BaseSqlConfig>

source

pub fn new_sqlite<CS: ConnectionStrategy>( storage: SqLiteDataStorageEngine<CS>, ) -> Result<Self, SqLiteDataStorageError>

Create a new client builder with SQLite storage providers.

source§

impl<C: IntoConfig> ClientBuilder<C>

source

pub fn extension_type( self, type_: ExtensionType, ) -> ClientBuilder<IntoConfigOutput<C>>

Add an extension type to the list of extension types supported by the client.

source

pub fn extension_types<I>(self, types: I) -> ClientBuilder<IntoConfigOutput<C>>
where I: IntoIterator<Item = ExtensionType>,

Add multiple extension types to the list of extension types supported by the client.

source

pub fn custom_proposal_type( self, type_: ProposalType, ) -> ClientBuilder<IntoConfigOutput<C>>

Add a custom proposal type to the list of proposals types supported by the client.

source

pub fn custom_proposal_types<I>( self, types: I, ) -> ClientBuilder<IntoConfigOutput<C>>
where I: IntoIterator<Item = ProposalType>,

Add multiple custom proposal types to the list of proposal types supported by the client.

source

pub fn protocol_version( self, version: ProtocolVersion, ) -> ClientBuilder<IntoConfigOutput<C>>

Add a protocol version to the list of protocol versions supported by the client.

If no protocol version is explicitly added, the client will support all protocol versions supported by this crate.

source

pub fn protocol_versions<I>( self, versions: I, ) -> ClientBuilder<IntoConfigOutput<C>>
where I: IntoIterator<Item = ProtocolVersion>,

Add multiple protocol versions to the list of protocol versions supported by the client.

If no protocol version is explicitly added, the client will support all protocol versions supported by this crate.

source

pub fn key_package_extension<T>( self, extension: T, ) -> Result<ClientBuilder<IntoConfigOutput<C>>, ExtensionError>
where T: MlsExtension, Self: Sized,

Add a key package extension to the list of key package extensions supported by the client.

source

pub fn key_package_extensions( self, extensions: ExtensionList, ) -> ClientBuilder<IntoConfigOutput<C>>

Add multiple key package extensions to the list of key package extensions supported by the client.

source

pub fn leaf_node_extension<T>( self, extension: T, ) -> Result<ClientBuilder<IntoConfigOutput<C>>, ExtensionError>
where T: MlsExtension, Self: Sized,

Add a leaf node extension to the list of leaf node extensions supported by the client.

source

pub fn leaf_node_extensions( self, extensions: ExtensionList, ) -> ClientBuilder<IntoConfigOutput<C>>

Add multiple leaf node extensions to the list of leaf node extensions supported by the client.

source

pub fn key_package_lifetime( self, duration_in_s: u64, ) -> ClientBuilder<IntoConfigOutput<C>>

Set the lifetime duration in seconds of key packages generated by the client.

source

pub fn key_package_repo<K>( self, key_package_repo: K, ) -> ClientBuilder<WithKeyPackageRepo<K, C>>

Set the key package repository to be used by the client.

By default, an in-memory repository is used.

source

pub fn psk_store<P>(self, psk_store: P) -> ClientBuilder<WithPskStore<P, C>>

Set the PSK store to be used by the client.

By default, an in-memory store is used.

source

pub fn group_state_storage<G>( self, group_state_storage: G, ) -> ClientBuilder<WithGroupStateStorage<G, C>>

Set the group state storage to be used by the client.

By default, an in-memory storage is used.

source

pub fn identity_provider<I>( self, identity_provider: I, ) -> ClientBuilder<WithIdentityProvider<I, C>>

Set the identity validator to be used by the client.

source

pub fn crypto_provider<Cp>( self, crypto_provider: Cp, ) -> ClientBuilder<WithCryptoProvider<Cp, C>>
where Cp: CryptoProvider,

Set the crypto provider to be used by the client.

source

pub fn mls_rules<Pr>(self, mls_rules: Pr) -> ClientBuilder<WithMlsRules<Pr, C>>
where Pr: MlsRules,

Set the user-defined proposal rules to be used by the client.

User-defined rules are used when sending and receiving commits before enforcing general MLS protocol rules. If the rule set returns an error when receiving a commit, the entire commit is considered invalid. If the rule set would return an error when sending a commit, individual proposals may be filtered out to compensate.

source

pub fn used_protocol_version( self, version: ProtocolVersion, ) -> ClientBuilder<IntoConfigOutput<C>>

Set the protocol version used by the client. By default, the client uses version MLS 1.0

source

pub fn signing_identity( self, signing_identity: SigningIdentity, signer: SignatureSecretKey, cipher_suite: CipherSuite, ) -> ClientBuilder<IntoConfigOutput<C>>

Set the signing identity used by the client as well as the matching signer and cipher suite. This must be called in order to create groups and key packages.

source

pub fn signer( self, signer: SignatureSecretKey, ) -> ClientBuilder<IntoConfigOutput<C>>

Set the signer used by the client. This must be called in order to join groups.

source§

impl<C: IntoConfig> ClientBuilder<C>
where C::KeyPackageRepository: KeyPackageStorage + Clone, C::PskStore: PreSharedKeyStorage + Clone, C::GroupStateStorage: GroupStateStorage + Clone, C::IdentityProvider: IdentityProvider + Clone, C::MlsRules: MlsRules + Clone, C::CryptoProvider: CryptoProvider + Clone,

source

pub fn build(self) -> Client<IntoConfigOutput<C>>

Build a client.

See ClientBuilder documentation if the return type of this function needs to be spelled out.

source§

impl<C: IntoConfig<PskStore = InMemoryPreSharedKeyStorage>> ClientBuilder<C>

source

pub fn psk( self, psk_id: ExternalPskId, psk: PreSharedKey, ) -> ClientBuilder<IntoConfigOutput<C>>

Add a PSK to the in-memory PSK store.

Trait Implementations§

source§

impl<C: Debug> Debug for ClientBuilder<C>

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for ClientBuilder<BaseConfig>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C> Freeze for ClientBuilder<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for ClientBuilder<C>
where C: RefUnwindSafe,

§

impl<C> Send for ClientBuilder<C>
where C: Send,

§

impl<C> Sync for ClientBuilder<C>
where C: Sync,

§

impl<C> Unpin for ClientBuilder<C>
where C: Unpin,

§

impl<C> UnwindSafe for ClientBuilder<C>
where C: UnwindSafe,

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.

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

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.