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
:
- To specify the
CryptoProvider
:ClientBuilder::crypto_provider
- To specify the
IdentityProvider
:ClientBuilder::identity_provider
§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§
sourcepub fn new_sqlite<CS: ConnectionStrategy>(
storage: SqLiteDataStorageEngine<CS>,
) -> Result<Self, SqLiteDataStorageError>
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>
impl<C: IntoConfig> ClientBuilder<C>
sourcepub fn extension_type(
self,
type_: ExtensionType,
) -> ClientBuilder<IntoConfigOutput<C>>
pub fn extension_type( self, type_: ExtensionType, ) -> ClientBuilder<IntoConfigOutput<C>>
Add an extension type to the list of extension types supported by the client.
sourcepub fn extension_types<I>(self, types: I) -> ClientBuilder<IntoConfigOutput<C>>where
I: IntoIterator<Item = ExtensionType>,
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.
sourcepub fn custom_proposal_type(
self,
type_: ProposalType,
) -> ClientBuilder<IntoConfigOutput<C>>
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.
sourcepub fn custom_proposal_types<I>(
self,
types: I,
) -> ClientBuilder<IntoConfigOutput<C>>where
I: IntoIterator<Item = ProposalType>,
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.
sourcepub fn protocol_version(
self,
version: ProtocolVersion,
) -> ClientBuilder<IntoConfigOutput<C>>
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.
sourcepub fn protocol_versions<I>(
self,
versions: I,
) -> ClientBuilder<IntoConfigOutput<C>>where
I: IntoIterator<Item = ProtocolVersion>,
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.
sourcepub fn key_package_extension<T>(
self,
extension: T,
) -> Result<ClientBuilder<IntoConfigOutput<C>>, ExtensionError>where
T: MlsExtension,
Self: Sized,
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.
sourcepub fn key_package_extensions(
self,
extensions: ExtensionList,
) -> ClientBuilder<IntoConfigOutput<C>>
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.
sourcepub fn leaf_node_extension<T>(
self,
extension: T,
) -> Result<ClientBuilder<IntoConfigOutput<C>>, ExtensionError>where
T: MlsExtension,
Self: Sized,
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.
sourcepub fn leaf_node_extensions(
self,
extensions: ExtensionList,
) -> ClientBuilder<IntoConfigOutput<C>>
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.
sourcepub fn key_package_lifetime(
self,
duration_in_s: u64,
) -> ClientBuilder<IntoConfigOutput<C>>
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.
sourcepub fn key_package_repo<K>(
self,
key_package_repo: K,
) -> ClientBuilder<WithKeyPackageRepo<K, C>>where
K: KeyPackageStorage,
pub fn key_package_repo<K>(
self,
key_package_repo: K,
) -> ClientBuilder<WithKeyPackageRepo<K, C>>where
K: KeyPackageStorage,
Set the key package repository to be used by the client.
By default, an in-memory repository is used.
sourcepub fn psk_store<P>(self, psk_store: P) -> ClientBuilder<WithPskStore<P, C>>where
P: PreSharedKeyStorage,
pub fn psk_store<P>(self, psk_store: P) -> ClientBuilder<WithPskStore<P, C>>where
P: PreSharedKeyStorage,
Set the PSK store to be used by the client.
By default, an in-memory store is used.
sourcepub fn group_state_storage<G>(
self,
group_state_storage: G,
) -> ClientBuilder<WithGroupStateStorage<G, C>>where
G: GroupStateStorage,
pub fn group_state_storage<G>(
self,
group_state_storage: G,
) -> ClientBuilder<WithGroupStateStorage<G, C>>where
G: GroupStateStorage,
Set the group state storage to be used by the client.
By default, an in-memory storage is used.
sourcepub fn identity_provider<I>(
self,
identity_provider: I,
) -> ClientBuilder<WithIdentityProvider<I, C>>where
I: IdentityProvider,
pub fn identity_provider<I>(
self,
identity_provider: I,
) -> ClientBuilder<WithIdentityProvider<I, C>>where
I: IdentityProvider,
Set the identity validator to be used by the client.
sourcepub fn crypto_provider<Cp>(
self,
crypto_provider: Cp,
) -> ClientBuilder<WithCryptoProvider<Cp, C>>where
Cp: CryptoProvider,
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.
sourcepub fn mls_rules<Pr>(self, mls_rules: Pr) -> ClientBuilder<WithMlsRules<Pr, C>>where
Pr: MlsRules,
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.
sourcepub fn used_protocol_version(
self,
version: ProtocolVersion,
) -> ClientBuilder<IntoConfigOutput<C>>
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
sourcepub fn signing_identity(
self,
signing_identity: SigningIdentity,
signer: SignatureSecretKey,
cipher_suite: CipherSuite,
) -> ClientBuilder<IntoConfigOutput<C>>
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.
sourcepub fn signer(
self,
signer: SignatureSecretKey,
) -> ClientBuilder<IntoConfigOutput<C>>
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,
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,
sourcepub fn build(self) -> Client<IntoConfigOutput<C>>
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>
impl<C: IntoConfig<PskStore = InMemoryPreSharedKeyStorage>> ClientBuilder<C>
sourcepub fn psk(
self,
psk_id: ExternalPskId,
psk: PreSharedKey,
) -> ClientBuilder<IntoConfigOutput<C>>
pub fn psk( self, psk_id: ExternalPskId, psk: PreSharedKey, ) -> ClientBuilder<IntoConfigOutput<C>>
Add a PSK to the in-memory PSK store.